.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
extended_types.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
"""This module implements the type extensions applied by SearXNG.
3
4
- :py:obj:`flask.request` is replaced by :py:obj:`sxng_request`
5
- :py:obj:`flask.Request` is replaced by :py:obj:`SXNG_Request`
6
- :py:obj:`httpx.response` is replaced by :py:obj:`SXNG_Response`
7
8
----
9
10
.. py:attribute:: sxng_request
11
:type: SXNG_Request
12
13
A replacement for :py:obj:`flask.request` with type cast :py:obj:`SXNG_Request`.
14
15
.. autoclass:: SXNG_Request
16
:members:
17
18
.. autoclass:: SXNG_Response
19
:members:
20
21
"""
22
# pylint: disable=invalid-name
23
24
__all__ = [
"SXNG_Request"
,
"sxng_request"
,
"SXNG_Response"
]
25
26
import
typing
27
import
flask
28
import
httpx
29
30
if
typing.TYPE_CHECKING:
31
import
searx.preferences
32
import
searx.results
33
from
searx.search.processors
import
ParamTypes
34
35
36
class
SXNG_Request
(flask.Request):
37
"""SearXNG extends the class :py:obj:`flask.Request` with properties from
38
*this* class definition, see type cast :py:obj:`sxng_request`.
39
"""
40
41
user_plugins: list[str]
42
"""list of searx.plugins.Plugin.id (the id of the plugins)"""
43
44
preferences:
"searx.preferences.Preferences"
45
"""The preferences of the request."""
46
47
errors: list[str]
48
"""A list of errors (translated text) added by :py:obj:`searx.webapp` in
49
case of errors."""
50
# request.form is of type werkzeug.datastructures.ImmutableMultiDict
51
# form: dict[str, str]
52
53
start_time: float
54
"""Start time of the request, :py:obj:`timeit.default_timer` added by
55
:py:obj:`searx.webapp` to calculate the total time of the request."""
56
57
render_time: float
58
"""Duration of the rendering, calculated and added by
59
:py:obj:`searx.webapp`."""
60
61
timings: list[
"searx.results.Timing"
]
62
"""A list of :py:obj:`searx.results.Timing` of the engines, calculatid in
63
and hold by :py:obj:`searx.results.ResultContainer.timings`."""
64
65
remote_addr: str
66
67
68
#: A replacement for :py:obj:`flask.request` with type cast :py:`SXNG_Request`.
69
sxng_request = typing.cast(SXNG_Request, flask.request)
70
71
72
class
SXNG_Response
(httpx.Response):
73
"""SearXNG extends the class :py:obj:`httpx.Response` with properties from
74
*this* class (type cast of :py:obj:`httpx.Response`).
75
76
.. code:: python
77
78
response = httpx.get("https://example.org")
79
response = typing.cast(SXNG_Response, response)
80
if response.ok:
81
...
82
query_was = search_params["query"]
83
"""
84
85
ok: bool
86
search_params:
"ParamTypes"
searx.extended_types.SXNG_Request
Definition
extended_types.py:36
searx.extended_types.SXNG_Response
Definition
extended_types.py:72
searx.preferences
Definition
preferences.py:1
searx.results
Definition
results.py:1
searx.search.processors
Definition
__init__.py:1
searxng
searx
extended_types.py
Generated on
for .oO SearXNG Developer Documentation Oo. by
1.14.0