.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
models.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2# pylint: disable=missing-module-docstring
3
4import typing
5import babel
6
7
9 """Reference by names to an engine and category"""
10
11 __slots__ = 'name', 'category'
12
13 def __init__(self, name: str, category: str):
14 self.name = name
15 self.category = category
16
17 def __repr__(self):
18 return "EngineRef({!r}, {!r})".format(self.name, self.category)
19
20 def __eq__(self, other):
21 return self.name == other.name and self.category == other.category
22
23 def __hash__(self):
24 return hash((self.name, self.category))
25
26
28 """container for all the search parameters (query, language, etc...)"""
29
30 __slots__ = (
31 'query',
32 'engineref_list',
33 'lang',
34 'locale',
35 'safesearch',
36 'pageno',
37 'time_range',
38 'timeout_limit',
39 'external_bang',
40 'engine_data',
41 'redirect_to_first_result',
42 )
43
45 self,
46 query: str,
47 engineref_list: typing.List[EngineRef],
48 lang: str = 'all',
49 safesearch: int = 0,
50 pageno: int = 1,
51 time_range: typing.Optional[str] = None,
52 timeout_limit: typing.Optional[float] = None,
53 external_bang: typing.Optional[str] = None,
54 engine_data: typing.Optional[typing.Dict[str, str]] = None,
55 redirect_to_first_result: typing.Optional[bool] = None,
56 ): # pylint:disable=too-many-arguments
57 self.query = query
58 self.engineref_list = engineref_list
59 self.lang = lang
60 self.safesearch = safesearch
61 self.pageno = pageno
62 self.time_range = time_range
63 self.timeout_limit = timeout_limit
64 self.external_bang = external_bang
65 self.engine_data = engine_data or {}
66 self.redirect_to_first_result = redirect_to_first_result
67
68 self.locale = None
69 if self.lang:
70 try:
71 self.locale = babel.Locale.parse(self.lang, sep='-')
72 except babel.core.UnknownLocaleError:
73 pass
74
75 @property
76 def categories(self):
77 return list(set(map(lambda engineref: engineref.category, self.engineref_list)))
78
79 def __repr__(self):
80 return "SearchQuery({!r}, {!r}, {!r}, {!r}, {!r}, {!r}, {!r}, {!r}, {!r})".format(
81 self.query,
82 self.engineref_list,
83 self.lang,
84 self.safesearch,
85 self.pageno,
86 self.time_range,
87 self.timeout_limit,
88 self.external_bang,
90 )
91
92 def __eq__(self, other):
93 return (
94 self.query == other.query
95 and self.engineref_list == other.engineref_list
96 and self.lang == other.lang
97 and self.safesearch == other.safesearch
98 and self.pageno == other.pageno
99 and self.time_range == other.time_range
100 and self.timeout_limit == other.timeout_limit
101 and self.external_bang == other.external_bang
102 and self.redirect_to_first_result == other.redirect_to_first_result
103 )
104
105 def __hash__(self):
106 return hash(
107 (
108 self.query,
109 tuple(self.engineref_list),
110 self.lang,
111 self.safesearch,
112 self.pageno,
113 self.time_range,
114 self.timeout_limit,
115 self.external_bang,
117 )
118 )
119
120 def __copy__(self):
121 return SearchQuery(
122 self.query,
123 self.engineref_list,
124 self.lang,
125 self.safesearch,
126 self.pageno,
127 self.time_range,
128 self.timeout_limit,
129 self.external_bang,
130 self.engine_data,
132 )
__init__(self, str name, str category)
Definition models.py:13
__init__(self, str query, typing.List[EngineRef] engineref_list, str lang='all', int safesearch=0, int pageno=1, typing.Optional[str] time_range=None, typing.Optional[float] timeout_limit=None, typing.Optional[str] external_bang=None, typing.Optional[typing.Dict[str, str]] engine_data=None, typing.Optional[bool] redirect_to_first_result=None)
Definition models.py:56