From f05fc209b015e9d883566fc8cc4141dc9eff4db3 Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 14 Jun 2019 12:01:55 +0100 Subject: Add a way to __or__ `utils.Check`s, as a "if one of these passes" thing --- src/utils/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 869690ff..c0acee4d 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -185,10 +185,19 @@ def export(setting: str, value: typing.Any): return module return _export_func +class MultiCheck(object): + def __init__(self, + requests: typing.List[typing.Tuple[str, typing.List[str]]]): + self.requests = requests class Check(object): def __init__(self, request: str, *args: typing.List[str]): self.request = request self.args = args + def to_multi(self): + return MultiCheck([(self.request, self.args)]) + def __or__(self, other: "Check"): + return MultiCheck([(self.request, self.args), + (other.request, other.args)]) TOP_10_CALLABLE = typing.Callable[[typing.Any], typing.Any] def top_10(items: typing.Dict[typing.Any, typing.Any], -- cgit v1.3.1-10-gc9f91