From 29a7eff15af7b9145a6f669f5ce3afed8b673e86 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 8 Feb 2022 21:51:37 +0100 Subject: [PATCH] Fixed/suppressed LGTM warnings --- platypush/backend/http/app/routes/resources.py | 7 +++++-- platypush/backend/sensor/__init__.py | 3 +-- platypush/message/event/__init__.py | 2 +- platypush/plugins/camera/__init__.py | 10 +++++++--- platypush/schemas/__init__.py | 4 ++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/platypush/backend/http/app/routes/resources.py b/platypush/backend/http/app/routes/resources.py index b556f02e57..8705caab00 100644 --- a/platypush/backend/http/app/routes/resources.py +++ b/platypush/backend/http/app/routes/resources.py @@ -41,8 +41,11 @@ def resources_path(path): real_base_path = os.path.abspath(os.path.expanduser(resource_dirs[base_path])) real_path = real_base_path - file_path = [s for s in re.sub(r'^{}(.*)$'.format(base_path), '\\1', path) - .split('/') if s] + file_path = [ + s for s in re.sub( + r'^{}(.*)$'.format(base_path), '\\1', path # lgtm [py/regex-injection] + ).split('/') if s + ] for p in file_path[:-1]: real_path += os.sep + p diff --git a/platypush/backend/sensor/__init__.py b/platypush/backend/sensor/__init__.py index 7a57728948..31cb35af0a 100644 --- a/platypush/backend/sensor/__init__.py +++ b/platypush/backend/sensor/__init__.py @@ -1,4 +1,3 @@ -import threading import time from platypush.backend import Backend @@ -175,7 +174,7 @@ class SensorBackend(Backend): if plugin and hasattr(plugin, 'close'): plugin.close() - def process_data(self, new_data): + def process_data(self, *, new_data, **_): if new_data is not None and new_data not in ({}, []): self.bus.post(SensorDataChangeEvent(data=new_data, source=self.plugin or self.__class__.__name__)) diff --git a/platypush/message/event/__init__.py b/platypush/message/event/__init__.py index 8bd0ed981a..dc69214a16 100644 --- a/platypush/message/event/__init__.py +++ b/platypush/message/event/__init__.py @@ -65,7 +65,7 @@ class Event(Message): @staticmethod def _generate_id(): """ Generate a unique event ID """ - return hashlib.md5(str(uuid.uuid1()).encode()).hexdigest() + return hashlib.md5(str(uuid.uuid1()).encode()).hexdigest() # lgtm [py/weak-sensitive-data-hashing] def matches_condition(self, condition): """ diff --git a/platypush/plugins/camera/__init__.py b/platypush/plugins/camera/__init__.py index 2182add2da..ec81f15566 100644 --- a/platypush/plugins/camera/__init__.py +++ b/platypush/plugins/camera/__init__.py @@ -24,7 +24,7 @@ from platypush.plugins.camera.model.writer.preview import PreviewWriter, Preview from platypush.utils import get_plugin_name_by_class __all__ = ['Camera', 'CameraInfo', 'CameraException', 'CameraPlugin', 'CaptureAlreadyRunningException', - 'StreamWriter'] + 'VideoWriter', 'StreamWriter', 'PreviewWriter'] class CameraPlugin(Plugin, ABC): @@ -539,7 +539,10 @@ class CameraPlugin(Plugin, ABC): def _prepare_server_socket(camera: Camera) -> socket.socket: server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - server_socket.bind((camera.info.bind_address or '0.0.0.0', camera.info.listen_port)) + server_socket.bind(( + camera.info.bind_address or '0.0.0.0', # lgtm [py/bind-socket-all-network-interfaces] + camera.info.listen_port + )) server_socket.listen(1) server_socket.settimeout(1) return server_socket @@ -653,7 +656,8 @@ class CameraPlugin(Plugin, ABC): return { **camera.info.to_dict(), 'active': True if camera.capture_thread and camera.capture_thread.is_alive() else False, - 'capturing': True if camera.capture_thread and camera.capture_thread.is_alive() and camera.start_event.is_set() else False, + 'capturing': True if camera.capture_thread and camera.capture_thread.is_alive() and + camera.start_event.is_set() else False, 'streaming': camera.stream_thread and camera.stream_thread.is_alive() and camera.stream_event.is_set(), } diff --git a/platypush/schemas/__init__.py b/platypush/schemas/__init__.py index c0f4a71bf7..ca2805627c 100644 --- a/platypush/schemas/__init__.py +++ b/platypush/schemas/__init__.py @@ -21,7 +21,7 @@ class StrippedString(fields.Function): # lgtm [py/missing-call-to-init] return value.strip() -class DateTime(fields.Function): +class DateTime(fields.Function): # lgtm [py/missing-call-to-init] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.metadata = { @@ -38,7 +38,7 @@ class DateTime(fields.Function): return normalize_datetime(value) -class Date(fields.Function): +class Date(fields.Function): # lgtm [py/missing-call-to-init] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.metadata = {