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,
|
||||
numerics: List[str]):
|
||||
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):
|
||||
return line.command in self._numerics
|
||||
|
@ -24,6 +26,8 @@ class Response(BaseResponse):
|
|||
params: List[ResponseParam]):
|
||||
self._command = command
|
||||
self._params = params
|
||||
def __repr__(self) -> str:
|
||||
return f"Response({self._command}: {self._params!r})"
|
||||
|
||||
def match(self, line: Line) -> bool:
|
||||
if line.command == self._command:
|
||||
|
@ -39,6 +43,8 @@ class Response(BaseResponse):
|
|||
class ResponseOr(BaseResponse):
|
||||
def __init__(self, *responses: BaseResponse):
|
||||
self._responses = responses
|
||||
def __repr__(self) -> str:
|
||||
return f"ResponseOr({self._responses!r})"
|
||||
def match(self, line: Line) -> bool:
|
||||
for response in self._responses:
|
||||
if response.match(line):
|
||||
|
@ -47,15 +53,21 @@ class ResponseOr(BaseResponse):
|
|||
return False
|
||||
|
||||
class ParamAny(ResponseParam):
|
||||
def __repr__(self) -> str:
|
||||
return "Any()"
|
||||
def match(self, arg: str) -> bool:
|
||||
return True
|
||||
class ParamLiteral(ResponseParam):
|
||||
def __init__(self, value: str):
|
||||
self._value = value
|
||||
def __repr__(self) -> str:
|
||||
return f"Literal({self._value!r})"
|
||||
def match(self, arg: str) -> bool:
|
||||
return self._value == arg
|
||||
class ParamNot(ResponseParam):
|
||||
def __init__(self, param: ResponseParam):
|
||||
self._param = param
|
||||
def __repr__(self) -> str:
|
||||
return f"Not({self._param!r})"
|
||||
def match(self, arg: str) -> bool:
|
||||
return not self._param.match(arg)
|
||||
|
|
|
@ -35,10 +35,9 @@ class Server(IServer):
|
|||
self._read_queue: Queue[Tuple[Line, List[Emit]]] = Queue()
|
||||
self._cap_queue: Set[ICapability] = set([])
|
||||
|
||||
async def send_raw(self, line: str, priority=SendPriority.DEFAULT
|
||||
) -> SentLine:
|
||||
async def send_raw(self, line: str, priority=SendPriority.DEFAULT):
|
||||
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)
|
||||
await self._write_queue.put(prio_line)
|
||||
await prio_line.future
|
||||
|
|
Loading…
Reference in a new issue