.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
34
35
class
SXNG_Request
(flask.Request):
36
"""SearXNG extends the class :py:obj:`flask.Request` with properties from
37
*this* class definition, see type cast :py:obj:`sxng_request`.
38
"""
39
40
user_plugins: list[str]
41
"""list of searx.plugins.Plugin.id (the id of the plugins)"""
42
43
preferences:
"searx.preferences.Preferences"
44
"""The preferences of the request."""
45
46
errors: list[str]
47
"""A list of errors (translated text) added by :py:obj:`searx.webapp` in
48
case of errors."""
49
# request.form is of type werkzeug.datastructures.ImmutableMultiDict
50
# form: dict[str, str]
51
52
start_time: float
53
"""Start time of the request, :py:obj:`timeit.default_timer` added by
54
:py:obj:`searx.webapp` to calculate the total time of the request."""
55
56
render_time: float
57
"""Duration of the rendering, calculated and added by
58
:py:obj:`searx.webapp`."""
59
60
timings: list[
"searx.results.Timing"
]
61
"""A list of :py:obj:`searx.results.Timing` of the engines, calculatid in
62
and hold by :py:obj:`searx.results.ResultContainer.timings`."""
63
64
remote_addr: str
65
66
67
#: A replacement for :py:obj:`flask.request` with type cast :py:`SXNG_Request`.
68
sxng_request = typing.cast(SXNG_Request, flask.request)
69
70
71
class
SXNG_Response
(httpx.Response):
72
"""SearXNG extends the class :py:obj:`httpx.Response` with properties from
73
*this* class (type cast of :py:obj:`httpx.Response`).
74
75
.. code:: python
76
77
response = httpx.get("https://example.org")
78
response = typing.cast(SXNG_Response, response)
79
if response.ok:
80
...
81
"""
82
83
ok: bool
searx.extended_types.SXNG_Request
Definition
extended_types.py:35
searx.extended_types.SXNG_Response
Definition
extended_types.py:71
searx.preferences
Definition
preferences.py:1
searx.results
Definition
results.py:1
searxng
searx
extended_types.py
Generated on
for .oO SearXNG Developer Documentation Oo. by
1.14.0