flake8 linting
This commit is contained in:
@@ -4,12 +4,15 @@ import os
|
||||
import os.path
|
||||
import typing
|
||||
|
||||
import jinja2
|
||||
|
||||
import quart.templating
|
||||
|
||||
import quart_trio
|
||||
|
||||
import capport.comm.hub
|
||||
import capport.config
|
||||
import capport.utils.ipneigh
|
||||
import jinja2
|
||||
import quart.templating
|
||||
import quart_trio
|
||||
|
||||
|
||||
class DispatchingJinjaLoader(quart.templating.DispatchingJinjaLoader):
|
||||
|
@@ -4,13 +4,14 @@ import ipaddress
|
||||
import typing
|
||||
|
||||
import quart
|
||||
from werkzeug.http import parse_list_header
|
||||
|
||||
import werkzeug
|
||||
from werkzeug.http import parse_list_header
|
||||
|
||||
from .app import app
|
||||
|
||||
|
||||
def _get_first_in_list(value_list: typing.Optional[str], allowed: typing.Sequence[str]=()) -> typing.Optional[str]:
|
||||
def _get_first_in_list(value_list: typing.Optional[str], allowed: typing.Sequence[str] = ()) -> typing.Optional[str]:
|
||||
if not value_list:
|
||||
return None
|
||||
values = parse_list_header(value_list)
|
||||
@@ -21,6 +22,8 @@ def _get_first_in_list(value_list: typing.Optional[str], allowed: typing.Sequenc
|
||||
|
||||
|
||||
def local_proxy_fix(request: quart.Request):
|
||||
if not request.remote_addr:
|
||||
return
|
||||
try:
|
||||
addr = ipaddress.ip_address(request.remote_addr)
|
||||
except ValueError:
|
||||
|
@@ -3,13 +3,13 @@ from __future__ import annotations
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
import capport.database
|
||||
import capport.comm.hub
|
||||
import capport.comm.message
|
||||
import capport.utils.cli
|
||||
import capport.utils.ipneigh
|
||||
import trio
|
||||
|
||||
import capport.comm.hub
|
||||
import capport.comm.message
|
||||
import capport.database
|
||||
import capport.utils.cli
|
||||
import capport.utils.ipneigh
|
||||
from capport.utils.sd_notify import open_sdnotify
|
||||
|
||||
from .app import app
|
||||
@@ -19,7 +19,12 @@ _logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ApiHubApp(capport.comm.hub.HubApplication):
|
||||
async def mac_states_changed(self, *, from_peer_id: uuid.UUID, pending_updates: capport.database.PendingUpdates) -> None:
|
||||
async def mac_states_changed(
|
||||
self,
|
||||
*,
|
||||
from_peer_id: uuid.UUID,
|
||||
pending_updates: capport.database.PendingUpdates,
|
||||
) -> None:
|
||||
# TODO: support websocket notification updates to clients?
|
||||
pass
|
||||
|
||||
|
@@ -4,13 +4,15 @@ import ipaddress
|
||||
import logging
|
||||
import typing
|
||||
|
||||
import quart
|
||||
|
||||
import trio
|
||||
|
||||
import capport.comm.hub
|
||||
import capport.comm.message
|
||||
import capport.database
|
||||
import capport.utils.cli
|
||||
import capport.utils.ipneigh
|
||||
import quart
|
||||
import trio
|
||||
from capport import cptypes
|
||||
|
||||
from .app import app
|
||||
@@ -20,22 +22,27 @@ _logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_client_ip() -> cptypes.IPAddress:
|
||||
remote_addr = quart.request.remote_addr
|
||||
if not remote_addr:
|
||||
quart.abort(500, 'Missing client address')
|
||||
try:
|
||||
addr = ipaddress.ip_address(quart.request.remote_addr)
|
||||
addr = ipaddress.ip_address(remote_addr)
|
||||
except ValueError as e:
|
||||
_logger.warning(f'Invalid client address {quart.request.remote_addr!r}: {e}')
|
||||
_logger.warning(f'Invalid client address {remote_addr!r}: {e}')
|
||||
quart.abort(500, 'Invalid client address')
|
||||
return addr
|
||||
|
||||
|
||||
async def get_client_mac_if_present(address: typing.Optional[cptypes.IPAddress]=None) -> typing.Optional[cptypes.MacAddress]:
|
||||
async def get_client_mac_if_present(
|
||||
address: typing.Optional[cptypes.IPAddress] = None,
|
||||
) -> typing.Optional[cptypes.MacAddress]:
|
||||
assert app.my_nc # for mypy
|
||||
if not address:
|
||||
address = get_client_ip()
|
||||
return await app.my_nc.get_neighbor_mac(address)
|
||||
|
||||
|
||||
async def get_client_mac(address: typing.Optional[cptypes.IPAddress]=None) -> cptypes.MacAddress:
|
||||
async def get_client_mac(address: typing.Optional[cptypes.IPAddress] = None) -> cptypes.MacAddress:
|
||||
mac = await get_client_mac_if_present(address)
|
||||
if mac is None:
|
||||
_logger.warning(f"Couldn't find MAC addresss for {address}")
|
||||
@@ -109,7 +116,7 @@ def check_self_origin():
|
||||
|
||||
|
||||
@app.route('/', methods=['GET'])
|
||||
async def index(missing_accept: bool=False):
|
||||
async def index(missing_accept: bool = False):
|
||||
state = await user_lookup()
|
||||
if not state.mac:
|
||||
return await render_i18n_template('index_unknown.html', state=state, missing_accept=missing_accept)
|
||||
|
Reference in New Issue
Block a user