2017-04-24 21:30:53 +00:00
|
|
|
from typing import Optional, List
|
2017-02-04 00:08:12 +00:00
|
|
|
from szurubooru.search.typing import SaQuery
|
|
|
|
|
|
|
|
|
|
|
|
class BaseCriterion:
|
|
|
|
def __init__(self, original_text: str) -> None:
|
2016-04-02 12:40:10 +00:00
|
|
|
self.original_text = original_text
|
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
def __repr__(self) -> str:
|
2016-04-02 12:40:10 +00:00
|
|
|
return self.original_text
|
|
|
|
|
2016-08-14 12:22:53 +00:00
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
class RangedCriterion(BaseCriterion):
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
original_text: str,
|
|
|
|
min_value: Optional[str],
|
|
|
|
max_value: Optional[str]) -> None:
|
2016-06-03 10:13:43 +00:00
|
|
|
super().__init__(original_text)
|
2016-04-02 12:40:10 +00:00
|
|
|
self.min_value = min_value
|
|
|
|
self.max_value = max_value
|
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
def __hash__(self) -> int:
|
2016-06-03 11:50:38 +00:00
|
|
|
return hash(('range', self.min_value, self.max_value))
|
|
|
|
|
2016-08-14 12:22:53 +00:00
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
class PlainCriterion(BaseCriterion):
|
|
|
|
def __init__(self, original_text: str, value: str) -> None:
|
2016-06-03 10:13:43 +00:00
|
|
|
super().__init__(original_text)
|
2016-04-02 12:40:10 +00:00
|
|
|
self.value = value
|
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
def __hash__(self) -> int:
|
2016-06-03 11:50:38 +00:00
|
|
|
return hash(self.value)
|
|
|
|
|
2016-08-14 12:22:53 +00:00
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
class ArrayCriterion(BaseCriterion):
|
|
|
|
def __init__(self, original_text: str, values: List[str]) -> None:
|
2016-06-03 10:13:43 +00:00
|
|
|
super().__init__(original_text)
|
2016-04-02 12:40:10 +00:00
|
|
|
self.values = values
|
2016-06-03 11:50:38 +00:00
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
def __hash__(self) -> int:
|
2016-06-03 11:50:38 +00:00
|
|
|
return hash(tuple(['array'] + self.values))
|