fix mypy
This commit is contained in:
parent
e7f5d0846f
commit
e7c03f8cf0
4 changed files with 20 additions and 16 deletions
|
|
@ -8,4 +8,4 @@ def get_resolver_with_public_nameserver() -> AsyncResolver:
|
|||
|
||||
async def resolve(host: str) -> str:
|
||||
hosts = await get_resolver_with_public_nameserver().resolve(host)
|
||||
return hosts[0]["host"]
|
||||
return hosts[0]["host"] # type:ignore[no-any-return]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"""Web server middleware module."""
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
from aiohttp import web
|
||||
from aiohttp.typedefs import Handler
|
||||
|
|
@ -13,7 +14,7 @@ _LOGGER = get_logger("webserver_requests")
|
|||
|
||||
|
||||
class CustomEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
def default(self, obj: Any) -> Any:
|
||||
if isinstance(obj, set):
|
||||
return list(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
|
@ -32,9 +33,14 @@ async def log_all_requests(request: Request, handler: Handler) -> StreamResponse
|
|||
"path": request.path,
|
||||
"query_string": request.query_string,
|
||||
"headers": {h for h in request.headers.items()},
|
||||
"route_resource": request.match_info.route.resource.canonical,
|
||||
}
|
||||
}
|
||||
|
||||
if request.match_info.route.resource:
|
||||
to_log["request"][
|
||||
"route_resource"
|
||||
] = request.match_info.route.resource.canonical
|
||||
|
||||
try:
|
||||
if request.content_length:
|
||||
if request.content_type == "application/json":
|
||||
|
|
@ -44,7 +50,7 @@ async def log_all_requests(request: Request, handler: Handler) -> StreamResponse
|
|||
|
||||
response = await handler(request)
|
||||
if response is None:
|
||||
confserverlog.warning( # type:ignore[unreachable]
|
||||
_LOGGER.warning( # type:ignore[unreachable]
|
||||
"Response was null!"
|
||||
)
|
||||
_LOGGER.warning(json.dumps(to_log, cls=CustomEncoder))
|
||||
|
|
@ -55,6 +61,7 @@ async def log_all_requests(request: Request, handler: Handler) -> StreamResponse
|
|||
}
|
||||
|
||||
if isinstance(response, Response) and response.body:
|
||||
assert response.text
|
||||
if response.content_type == "application/json":
|
||||
to_log["response"]["body"] = json.loads(response.text)
|
||||
elif response.content_type.startswith("text"):
|
||||
|
|
|
|||
|
|
@ -319,7 +319,7 @@ class WebServer:
|
|||
if request.content.total_bytes > 0:
|
||||
read_body = await request.read()
|
||||
proxymodelog.info(
|
||||
f"HTTP Proxy Request to EcoVacs (body=true) (URL:{request.url}) - {read_body}"
|
||||
f"HTTP Proxy Request to EcoVacs (body=true) (URL:{request.url}) - {read_body.decode('utf-8')}"
|
||||
)
|
||||
if request.content_type == "application/x-www-form-urlencoded":
|
||||
# android apps use form
|
||||
|
|
@ -349,10 +349,10 @@ class WebServer:
|
|||
)
|
||||
async with session.request(request.method, request.url) as resp:
|
||||
if resp.content_type == "application/octet-stream":
|
||||
response = await resp.read()
|
||||
proxymodelog.info(
|
||||
f"HTTP Proxy Response from EcoVacs (URL: {request.url}) - (Status: {resp.status}) - <BYTES CONTENT>"
|
||||
)
|
||||
return web.Response(body=await resp.read())
|
||||
else:
|
||||
response = await resp.text()
|
||||
proxymodelog.info(
|
||||
|
|
@ -363,14 +363,10 @@ class WebServer:
|
|||
if resp.content_type == "application/json":
|
||||
response = json.loads(response)
|
||||
return web.json_response(response)
|
||||
elif resp.content_type == "application/octet-stream":
|
||||
if resp.content_type == "application/octet-stream":
|
||||
return web.Response(body=response)
|
||||
else:
|
||||
return web.Response(text=response)
|
||||
|
||||
else:
|
||||
return web.Response(text=response)
|
||||
|
||||
except asyncio.CancelledError:
|
||||
proxymodelog.exception(
|
||||
f"Request cancelled or timeout - {request.url}", exc_info=True
|
||||
|
|
|
|||
|
|
@ -314,8 +314,8 @@ class XMPPAsyncClient:
|
|||
xmppserverlog.info(
|
||||
"Bot reported user has no permissions, Bumper will attempt to add user to bot. This is typical if bot was last on Ecovacs Network."
|
||||
)
|
||||
xquery = xml.getchildren()
|
||||
ctl = xquery[0].getchildren()
|
||||
xquery = list(xml)
|
||||
ctl = list(xquery[0])
|
||||
if "error" in ctl[0].attrib:
|
||||
ctlerr = ctl[0].attrib["error"]
|
||||
adminuser = ctlerr.replace(
|
||||
|
|
@ -328,7 +328,8 @@ class XMPPAsyncClient:
|
|||
adminuser.startswith("fuid_")
|
||||
or adminuser.startswith("fusername_")
|
||||
or bumper.use_auth
|
||||
): # if not fuid_ then its ecovacs OR ignore bumper auth
|
||||
):
|
||||
# if not fuid_ then its ecovacs OR ignore bumper auth
|
||||
# TODO: Implement auth later, should this user have access to bot?
|
||||
|
||||
# Add user jid to bot
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue