forked from platypush/platypush
Fixed LGTM errors and warnings
This commit is contained in:
parent
85af031c26
commit
1a314ffd6b
6 changed files with 19 additions and 24 deletions
|
@ -6,8 +6,9 @@ from multiprocessing import Process
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from websockets.exceptions import ConnectionClosed
|
from websockets.exceptions import ConnectionClosed
|
||||||
|
from websockets import serve as websocket_serve
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from websockets import ConnectionClosed
|
from websockets import ConnectionClosed, serve as websocket_serve
|
||||||
|
|
||||||
from platypush.backend import Backend
|
from platypush.backend import Backend
|
||||||
from platypush.backend.http.app import application
|
from platypush.backend.http.app import application
|
||||||
|
@ -354,7 +355,6 @@ class HttpBackend(Backend):
|
||||||
|
|
||||||
def websocket(self):
|
def websocket(self):
|
||||||
""" Websocket main server """
|
""" Websocket main server """
|
||||||
import websockets
|
|
||||||
set_thread_name('WebsocketServer')
|
set_thread_name('WebsocketServer')
|
||||||
|
|
||||||
async def register_websocket(websocket, path):
|
async def register_websocket(websocket, path):
|
||||||
|
@ -378,7 +378,7 @@ class HttpBackend(Backend):
|
||||||
|
|
||||||
self._websocket_loop = get_or_create_event_loop()
|
self._websocket_loop = get_or_create_event_loop()
|
||||||
self._websocket_loop.run_until_complete(
|
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))
|
**websocket_args))
|
||||||
self._websocket_loop.run_forever()
|
self._websocket_loop.run_forever()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
from platypush.backend import Backend
|
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.context import get_plugin, get_or_create_event_loop
|
||||||
from platypush.message import Message
|
from platypush.message import Message
|
||||||
from platypush.message.request import Request
|
from platypush.message.request import Request
|
||||||
|
@ -73,10 +79,6 @@ class WebsocketBackend(Backend):
|
||||||
|
|
||||||
def notify_web_clients(self, event):
|
def notify_web_clients(self, event):
|
||||||
""" Notify all the connected web clients (over websocket) of a new 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):
|
async def send_event(websocket):
|
||||||
try:
|
try:
|
||||||
|
@ -96,12 +98,6 @@ class WebsocketBackend(Backend):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
import asyncio
|
import asyncio
|
||||||
import websockets
|
|
||||||
|
|
||||||
try:
|
|
||||||
from websockets.exceptions import ConnectionClosed
|
|
||||||
except ImportError:
|
|
||||||
from websockets import ConnectionClosed
|
|
||||||
|
|
||||||
super().run()
|
super().run()
|
||||||
self.register_service(port=self.port, name='ws')
|
self.register_service(port=self.port, name='ws')
|
||||||
|
@ -152,8 +148,7 @@ class WebsocketBackend(Backend):
|
||||||
websocket_args['ssl'] = self.ssl_context
|
websocket_args['ssl'] = self.ssl_context
|
||||||
|
|
||||||
self._loop = get_or_create_event_loop()
|
self._loop = get_or_create_event_loop()
|
||||||
server = websockets.serve(serve_client, self.bind_address, self.port,
|
server = websocket_serve(serve_client, self.bind_address, self.port, **websocket_args)
|
||||||
**websocket_args)
|
|
||||||
|
|
||||||
self._loop.run_until_complete(server)
|
self._loop.run_until_complete(server)
|
||||||
self._loop.run_forever()
|
self._loop.run_forever()
|
||||||
|
|
|
@ -26,7 +26,7 @@ class SlackEvent(Event, ABCMeta):
|
||||||
return datetime.fromtimestamp(timestamp, tz=gettz()) # lgtm [py/call-to-non-callable]
|
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.
|
Base class for message-related events.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -39,7 +39,7 @@ def action(f):
|
||||||
return _execute_action
|
return _execute_action
|
||||||
|
|
||||||
|
|
||||||
class Plugin(EventGenerator, ExtensionWithManifest):
|
class Plugin(EventGenerator, ExtensionWithManifest): # lgtm [py/missing-call-to-init]
|
||||||
""" Base plugin class """
|
""" Base plugin class """
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import json
|
import json
|
||||||
import websockets
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from websockets.exceptions import ConnectionClosed
|
from websockets.exceptions import ConnectionClosed
|
||||||
|
from websockets import connect as websocket_connect
|
||||||
except ImportError:
|
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.context import get_or_create_event_loop
|
||||||
from platypush.message import Message
|
from platypush.message import Message
|
||||||
|
@ -52,7 +52,7 @@ class WebsocketPlugin(Plugin):
|
||||||
ssl_cafile=ssl_cafile,
|
ssl_cafile=ssl_cafile,
|
||||||
ssl_capath=ssl_capath)
|
ssl_capath=ssl_capath)
|
||||||
|
|
||||||
async with websockets.connect(url, **websocket_args) as websocket:
|
async with websocket_connect(url, **websocket_args) as websocket:
|
||||||
try:
|
try:
|
||||||
await websocket.send(str(msg))
|
await websocket.send(str(msg))
|
||||||
except ConnectionClosed as err:
|
except ConnectionClosed as err:
|
||||||
|
|
|
@ -5,12 +5,12 @@ import time
|
||||||
from typing import Optional, Dict
|
from typing import Optional, Dict
|
||||||
|
|
||||||
import bcrypt
|
import bcrypt
|
||||||
import jwt
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from jwt.exceptions import PyJWTError
|
from jwt.exceptions import PyJWTError
|
||||||
|
from jwt import encode as jwt_encode, decode as jwt_decode
|
||||||
except ImportError:
|
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 import Column, Integer, String, DateTime, ForeignKey
|
||||||
from sqlalchemy.orm import sessionmaker, scoped_session
|
from sqlalchemy.orm import sessionmaker, scoped_session
|
||||||
|
@ -204,7 +204,7 @@ class UserManager:
|
||||||
'expires_at': expires_at.timestamp() if expires_at else None,
|
'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):
|
if isinstance(token, bytes):
|
||||||
token = token.decode()
|
token = token.decode()
|
||||||
return token
|
return token
|
||||||
|
@ -230,7 +230,7 @@ class UserManager:
|
||||||
pub_key, priv_key = get_or_generate_jwt_rsa_key_pair()
|
pub_key, priv_key = get_or_generate_jwt_rsa_key_pair()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payload = jwt.decode(token.encode(), pub_key, algorithms=['RS256'])
|
payload = jwt_decode(token.encode(), pub_key, algorithms=['RS256'])
|
||||||
except PyJWTError as e:
|
except PyJWTError as e:
|
||||||
raise InvalidJWTTokenException(str(e))
|
raise InvalidJWTTokenException(str(e))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue