add __repr__ for matching.py objects
This commit is contained in:
parent
688418df04
commit
404154e6a2
2 changed files with 14 additions and 3 deletions
|
@ -14,6 +14,8 @@ class Numerics(BaseResponse):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
numerics: List[str]):
|
numerics: List[str]):
|
||||||
self._numerics = [NUMERIC_NAMES.get(n, n) for n in numerics]
|
self._numerics = [NUMERIC_NAMES.get(n, n) for n in numerics]
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f"Numerics({self._numerics!r})"
|
||||||
|
|
||||||
def match(self, line: Line):
|
def match(self, line: Line):
|
||||||
return line.command in self._numerics
|
return line.command in self._numerics
|
||||||
|
@ -24,6 +26,8 @@ class Response(BaseResponse):
|
||||||
params: List[ResponseParam]):
|
params: List[ResponseParam]):
|
||||||
self._command = command
|
self._command = command
|
||||||
self._params = params
|
self._params = params
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f"Response({self._command}: {self._params!r})"
|
||||||
|
|
||||||
def match(self, line: Line) -> bool:
|
def match(self, line: Line) -> bool:
|
||||||
if line.command == self._command:
|
if line.command == self._command:
|
||||||
|
@ -39,6 +43,8 @@ class Response(BaseResponse):
|
||||||
class ResponseOr(BaseResponse):
|
class ResponseOr(BaseResponse):
|
||||||
def __init__(self, *responses: BaseResponse):
|
def __init__(self, *responses: BaseResponse):
|
||||||
self._responses = responses
|
self._responses = responses
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f"ResponseOr({self._responses!r})"
|
||||||
def match(self, line: Line) -> bool:
|
def match(self, line: Line) -> bool:
|
||||||
for response in self._responses:
|
for response in self._responses:
|
||||||
if response.match(line):
|
if response.match(line):
|
||||||
|
@ -47,15 +53,21 @@ class ResponseOr(BaseResponse):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class ParamAny(ResponseParam):
|
class ParamAny(ResponseParam):
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return "Any()"
|
||||||
def match(self, arg: str) -> bool:
|
def match(self, arg: str) -> bool:
|
||||||
return True
|
return True
|
||||||
class ParamLiteral(ResponseParam):
|
class ParamLiteral(ResponseParam):
|
||||||
def __init__(self, value: str):
|
def __init__(self, value: str):
|
||||||
self._value = value
|
self._value = value
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f"Literal({self._value!r})"
|
||||||
def match(self, arg: str) -> bool:
|
def match(self, arg: str) -> bool:
|
||||||
return self._value == arg
|
return self._value == arg
|
||||||
class ParamNot(ResponseParam):
|
class ParamNot(ResponseParam):
|
||||||
def __init__(self, param: ResponseParam):
|
def __init__(self, param: ResponseParam):
|
||||||
self._param = param
|
self._param = param
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f"Not({self._param!r})"
|
||||||
def match(self, arg: str) -> bool:
|
def match(self, arg: str) -> bool:
|
||||||
return not self._param.match(arg)
|
return not self._param.match(arg)
|
||||||
|
|
|
@ -35,10 +35,9 @@ class Server(IServer):
|
||||||
self._read_queue: Queue[Tuple[Line, List[Emit]]] = Queue()
|
self._read_queue: Queue[Tuple[Line, List[Emit]]] = Queue()
|
||||||
self._cap_queue: Set[ICapability] = set([])
|
self._cap_queue: Set[ICapability] = set([])
|
||||||
|
|
||||||
async def send_raw(self, line: str, priority=SendPriority.DEFAULT
|
async def send_raw(self, line: str, priority=SendPriority.DEFAULT):
|
||||||
) -> SentLine:
|
|
||||||
await self.send(tokenise(line), priority)
|
await self.send(tokenise(line), priority)
|
||||||
async def send(self, line: Line, priority=SendPriority.DEFAULT) -> SentLine:
|
async def send(self, line: Line, priority=SendPriority.DEFAULT):
|
||||||
prio_line = SentLine(priority, line)
|
prio_line = SentLine(priority, line)
|
||||||
await self._write_queue.put(prio_line)
|
await self._write_queue.put(prio_line)
|
||||||
await prio_line.future
|
await prio_line.future
|
||||||
|
|
Loading…
Reference in a new issue