add a Response subclass just to take RPL_/ERR_ names along with params

This commit is contained in:
jesopo 2020-04-05 17:16:19 +01:00
parent 0829fd9499
commit 423623fec1

View file

@ -3,16 +3,6 @@ from irctokens import Line
from .numerics import NUMERIC_NAMES
from .interface import IServer, IMatchResponse, IMatchResponseParam
class Numerics(IMatchResponse):
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, server: IServer, line: Line):
return line.command in self._numerics
class Response(IMatchResponse):
def __init__(self,
command: str,
@ -33,6 +23,22 @@ class Response(IMatchResponse):
else:
return False
class Numeric(Response):
def __init__(self,
name: str,
params: List[IMatchResponseParam]=[]):
super().__init__(NUMERIC_NAMES.get(name, name), params)
class Numerics(IMatchResponse):
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, server: IServer, line: Line):
return line.command in self._numerics
class ResponseOr(IMatchResponse):
def __init__(self, *responses: IMatchResponse):
self._responses = responses