Fixed LGTM errors and warnings

This commit is contained in:
Fabio Manganiello 2021-09-17 22:21:06 +02:00
parent 85af031c26
commit 1a314ffd6b
6 changed files with 19 additions and 24 deletions

View file

@ -6,8 +6,9 @@ from multiprocessing import Process
try:
from websockets.exceptions import ConnectionClosed
from websockets import serve as websocket_serve
except ImportError:
from websockets import ConnectionClosed
from websockets import ConnectionClosed, serve as websocket_serve
from platypush.backend import Backend
from platypush.backend.http.app import application
@ -354,7 +355,6 @@ class HttpBackend(Backend):
def websocket(self):
""" Websocket main server """
import websockets
set_thread_name('WebsocketServer')
async def register_websocket(websocket, path):
@ -378,7 +378,7 @@ class HttpBackend(Backend):
self._websocket_loop = get_or_create_event_loop()
self._websocket_loop.run_until_complete(
websockets.serve(register_websocket, self.bind_address, self.websocket_port,
websocket_serve(register_websocket, self.bind_address, self.websocket_port,
**websocket_args))
self._websocket_loop.run_forever()

View file

@ -1,4 +1,10 @@
from platypush.backend import Backend
try:
from websockets.exceptions import ConnectionClosed
from websockets import serve as websocket_serve
except ImportError:
from websockets import ConnectionClosed, serve as websocket_serve
from platypush.context import get_plugin, get_or_create_event_loop
from platypush.message import Message
from platypush.message.request import Request
@ -73,10 +79,6 @@ class WebsocketBackend(Backend):
def notify_web_clients(self, event):
""" Notify all the connected web clients (over websocket) of a new event """
try:
from websockets.exceptions import ConnectionClosed
except ImportError:
from websockets import ConnectionClosed
async def send_event(websocket):
try:
@ -96,12 +98,6 @@ class WebsocketBackend(Backend):
def run(self):
import asyncio
import websockets
try:
from websockets.exceptions import ConnectionClosed
except ImportError:
from websockets import ConnectionClosed
super().run()
self.register_service(port=self.port, name='ws')
@ -152,8 +148,7 @@ class WebsocketBackend(Backend):
websocket_args['ssl'] = self.ssl_context
self._loop = get_or_create_event_loop()
server = websockets.serve(serve_client, self.bind_address, self.port,
**websocket_args)
server = websocket_serve(serve_client, self.bind_address, self.port, **websocket_args)
self._loop.run_until_complete(server)
self._loop.run_forever()

View file

@ -26,7 +26,7 @@ class SlackEvent(Event, ABCMeta):
return datetime.fromtimestamp(timestamp, tz=gettz()) # lgtm [py/call-to-non-callable]
class SlackMessageEvent(SlackEvent, ABCMeta):
class SlackMessageEvent(SlackEvent, ABCMeta): # lgtm [py/conflicting-attributes]
"""
Base class for message-related events.
"""

View file

@ -39,7 +39,7 @@ def action(f):
return _execute_action
class Plugin(EventGenerator, ExtensionWithManifest):
class Plugin(EventGenerator, ExtensionWithManifest): # lgtm [py/missing-call-to-init]
""" Base plugin class """
def __init__(self, **kwargs):

View file

@ -1,10 +1,10 @@
import json
import websockets
try:
from websockets.exceptions import ConnectionClosed
from websockets import connect as websocket_connect
except ImportError:
from websockets import ConnectionClosed
from websockets import ConnectionClosed, connect as websocket_connect
from platypush.context import get_or_create_event_loop
from platypush.message import Message
@ -52,7 +52,7 @@ class WebsocketPlugin(Plugin):
ssl_cafile=ssl_cafile,
ssl_capath=ssl_capath)
async with websockets.connect(url, **websocket_args) as websocket:
async with websocket_connect(url, **websocket_args) as websocket:
try:
await websocket.send(str(msg))
except ConnectionClosed as err:

View file

@ -5,12 +5,12 @@ import time
from typing import Optional, Dict
import bcrypt
import jwt
try:
from jwt.exceptions import PyJWTError
from jwt import encode as jwt_encode, decode as jwt_decode
except ImportError:
from jwt import PyJWTError
from jwt import PyJWTError, encode as jwt_encode, decode as jwt_decode
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
from sqlalchemy.orm import sessionmaker, scoped_session
@ -204,7 +204,7 @@ class UserManager:
'expires_at': expires_at.timestamp() if expires_at else None,
}
token = jwt.encode(payload, priv_key, algorithm='RS256')
token = jwt_encode(payload, priv_key, algorithm='RS256')
if isinstance(token, bytes):
token = token.decode()
return token
@ -230,7 +230,7 @@ class UserManager:
pub_key, priv_key = get_or_generate_jwt_rsa_key_pair()
try:
payload = jwt.decode(token.encode(), pub_key, algorithms=['RS256'])
payload = jwt_decode(token.encode(), pub_key, algorithms=['RS256'])
except PyJWTError as e:
raise InvalidJWTTokenException(str(e))