diff --git a/apicli.py b/apicli.py index bcce31a..2fa2f2c 100755 --- a/apicli.py +++ b/apicli.py @@ -3,7 +3,6 @@ """Command line interface for debugging purpouses.""" - import logging import getpass from argparse import ArgumentParser @@ -14,19 +13,16 @@ from librouteros import connect from librouteros.exceptions import TrapError, FatalError -argParser = ArgumentParser(description='mikrotik api cli interface') -argParser.add_argument( - 'host', type=str, - help="host to with to connect. may be fqdn, ipv4 or ipv6 address") -argParser.add_argument('-u', '--user', type=str, required=True, help="username") -argParser.add_argument( - '-p', '--port', type=int, default=8728, help="port to connect to (default 8728)") +argParser = ArgumentParser(description="mikrotik api cli interface") +argParser.add_argument("host", type=str, help="host to with to connect. may be fqdn, ipv4 or ipv6 address") +argParser.add_argument("-u", "--user", type=str, required=True, help="username") +argParser.add_argument("-p", "--port", type=int, default=8728, help="port to connect to (default 8728)") args = argParser.parse_args() -mainlog = logging.getLogger('librouteros') +mainlog = logging.getLogger("librouteros") console = logging.StreamHandler(stdout) mainlog.setLevel(logging.DEBUG) -formatter = logging.Formatter(fmt='%(message)s') +formatter = logging.Formatter(fmt="%(message)s") console.setFormatter(formatter) mainlog.addHandler(console) @@ -72,5 +68,5 @@ def main(): api.close() -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/librouteros/__init__.py b/librouteros/__init__.py index 1b75086..6cb6bbb 100644 --- a/librouteros/__init__.py +++ b/librouteros/__init__.py @@ -14,7 +14,7 @@ from librouteros.login import ( plain, token, # noqa: F401 BACK_COMP - async_plain + async_plain, ) from librouteros.api import Api, AsyncApi diff --git a/librouteros/api.py b/librouteros/api.py index 15221c7..a2c135a 100644 --- a/librouteros/api.py +++ b/librouteros/api.py @@ -137,11 +137,12 @@ def add(self, **kwargs: typing.Any) -> str: def update(self, **kwargs: typing.Any) -> None: tuple( - self( - "set", - **kwargs, - ) - ) + self( + "set", + **kwargs, + ) + ) + class AsyncApi: def __init__(self, protocol: AsyncApiProtocol): diff --git a/librouteros/login.py b/librouteros/login.py index ba3e784..77b97de 100644 --- a/librouteros/login.py +++ b/librouteros/login.py @@ -28,5 +28,6 @@ def plain(api: typing.Any, username: str, password: str) -> None: """Login using post routeros 6.43 authorization method.""" tuple(api("/login", **{"name": username, "password": password})) + async def async_plain(api, username, password): - [response async for response in api("/login", **{"name": username, "password": password})] \ No newline at end of file + [response async for response in api("/login", **{"name": username, "password": password})] diff --git a/librouteros/protocol.py b/librouteros/protocol.py index 37d21e3..e0c96a4 100644 --- a/librouteros/protocol.py +++ b/librouteros/protocol.py @@ -204,6 +204,7 @@ def readWord(self) -> str: def close(self) -> None: self.transport.close() + class AsyncApiProtocol(Encoder, Decoder): def __init__(self, transport: AsyncSocketTransport, encoding: str, timeout: float): self.transport = transport diff --git a/librouteros/query.py b/librouteros/query.py index ec7f2cc..bac378b 100644 --- a/librouteros/query.py +++ b/librouteros/query.py @@ -72,6 +72,7 @@ def Or(left: QueryGen, right: QueryGen, *rest: QueryGen) -> QueryGen: yield "?#|" yield from ("?#|",) * len(rest) + class AsyncQuery: def __init__(self, path, keys: typing.Sequence[Key], api): self.path = path