rr- ad842ee8a5 server: refactor + add type hinting
- Added type hinting (for now, 3.5-compatible)
- Split `db` namespace into `db` module and `model` namespace
- Changed elastic search to be created lazily for each operation
- Changed to class based approach in entity serialization to allow
  stronger typing
- Removed `required` argument from `context.get_*` family of functions;
  now it's implied if `default` argument is omitted
- Changed `unalias_dict` implementation to use less magic inputs
2017-02-05 16:34:45 +01:00

45 lines
1.1 KiB
Python

from szurubooru.search.criteria import BaseCriterion
class AnonymousToken:
def __init__(self, criterion: BaseCriterion, negated: bool) -> None:
self.criterion = criterion
self.negated = negated
def __hash__(self) -> int:
return hash((self.criterion, self.negated))
class NamedToken(AnonymousToken):
def __init__(
self, name: str, criterion: BaseCriterion, negated: bool) -> None:
super().__init__(criterion, negated)
self.name = name
def __hash__(self) -> int:
return hash((self.name, self.criterion, self.negated))
class SortToken:
SORT_DESC = 'desc'
SORT_ASC = 'asc'
SORT_NONE = ''
SORT_DEFAULT = 'default'
SORT_NEGATED_DEFAULT = 'negated default'
def __init__(self, name: str, order: str) -> None:
self.name = name
self.order = order
def __hash__(self) -> int:
return hash((self.name, self.order))
class SpecialToken:
def __init__(self, value: str, negated: bool) -> None:
self.value = value
self.negated = negated
def __hash__(self) -> int:
return hash((self.value, self.negated))