reverted to official librouteros #9

This commit is contained in:
tomaae 2020-03-16 18:33:51 +01:00
parent 25e90702d2
commit 3cf637d1ba
9 changed files with 31 additions and 621 deletions

View file

@ -1,64 +0,0 @@
# -*- coding: UTF-8 -*-
from itertools import chain
from .protocol import (
cast_to_api,
)
class Key:
def __init__(self, name):
self.name = name
def __eq__(self, other):
yield '?={}={}'.format(self, cast_to_api(other))
def __ne__(self, other):
yield from self == other
yield '?#!'
def __lt__(self, other):
yield '?<{}={}'.format(self, cast_to_api(other))
def __gt__(self, other):
yield '?>{}={}'.format(self, cast_to_api(other))
def __str__(self):
return str(self.name)
class Query:
def __init__(self, path, keys, api):
self.path = path
self.keys = keys
self.api = api
self.query = tuple()
def where(self, *args):
self.query = tuple(chain.from_iterable(args))
return self
def __iter__(self):
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):
#pylint: disable=invalid-name
yield from left
yield from right
yield from chain.from_iterable(rest)
yield '?#&'
yield from ('?#&', ) * len(rest)
def Or(left, right, *rest):
#pylint: disable=invalid-name
yield from left
yield from right
yield from chain.from_iterable(rest)
yield '?#|'
yield from ('?#|', ) * len(rest)