mirror of
https://git.collinwebdesigns.de/oscar.krause/fastapi-dls.git
synced 2024-11-23 15:31:00 +03:00
code styling
This commit is contained in:
parent
afb38d628b
commit
1daa365df9
@ -28,23 +28,21 @@ class PatchMalformedJsonMiddleware(BaseHTTPMiddleware):
|
|||||||
# try to fix json
|
# try to fix json
|
||||||
try:
|
try:
|
||||||
j = json.loads(body)
|
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:
|
except json.decoder.JSONDecodeError:
|
||||||
logger.warning(f'Malformed json received! Try to fix it.')
|
logger.warning(f'Malformed json received! Try to fix it.')
|
||||||
body = PatchMalformedJsonMiddleware.fix_json(body)
|
body = PatchMalformedJsonMiddleware.fix_json(body)
|
||||||
logger.debug(f'Fixed JSON: "{body}"')
|
logger.debug(f'Fixed JSON: "{body}"')
|
||||||
j = json.loads(body) # ensure json is now valid
|
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
|
# set new body
|
||||||
request._body = json.dumps(j).encode('utf-8')
|
request._body = json.dumps(j).encode('utf-8')
|
||||||
|
|
||||||
response = await call_next(request)
|
response = await call_next(request)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def fix_mac_address_list_length(self, j: dict, size: int = 1) -> dict:
|
@staticmethod
|
||||||
if not self.enabled:
|
def __fix_mac_address_list_length(j: dict, size: int = 1) -> dict:
|
||||||
return j
|
|
||||||
|
|
||||||
# reduce "mac_address_list" to
|
# reduce "mac_address_list" to
|
||||||
environment = j.get('environment', {})
|
environment = j.get('environment', {})
|
||||||
fingerprint = environment.get('fingerprint', {})
|
fingerprint = environment.get('fingerprint', {})
|
||||||
|
Loading…
Reference in New Issue
Block a user