Hello community,
here is the log from the commit of package python-librouteros for
openSUSE:Leap:15.2 checked in at 2020-04-25 19:07:36
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Leap:15.2/python-librouteros (Old)
and /work/SRC/openSUSE:Leap:15.2/.python-librouteros.new.2738 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-librouteros"
Sat Apr 25 19:07:36 2020 rev:2 rq:797238 version:3.0.1
Changes:
--------
--- /work/SRC/openSUSE:Leap:15.2/python-librouteros/python-librouteros.changes
2020-03-27 16:48:21.559941615 +0100
+++
/work/SRC/openSUSE:Leap:15.2/.python-librouteros.new.2738/python-librouteros.changes
2020-04-25 19:08:06.955986729 +0200
@@ -1,0 +2,6 @@
+Mon Apr 20 17:58:37 UTC 2020 - Martin Hauke <[email protected]>
+
+- Update to version 3.0.1
+ * Add typing annotations
+
+-------------------------------------------------------------------
Old:
----
librouteros-3.0.0.tar.gz
New:
----
librouteros-3.0.1.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-librouteros.spec ++++++
--- /var/tmp/diff_new_pack.ANhofh/_old 2020-04-25 19:08:07.755988449 +0200
+++ /var/tmp/diff_new_pack.ANhofh/_new 2020-04-25 19:08:07.755988449 +0200
@@ -1,7 +1,7 @@
#
# spec file for package python-librouteros
#
-# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2020 SUSE LLC
# Copyright (c) 2017-2019, Martin Hauke <[email protected]>
#
# All modifications and additions to the file contributed by third parties
@@ -20,7 +20,7 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%define skip_python2 1
Name: python-librouteros
-Version: 3.0.0
+Version: 3.0.1
Release: 0
Summary: Python implementation of MikroTik RouterOS API
License: GPL-2.0-or-later
++++++ librouteros-3.0.0.tar.gz -> librouteros-3.0.1.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/.bumpversion.cfg
new/librouteros-3.0.1/.bumpversion.cfg
--- old/librouteros-3.0.0/.bumpversion.cfg 2019-11-06 21:27:52.000000000
+0100
+++ new/librouteros-3.0.1/.bumpversion.cfg 2020-04-17 22:30:50.000000000
+0200
@@ -1,5 +1,5 @@
[bumpversion]
-current_version = 3.0.0
+current_version = 3.0.1
commit = True
tag = True
tag_name = {new_version}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/.github/workflows/ci.yml
new/librouteros-3.0.1/.github/workflows/ci.yml
--- old/librouteros-3.0.0/.github/workflows/ci.yml 1970-01-01
01:00:00.000000000 +0100
+++ new/librouteros-3.0.1/.github/workflows/ci.yml 2020-04-17
22:30:50.000000000 +0200
@@ -0,0 +1,70 @@
+name: CI
+
+on:
+ - push
+ - pull_request
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ env:
+ CI: yes
+ strategy:
+ matrix:
+ python-version:
+ - 3.6
+ - 3.7
+ - 3.8
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+
+ - name: Set up Python ${{ matrix.python-version }}
+ uses: actions/setup-python@v1
+ with:
+ python-version: ${{ matrix.python-version }}
+
+ - name: Update apt
+ run: sudo apt update
+
+ - name: Install qemu
+ run: >
+ sudo apt-get install -yq --no-install-recommends
+ qemu-system-i386
+ qemu-utils
+
+ - name: Install test requirements
+ run: pip install -U -r requirements.tests.txt
+
+ - name: Install package
+ run: pip install -e .
+
+ - name: Lint
+ run: pylint librouteros
+
+ - name: Type check
+ run: mypy librouteros
+
+ - name: Format
+ run: >
+ yapf -dr
+ librouteros
+ tests
+
+ - name: Download routeros images
+ run: |
+ wget --quiet netng.pl/routeros_test_images/routeros_6.33.3.qcow2 -O
images/routeros_6.33.3.qcow2
+ wget --quiet netng.pl/routeros_test_images/routeros_6.44.5.qcow2 -O
images/routeros_6.44.5.qcow2
+
+ - name: Unit tests
+ run: pytest tests/unit
+
+ - name: Integration tests
+ run: pytest -n auto tests/integration
+
+ - name: Publish package
+ if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
&& matrix.python-version == '3.7' && success()
+ uses: pypa/gh-action-pypi-publish@master
+ with:
+ user: __token__
+ password: ${{ secrets.pypi_password }}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/.gitignore
new/librouteros-3.0.1/.gitignore
--- old/librouteros-3.0.0/.gitignore 2019-11-06 21:27:52.000000000 +0100
+++ new/librouteros-3.0.1/.gitignore 2020-04-17 22:30:50.000000000 +0200
@@ -17,6 +17,7 @@
#pytest cache
.cache
.pytest_cache
+.mypy_cache
# IDE stuff
.idea
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/.pylintrc
new/librouteros-3.0.1/.pylintrc
--- old/librouteros-3.0.0/.pylintrc 2019-11-06 21:27:52.000000000 +0100
+++ new/librouteros-3.0.1/.pylintrc 2020-04-17 22:30:50.000000000 +0200
@@ -65,6 +65,7 @@
missing-function-docstring,
unidiomatic-typecheck,
logging-format-interpolation,
+ trailing-newlines,
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/.travis.yml
new/librouteros-3.0.1/.travis.yml
--- old/librouteros-3.0.0/.travis.yml 2019-11-06 21:27:52.000000000 +0100
+++ new/librouteros-3.0.1/.travis.yml 1970-01-01 01:00:00.000000000 +0100
@@ -1,34 +0,0 @@
-notifications:
- email:
- on_success: change
- on_failure: change
-dist: bionic
-sudo: false
-language: python
-cache: pip
-python:
- - 3.6
- - 3.7
-addons:
- apt:
- packages:
- - qemu-system-i386
- - qemu-utils
-install:
- - pip install -U -r requirements.tests.txt
- - pip install -e .
-script:
- - pylint librouteros
- - yapf -dr librouteros
- - yapf -dr tests
- - wget --quiet netng.pl/routeros_test_images/routeros_6.33.3.qcow2 -O
images/routeros_6.33.3.qcow2
- - wget --quiet netng.pl/routeros_test_images/routeros_6.44.5.qcow2 -O
images/routeros_6.44.5.qcow2
- - pytest tests/unit
- - pytest -n auto tests/integration
-deploy:
- provider: pypi
- user: lkostka
- password: $PYPI_PASS
- on:
- tags: true
- python: 3.8
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/CHANGELOG.rst
new/librouteros-3.0.1/CHANGELOG.rst
--- old/librouteros-3.0.0/CHANGELOG.rst 2019-11-06 21:27:52.000000000 +0100
+++ new/librouteros-3.0.1/CHANGELOG.rst 2020-04-17 22:30:50.000000000 +0200
@@ -1,4 +1,10 @@
-3.0.0
+3.0.1
+__________
+
+- Add typing annotations
+
+
+3.0.1
----------
- Introduce query support.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/docs/path.rst
new/librouteros-3.0.1/docs/path.rst
--- old/librouteros-3.0.0/docs/path.rst 2019-11-06 21:27:52.000000000 +0100
+++ new/librouteros-3.0.1/docs/path.rst 2020-04-17 22:30:50.000000000 +0200
@@ -61,10 +61,11 @@
Arbitrary command
-----------------
For all other commands, call ``Path`` object directly.
+Remember to consume the result since it returns a generator.
As a first argument, pass command that you wish to run without absolute path.
.. code-block:: python
script = api.path('system', 'script')
# Will run /system/script/run with desired .id
- script('run', **{'.id': '*1'})
+ tuple(script('run', **{'.id': '*1'}))
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/librouteros/__init__.py
new/librouteros-3.0.1/librouteros/__init__.py
--- old/librouteros-3.0.0/librouteros/__init__.py 2019-11-06
21:27:52.000000000 +0100
+++ new/librouteros-3.0.1/librouteros/__init__.py 2020-04-17
22:30:50.000000000 +0200
@@ -1,5 +1,6 @@
# -*- coding: UTF-8 -*-
+import typing
from socket import create_connection
from collections import ChainMap
@@ -26,7 +27,7 @@
}
-def connect(host, username, password, **kwargs):
+def connect(host: str, username: str, password: str, **kwargs) ->
typing.Type[Api]:
"""
Connect and login to routeros device.
Upon success return a Api class.
@@ -54,7 +55,7 @@
raise
-def create_transport(host, **kwargs):
+def create_transport(host: str, **kwargs) -> SocketTransport:
sock = create_connection((host, kwargs['port']), kwargs['timeout'],
(kwargs['saddr'], 0))
sock = kwargs['ssl_wrapper'](sock)
return SocketTransport(sock=sock)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/librouteros/api.py
new/librouteros-3.0.1/librouteros/api.py
--- old/librouteros-3.0.0/librouteros/api.py 2019-11-06 21:27:52.000000000
+0100
+++ new/librouteros-3.0.1/librouteros/api.py 2020-04-17 22:30:50.000000000
+0200
@@ -1,21 +1,27 @@
# -*- coding: UTF-8 -*-
+import typing
from posixpath import join as pjoin
-
from librouteros.exceptions import TrapError, MultiTrapError
from librouteros.protocol import (
compose_word,
parse_word,
+ ApiProtocol,
+)
+from librouteros import query
+
+from librouteros.types import (
+ ReplyDict,
+ ResponseIter,
)
-from librouteros.query import Query
class Api:
- def __init__(self, protocol):
+ def __init__(self, protocol: ApiProtocol):
self.protocol = protocol
- def __call__(self, cmd, **kwargs):
+ def __call__(self, cmd: str, **kwargs: typing.Any) -> ResponseIter:
"""
Call Api with given command.
Yield each row.
@@ -27,7 +33,7 @@
self.protocol.writeSentence(cmd, *words)
yield from self.readResponse()
- def rawCmd(self, cmd, *words):
+ def rawCmd(self, cmd: str, *words: str) -> ResponseIter:
"""
Call Api with given command and raw words.
End user is responsible to properly format each api word argument.
@@ -37,17 +43,16 @@
self.protocol.writeSentence(cmd, *words)
yield from self.readResponse()
- def readSentence(self):
+ def readSentence(self) -> typing.Tuple[str, ReplyDict]:
"""
Read one sentence and parse words.
:returns: Reply word, dict with attribute words.
"""
reply_word, words = self.protocol.readSentence()
- words = dict(parse_word(word) for word in words)
- return reply_word, words
+ return reply_word, dict(parse_word(word) for word in words)
- def readResponse(self):
+ def readResponse(self) -> ResponseIter:
"""
Yield each sentence untill !done is received.
@@ -68,10 +73,10 @@
if len(traps) == 1:
raise traps[0]
- def close(self):
+ def close(self) -> None:
self.protocol.close()
- def path(self, *path):
+ def path(self, *path: str):
return Path(
path='',
api=self,
@@ -81,55 +86,55 @@
class Path:
"""Represents absolute command path."""
- def __init__(self, path, api):
+ def __init__(self, path: str, api: Api):
self.path = path
self.api = api
- def select(self, key, *other):
+ def select(self, key: query.Key, *other: query.Key) -> query.Query:
keys = (key, ) + other
- return Query(path=self, keys=keys, api=self.api)
+ return query.Query(path=self, keys=keys, api=self.api)
- def __str__(self):
+ def __str__(self) -> str:
return self.path
- def __repr__(self):
+ def __repr__(self) -> str:
return "<{module}.{cls} {path!r}>".format(
module=self.__class__.__module__,
cls=self.__class__.__name__,
path=self.path,
)
- def __iter__(self):
+ def __iter__(self) -> ResponseIter:
yield from self('print')
- def __call__(self, cmd, **kwargs):
+ def __call__(self, cmd: str, **kwargs: typing.Any) -> ResponseIter:
yield from self.api(
self.join(cmd).path,
**kwargs,
)
- def join(self, *path):
+ def join(self, *path: str):
"""Join current path with one or more path strings."""
return Path(
api=self.api,
path=pjoin('/', self.path, *path).rstrip('/'),
)
- def remove(self, *ids):
- ids = ','.join(ids)
+ def remove(self, *ids: str) -> None:
+ joined = ','.join(ids)
tuple(self(
'remove',
- **{'.id': ids},
+ **{'.id': joined},
))
- def add(self, **kwargs):
+ def add(self, **kwargs: typing.Any) -> str:
ret = self(
'add',
**kwargs,
)
return tuple(ret)[0]['ret']
- def update(self, **kwargs):
+ def update(self, **kwargs: typing.Any) -> None:
tuple(self(
'set',
**kwargs,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/librouteros/connections.py
new/librouteros-3.0.1/librouteros/connections.py
--- old/librouteros-3.0.0/librouteros/connections.py 2019-11-06
21:27:52.000000000 +0100
+++ new/librouteros-3.0.1/librouteros/connections.py 2020-04-17
22:30:50.000000000 +0200
@@ -1,21 +1,21 @@
# -*- coding: UTF-8 -*-
-
+from socket import socket
from librouteros.exceptions import ConnectionClosed
class SocketTransport:
- def __init__(self, sock):
+ def __init__(self, sock: socket):
self.sock = sock
- def write(self, data):
+ def write(self, data: bytes) -> None:
"""
Write given bytes to socket. Loop as long as every byte in
string is written unless exception is raised.
"""
self.sock.sendall(data)
- def read(self, length):
+ def read(self, length: int) -> bytes:
"""
Read as many bytes from socket as specified in length.
Loop as long as every byte is read unless exception is raised.
@@ -27,5 +27,5 @@
raise ConnectionClosed('Connection unexpectedly closed.')
return data
- def close(self):
+ def close(self) -> None:
self.sock.close()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/librouteros/exceptions.py
new/librouteros-3.0.1/librouteros/exceptions.py
--- old/librouteros-3.0.0/librouteros/exceptions.py 2019-11-06
21:27:52.000000000 +0100
+++ new/librouteros-3.0.1/librouteros/exceptions.py 2020-04-17
22:30:50.000000000 +0200
@@ -1,4 +1,5 @@
# -*- coding: UTF-8 -*-
+import typing
class LibRouterosError(Exception):
@@ -25,15 +26,15 @@
:param str message: Error message.
"""
- def __init__(self, message, category=None):
+ def __init__(self, message: str, category: typing.Union[None, int] = None):
self.category = category
self.message = message
super().__init__()
- def __str__(self):
+ def __str__(self) -> str:
return str(self.message.replace('\r\n', ','))
- def __repr__(self):
+ def __repr__(self) -> str:
return '{}({!r})'.format(self.__class__.__name__, str(self))
@@ -44,9 +45,9 @@
:param traps: TrapError instances.
"""
- def __init__(self, *traps):
+ def __init__(self, *traps: TrapError):
self.traps = traps
super().__init__()
- def __str__(self):
+ def __str__(self) -> str:
return ', '.join(str(trap) for trap in self.traps)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/librouteros/login.py
new/librouteros-3.0.1/librouteros/login.py
--- old/librouteros-3.0.0/librouteros/login.py 2019-11-06 21:27:52.000000000
+0100
+++ new/librouteros-3.0.1/librouteros/login.py 2020-04-17 22:30:50.000000000
+0200
@@ -1,19 +1,22 @@
+# -*- coding: UTF-8 -*-
+
+import typing
from binascii import unhexlify, hexlify
from hashlib import md5
-def encode_password(token, password):
+def encode_password(token: str, password: str) -> str:
#pylint: disable=redefined-outer-name
- token = token.encode('ascii', 'strict')
- token = unhexlify(token)
- password = password.encode('ascii', 'strict')
+ token_bytes = token.encode('ascii', 'strict')
+ token_bytes = unhexlify(token)
+ password_bytes = password.encode('ascii', 'strict')
hasher = md5()
- hasher.update(b'\x00' + password + token)
- password = hexlify(hasher.digest())
- return '00' + password.decode('ascii', 'strict')
+ hasher.update(b'\x00' + password_bytes + token_bytes)
+ password_bytes = hexlify(hasher.digest())
+ return '00' + password_bytes.decode('ascii', 'strict')
-def token(api, username, password):
+def token(api: typing.Any, username: str, password: str) -> None:
"""Login using pre routeros 6.43 authorization method."""
sentence = api('/login')
tok = tuple(sentence)[0]['ret']
@@ -21,6 +24,6 @@
tuple(api('/login', **{'name': username, 'response': encoded}))
-def plain(api, username, password):
+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}))
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/librouteros/protocol.py
new/librouteros-3.0.1/librouteros/protocol.py
--- old/librouteros-3.0.0/librouteros/protocol.py 2019-11-06
21:27:52.000000000 +0100
+++ new/librouteros-3.0.1/librouteros/protocol.py 2020-04-17
22:30:50.000000000 +0200
@@ -1,5 +1,6 @@
# -*- coding: UTF-8 -*-
+import typing
from struct import pack, unpack
from logging import getLogger, NullHandler
@@ -7,12 +8,13 @@
ProtocolError,
FatalError,
)
+from librouteros.connections import SocketTransport
LOGGER = getLogger('librouteros')
LOGGER.addHandler(NullHandler())
-def parse_word(word):
+def parse_word(word: str) -> typing.Tuple[str, typing.Any]:
"""
Split given attribute word to key, value pair.
@@ -24,24 +26,22 @@
mapping = {'yes': True, 'true': True, 'no': False, 'false': False}
_, key, value = word.split('=', 2)
try:
- value = int(value)
+ value = int(value) # type: ignore
except ValueError:
- value = mapping.get(value, value)
+ value = mapping.get(value, value) # type: ignore
return (key, value)
-def cast_to_api(value):
+def cast_to_api(value: typing.Any) -> str:
"""Cast python equivalent to API."""
mapping = {True: 'yes', False: 'no'}
# this is necesary because 1 == True, 0 == False
if type(value) == int:
- value = str(value)
- else:
- value = mapping.get(value, str(value))
- return value
+ return str(value)
+ return mapping.get(value, str(value))
-def compose_word(key, value):
+def compose_word(key: str, value: typing.Any) -> str:
"""
Create a attribute word from key, value pair.
Values are casted to api equivalents.
@@ -51,20 +51,19 @@
class Encoder:
- def encodeSentence(self, *words):
+ def encodeSentence(self, *words: str) -> bytes:
"""
Encode given sentence in API format.
:param words: Words to endoce.
:returns: Encoded sentence.
"""
- encoded = map(self.encodeWord, words)
- encoded = b''.join(encoded)
+ encoded = b''.join(self.encodeWord(word) for word in words)
# append EOS (end of sentence) byte
encoded += b'\x00'
return encoded
- def encodeWord(self, word):
+ def encodeWord(self, word: str) -> bytes:
"""
Encode word in API format.
@@ -72,11 +71,11 @@
:returns: Encoded word.
"""
#pylint: disable=no-member
- encoded_word = word.encode(encoding=self.encoding, errors='strict')
+ encoded_word = word.encode(encoding=self.encoding, errors='strict') #
type: ignore
return Encoder.encodeLength(len(word)) + encoded_word
@staticmethod
- def encodeLength(length):
+ def encodeLength(length: int) -> bytes:
"""
Encode given length in mikrotik format.
@@ -104,7 +103,7 @@
class Decoder:
@staticmethod
- def determineLength(length):
+ def determineLength(length: bytes) -> int:
"""
Given first read byte, determine how many more bytes
needs to be known in order to get fully encoded length.
@@ -124,10 +123,10 @@
elif integer < 240:
return 3
- raise ProtocolError('Unknown controll byte {}'.format(length))
+ raise ProtocolError('Unknown controll byte {!r}'.format(length))
@staticmethod
- def decodeLength(length):
+ def decodeLength(length: bytes) -> int:
"""
Decode length based on given bytes.
@@ -149,27 +148,27 @@
offset = b''
xor = 0xE0000000
else:
- raise ProtocolError('Unable to decode length of {}'.format(length))
+ raise ProtocolError('Unable to decode length of
{!r}'.format(length))
- decoded = unpack('!I', (offset + length))[0]
+ decoded: int = unpack('!I', (offset + length))[0]
decoded ^= xor
return decoded
class ApiProtocol(Encoder, Decoder):
- def __init__(self, transport, encoding):
+ def __init__(self, transport: SocketTransport, encoding: str):
self.transport = transport
self.encoding = encoding
@staticmethod
- def log(direction_string, *sentence):
+ def log(direction_string: str, *sentence: str) -> None:
for word in sentence:
LOGGER.debug('{0} {1!r}'.format(direction_string, word))
LOGGER.debug('{0} EOS'.format(direction_string))
- def writeSentence(self, cmd, *words):
+ def writeSentence(self, cmd: str, *words: str) -> None:
"""
Write encoded sentence.
@@ -180,7 +179,7 @@
self.log('<---', cmd, *words)
self.transport.write(encoded)
- def readSentence(self):
+ def readSentence(self) -> typing.Tuple[str, typing.Tuple[str, ...]]:
"""
Read every word untill empty word (NULL byte) is received.
@@ -194,7 +193,7 @@
raise FatalError(words[0])
return reply_word, words
- def readWord(self):
+ def readWord(self) -> str:
byte = self.transport.read(1)
# Early return check for null byte
if byte == b'\x00':
@@ -205,5 +204,5 @@
word = self.transport.read(length)
return word.decode(encoding=self.encoding, errors='strict')
- def close(self):
+ def close(self) -> None:
self.transport.close()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/librouteros/query.py
new/librouteros-3.0.1/librouteros/query.py
--- old/librouteros-3.0.0/librouteros/query.py 2019-11-06 21:27:52.000000000
+0100
+++ new/librouteros-3.0.1/librouteros/query.py 2020-04-17 22:30:50.000000000
+0200
@@ -1,13 +1,18 @@
# -*- coding: UTF-8 -*-
+import typing
from itertools import chain
from librouteros.protocol import (
cast_to_api,
)
+from librouteros.types import (
+ QueryGen,
+ ResponseIter,
+)
class Key:
- def __init__(self, name):
+ def __init__(self, name: str):
self.name = name
def __eq__(self, other):
@@ -23,30 +28,30 @@
def __gt__(self, other):
yield '?>{}={}'.format(self, cast_to_api(other))
- def __str__(self):
+ def __str__(self) -> str:
return str(self.name)
class Query:
- def __init__(self, path, keys, api):
+ def __init__(self, path, keys: typing.Sequence[Key], api):
self.path = path
self.keys = keys
self.api = api
- self.query = tuple()
+ self.query: typing.Tuple[str, ...] = tuple()
- def where(self, *args):
+ def where(self, *args: str):
self.query = tuple(chain.from_iterable(args))
return self
- def __iter__(self):
+ def __iter__(self) -> ResponseIter:
keys = ','.join(str(key) for key in self.keys)
keys = '=.proplist={}'.format(keys)
cmd = str(self.path.join('print'))
return iter(self.api.rawCmd(cmd, keys, *self.query))
-def And(left, right, *rest):
+def And(left: QueryGen, right: QueryGen, *rest: QueryGen) -> QueryGen:
#pylint: disable=invalid-name
yield from left
yield from right
@@ -55,7 +60,7 @@
yield from ('?#&', ) * len(rest)
-def Or(left, right, *rest):
+def Or(left: QueryGen, right: QueryGen, *rest: QueryGen) -> QueryGen:
#pylint: disable=invalid-name
yield from left
yield from right
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/librouteros/types.py
new/librouteros-3.0.1/librouteros/types.py
--- old/librouteros-3.0.0/librouteros/types.py 1970-01-01 01:00:00.000000000
+0100
+++ new/librouteros-3.0.1/librouteros/types.py 2020-04-17 22:30:50.000000000
+0200
@@ -0,0 +1,11 @@
+# -*- coding: UTF-8 -*-
+
+from typing import (
+ Dict,
+ Iterator,
+ Any,
+)
+
+ReplyDict = Dict[str, Any]
+ResponseIter = Iterator[ReplyDict]
+QueryGen = Iterator[str]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/requirements.tests.txt
new/librouteros-3.0.1/requirements.tests.txt
--- old/librouteros-3.0.0/requirements.tests.txt 2019-11-06
21:27:52.000000000 +0100
+++ new/librouteros-3.0.1/requirements.tests.txt 2020-04-17
22:30:50.000000000 +0200
@@ -3,3 +3,4 @@
pydocstyle
yapf
pylint
+mypy
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/setup.py
new/librouteros-3.0.1/setup.py
--- old/librouteros-3.0.0/setup.py 2019-11-06 21:27:52.000000000 +0100
+++ new/librouteros-3.0.1/setup.py 2020-04-17 22:30:50.000000000 +0200
@@ -28,7 +28,7 @@
setup_requires=setup_pkgs,
zip_safe=False,
name='librouteros',
- version='3.0.0',
+ version='3.0.1',
description='Python implementation of MikroTik RouterOS API',
long_description=read('README.rst'),
author='Ćukasz Kostka',
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/librouteros-3.0.0/tests/integration/conftest.py
new/librouteros-3.0.1/tests/integration/conftest.py
--- old/librouteros-3.0.0/tests/integration/conftest.py 2019-11-06
21:27:52.000000000 +0100
+++ new/librouteros-3.0.1/tests/integration/conftest.py 2020-04-17
22:30:50.000000000 +0200
@@ -64,7 +64,7 @@
'Darwin': 'hvf',
'Linux': 'kvm',
}
- if environ.get('TRAVIS') and environ.get('CI'):
+ if environ.get('CI'):
accel['Linux'] = 'tcg'
cmd = [
'qemu-system-x86_64',