# Path: librouteros/protocol.py
# 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:
#         return str(value)
#     return mapping.get(value, str(value))
# 
# Path: librouteros/types.py



import typing
from itertools import chain
from librouteros.protocol import (
    cast_to_api,
)
from librouteros.types import (
    QueryGen,
    ResponseIter,
)


class Query:

    def __init__(self, path, keys: typing.Sequence[Key], api):
        self.path = path
        self.keys = keys
        self.api = api
        self.query: typing.Tuple[str, ...] = tuple()

    def where(self, *args: str):
        self.query = tuple(chain.from_iterable(args))
        return self

    def __iter__(self) -> ResponseIter:
        keys = ','.join(str(key) for key in self.keys)
        keys = f'=.proplist={keys}'
        cmd = str(self.path.join('print'))
        return iter(self.api.rawCmd(cmd, keys, *self.query))


def And(left: QueryGen, right: QueryGen, *rest: QueryGen) -> QueryGen:
    #pylint: disable=invalid-name
    yield from left
    yield from right
    yield from chain.from_iterable(rest)
    yield '?#&'
    yield from ('?#&', ) * len(rest)



# Path: librouteros/protocol.py
# 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:
#         return str(value)
#     return mapping.get(value, str(value))
# 
# Path: librouteros/types.py



# Path: librouteros/query.py
import typing
from itertools import chain
from librouteros.protocol import (
    cast_to_api,
)
from librouteros.types import (
    QueryGen,
    ResponseIter,
)



class Query:

    def __init__(self, path, keys: typing.Sequence[Key], api):
        self.path = path
        self.keys = keys
        self.api = api
        self.query: typing.Tuple[str, ...] = tuple()

    def where(self, *args: str):
        self.query = tuple(chain.from_iterable(args))
        return self

    def __iter__(self) -> ResponseIter:
        keys = ','.join(str(key) for key in self.keys)
        keys = f'=.proplist={keys}'
        cmd = str(self.path.join('print'))
        return iter(self.api.rawCmd(cmd, keys, *self.query))


def And(left: QueryGen, right: QueryGen, *rest: QueryGen) -> QueryGen:
    #pylint: disable=invalid-name
    yield from left
    yield from right
    yield from chain.from_iterable(rest)
    yield '?#&'
    yield from ('?#&', ) * len(rest)



def Or(left: QueryGen, right: QueryGen, *rest: QueryGen) -> QueryGen: