Pass extra info to argument parsers and add dateparser to temporary dockerfile dependencies

This commit is contained in:
Tulir Asokan 2019-06-08 12:31:38 +03:00
parent b137d0686f
commit e565b99826
2 changed files with 8 additions and 7 deletions

View File

@ -24,8 +24,8 @@ RUN apk add --no-cache \
py3-pillow \ py3-pillow \
py3-magic \ py3-magic \
py3-psycopg2 \ py3-psycopg2 \
&& pip3 install -r requirements.txt feedparser && pip3 install -r requirements.txt feedparser dateparser
# TODO require pillow, magic and feedparser when maubot supports installing dependencies # TODO remove pillow, magic and feedparser when maubot supports installing dependencies
VOLUME /data VOLUME /data

View File

@ -126,7 +126,8 @@ class CommandHandler:
remaining_val: str) -> Tuple[bool, str]: remaining_val: str) -> Tuple[bool, str]:
for arg in self.__mb_arguments__: for arg in self.__mb_arguments__:
try: try:
remaining_val, call_args[arg.name] = arg.match(remaining_val.strip()) remaining_val, call_args[arg.name] = arg.match(remaining_val.strip(), evt=evt,
instance=self.__bound_instance__)
if arg.required and not call_args[arg.name]: if arg.required and not call_args[arg.name]:
raise ValueError("Argument required") raise ValueError("Argument required")
except ArgumentSyntaxError as e: except ArgumentSyntaxError as e:
@ -260,7 +261,7 @@ class Argument(ABC):
self.pass_raw = pass_raw self.pass_raw = pass_raw
@abstractmethod @abstractmethod
def match(self, val: str) -> Tuple[str, Any]: def match(self, val: str, **kwargs) -> Tuple[str, Any]:
pass pass
def __call__(self, func: Union[CommandHandler, CommandHandlerFunc]) -> CommandHandler: def __call__(self, func: Union[CommandHandler, CommandHandlerFunc]) -> CommandHandler:
@ -277,7 +278,7 @@ class RegexArgument(Argument):
matches = f"^{matches}" if self.pass_raw else f"^{matches}$" matches = f"^{matches}" if self.pass_raw else f"^{matches}$"
self.regex = re.compile(matches) self.regex = re.compile(matches)
def match(self, val: str) -> Tuple[str, Any]: def match(self, val: str, **kwargs) -> Tuple[str, Any]:
orig_val = val orig_val = val
if not self.pass_raw: if not self.pass_raw:
val = val.split(" ")[0] val = val.split(" ")[0]
@ -294,7 +295,7 @@ class CustomArgument(Argument):
super().__init__(name, label, required=required, pass_raw=pass_raw) super().__init__(name, label, required=required, pass_raw=pass_raw)
self.matcher = matcher self.matcher = matcher
def match(self, val: str) -> Tuple[str, Any]: def match(self, val: str, **kwargs) -> Tuple[str, Any]:
if self.pass_raw: if self.pass_raw:
return self.matcher(val) return self.matcher(val)
orig_val = val orig_val = val
@ -306,7 +307,7 @@ class CustomArgument(Argument):
class SimpleArgument(Argument): class SimpleArgument(Argument):
def match(self, val: str) -> Tuple[str, Any]: def match(self, val: str, **kwargs) -> Tuple[str, Any]:
if self.pass_raw: if self.pass_raw:
return "", val return "", val
res = val.split(" ")[0] res = val.split(" ")[0]