From 1daa365df9afdd08ef27ce5684be1b27db1241e8 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Fri, 22 Nov 2024 15:00:16 +0100 Subject: [PATCH] code styling --- app/middleware.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/middleware.py b/app/middleware.py index 2e7ce27..4f66ced 100644 --- a/app/middleware.py +++ b/app/middleware.py @@ -28,23 +28,21 @@ class PatchMalformedJsonMiddleware(BaseHTTPMiddleware): # try to fix json try: j = json.loads(body) - self.fix_mac_address_list_length(j=j, size=1) + self.__fix_mac_address_list_length(j=j, size=1) except json.decoder.JSONDecodeError: logger.warning(f'Malformed json received! Try to fix it.') body = PatchMalformedJsonMiddleware.fix_json(body) logger.debug(f'Fixed JSON: "{body}"') j = json.loads(body) # ensure json is now valid - j = self.fix_mac_address_list_length(j=j, size=1) + j = self.__fix_mac_address_list_length(j=j, size=1) # set new body request._body = json.dumps(j).encode('utf-8') response = await call_next(request) return response - def fix_mac_address_list_length(self, j: dict, size: int = 1) -> dict: - if not self.enabled: - return j - + @staticmethod + def __fix_mac_address_list_length(j: dict, size: int = 1) -> dict: # reduce "mac_address_list" to environment = j.get('environment', {}) fingerprint = environment.get('fingerprint', {})