summaryrefslogtreecommitdiff
path: root/searx/webapp.py
AgeCommit message (Collapse)Author
2021-08-24[mod] /image_proxy: use HTTP/1 instead of HTTP/2Alexandre Flament
httpx: HTTP/2 is slow when a lot data is downloaded. https://github.com/dalf/pyhttp-benchmark also, the usage of HTTP/1 decreases the load average
2021-08-24[fix] image_proxy: always close the httpx responeAlexandre Flament
previously, when the content type was not an image and some other error, the httpx response was not closed
2021-08-22Merge pull request #260 from dalf/mod_localeMarkus Heiser
[mod] searx.webapp.get_locale: read locale from the preferences
2021-08-18[fix] /config add missing GIT_BRANCH valueMarkus Heiser
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2021-08-17[mod] searx.webapp.get_locale: read locale from the preferencesAlexandre Flament
pre_request already set the locale.
2021-08-03[mod] settings.yml: remove localesAlexandre Flament
There are detected from the searx/translations directory
2021-07-30version based on the git repositoryAlexandre Flament
This commit remove the need to update the brand for GIT_URL and GIT_BRANCH: there are read from the git repository. It is possible to call python -m searx.version freeze to freeze the current version. Useful when the code is installed outside git (distro package, docker, etc...)
2021-07-21[mod] drop usage of the searx.brand namespace (templates & /config)Markus Heiser
In the templates and the /config (JSON) the usage of the 'brand.*' name space is replaced by 'searx.get_setting' function. - new_issue_url --> get_setting('brand.new_issue_url') - brand.GIT_URL --> get_setting('brand.git_url') - brand.PUBLIC_INSTANCES --> get_setting('brand.public_instances') - brand.DOCS_URL --> get_setting('brand.docs_url') - brand.ISSUE_URL --> get_setting('brand.issue_url') - brand.CONTACT_URL --> get_setting('general.contact_url', '') The macro 'new_issue' from searx/templates/*/messages/no_results.html is now imported with context:: {% from '__common__/new_issue.html' import new_issue with context %} To get *public instances URL* from context's 'get_setting()' function:: get_setting('brand.public_instances','') Macro's prototype does no longer need the 'new_issue_url' argument and has been changed to:: macro new_issue(engine_name, engine_reliability) Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2021-07-03[pylint] prepare for pylint v2.9.3 / fix some (new) pylint issuesMarkus Heiser
Upgrade from pylint v2.8.3 to 2.9.3 raise some new issues:: searx/search/checker/__main__.py:37:26: R1732: Consider using 'with' for resource-allocating operations (consider-using-with) searx/search/checker/__main__.py:38:26: R1732: Consider using 'with' for resource-allocating operations (consider-using-with) searx/search/processors/__init__.py:20:0: R0402: Use 'from searx import engines' instead (consider-using-from-import) searx/preferences.py:182:19: C0207: Use data.split('-', maxsplit=1)[0] instead (use-maxsplit-arg) searx/preferences.py:506:15: R1733: Unnecessary dictionary index lookup, use 'user_setting' instead (unnecessary-dict-index-lookup) searx/webapp.py:436:0: C0206: Consider iterating with .items() (consider-using-dict-items) searx/webapp.py:950:4: C0206: Consider iterating with .items() (consider-using-dict-items) Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2021-06-10[coding-style] searx/webapp.py - normalize indentationsMarkus Heiser
No functional change! Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2021-06-08[mod] refactor searx.webapp.renderAlexandre Flament
render automatically adds these variables to the template context: * advanced_search * all_categories * categories before render was checking if the variable was already set but it is actually never set by the callers
2021-06-08[mod] move hook to set Unix thread name into searx.unixthreadnameAlexandre Flament
requires setproctitle (but optional)
2021-06-08[mod] remove unused filter searx.webapp.extract_domainAlexandre Flament
it was used in the pix-art theme
2021-06-08[mod] refactor searx.webapp.renderAlexandre Flament
no functional change, reorder declarations
2021-06-08[mod] refactor searx.webapp.render: remove unused parametersAlexandre Flament
2021-06-08[mod] remove check of Python 2.Alexandre Flament
2021-06-08[mod] remove searx.webapp.get_base_url functionAlexandre Flament
see the result of: git grep "base_url" searx/templates "base_url" is not used any more.
2021-06-08[mod] refactor: move Flask proxy fix to searx.flaskfix moduleAlexandre Flament
2021-06-03[enh] flask debug mode: reload the app when searx/settings.yml changesAlexandre Flament
2021-06-01[mod] remove overpass API callAlexandre Flament
prepare the code the PR #90
2021-06-01[mod] move all default settings into searx.settings_defaultsAlexandre Flament
2021-05-28[enh] add settings option to enable/disable search formatsMarkus Heiser
Access to formats can be denied by settings configuration:: search: formats: [html, csv, json, rss] Closes: https://github.com/searxng/searxng/issues/95 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2021-05-27[pylint] webapp.py - fix all messages from pylintMarkus Heiser
No functional change, just some linting. - fix messages from pylint (see below) - log where general Exceptions are catched (broad-except) - normalized various indentation - To avoid clashes with common names, add prefix 'route_' to all @app.route decorated functions. Fixed messages:: searx/webapp.py:744:0: C0301: Line too long (146/120) (line-too-long) searx/webapp.py:756:0: C0301: Line too long (132/120) (line-too-long) searx/webapp.py:730:9: W0511: TODO, check if timezone is calculated right (fixme) searx/webapp.py:1:0: C0114: Missing module docstring (missing-module-docstring) searx/webapp.py:126:8: I1101: Module 'setproctitle' has no 'setthreadtitle' member, but source is unavailable. Consider adding this module to extension-pkg-allow-list if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) searx/webapp.py:126:36: W0212: Access to a protected member _name of a client class (protected-access) searx/webapp.py:131:4: R1722: Consider using sys.exit() (consider-using-sys-exit) searx/webapp.py:141:4: R1722: Consider using sys.exit() (consider-using-sys-exit) searx/webapp.py:255:38: W0621: Redefining name 'request' from outer scope (line 32) (redefined-outer-name) searx/webapp.py:307:4: W0702: No exception type(s) specified (bare-except) searx/webapp.py:374:24: W0621: Redefining name 'theme' from outer scope (line 155) (redefined-outer-name) searx/webapp.py:420:8: R1705: Unnecessary "else" after "return" (no-else-return) searx/webapp.py:544:4: W0621: Redefining name 'preferences' from outer scope (line 917) (redefined-outer-name) searx/webapp.py:551:4: W0702: No exception type(s) specified (bare-except) searx/webapp.py:566:15: W0703: Catching too general exception Exception (broad-except) searx/webapp.py:613:4: R1705: Unnecessary "elif" after "return" (no-else-return) searx/webapp.py:690:8: W0621: Redefining name 'search' from outer scope (line 661) (redefined-outer-name) searx/webapp.py:661:0: R0914: Too many local variables (22/20) (too-many-locals) searx/webapp.py:674:8: R1705: Unnecessary "else" after "return" (no-else-return) searx/webapp.py:697:11: W0703: Catching too general exception Exception (broad-except) searx/webapp.py:748:4: R1705: Unnecessary "elif" after "return" (no-else-return) searx/webapp.py:661:0: R0911: Too many return statements (9/6) (too-many-return-statements) searx/webapp.py:661:0: R0912: Too many branches (29/12) (too-many-branches) searx/webapp.py:661:0: R0915: Too many statements (74/50) (too-many-statements) searx/webapp.py:931:4: W0621: Redefining name 'image_proxy' from outer scope (line 1072) (redefined-outer-name) searx/webapp.py:946:4: W0621: Redefining name 'stats' from outer scope (line 1132) (redefined-outer-name) searx/webapp.py:917:0: R0914: Too many local variables (34/20) (too-many-locals) searx/webapp.py:917:0: R0912: Too many branches (19/12) (too-many-branches) searx/webapp.py:917:0: R0915: Too many statements (65/50) (too-many-statements) searx/webapp.py:1063:44: W0621: Redefining name 'preferences' from outer scope (line 917) (redefined-outer-name) searx/webapp.py:1072:0: R0911: Too many return statements (9/6) (too-many-return-statements) searx/webapp.py:1151:4: C0103: Variable name "SORT_PARAMETERS" doesn't conform to '(([a-z][a-zA-Z0-9_]{2,30})|(_[a-z0-9_]*)|([a-z]))$' pattern (invalid-name) searx/webapp.py:1297:0: R1721: Unnecessary use of a comprehension (unnecessary-comprehension) searx/webapp.py:1303:0: C0103: Argument name "e" doesn't conform to '(([a-z][a-zA-Z0-9_]{2,30})|(_[a-z0-9_]*))$' pattern (invalid-name) searx/webapp.py:1303:19: W0613: Unused argument 'e' (unused-argument) searx/webapp.py:1338:23: W0621: Redefining name 'app' from outer scope (line 162) (redefined-outer-name) searx/webapp.py:1318:0: R0903: Too few public methods (1/2) (too-few-public-methods) Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2021-05-26[pylint] webapp.py - fix all wrong-import-order messages from pylintMarkus Heiser
pylint message: wrong-import-order Respect PEP8 import order (standard imports first, then third-party libraries, then local imports). pylint message: wrong-import-position Do not mix code & imports BTW: - only one import per line - replace licence text by SPDX tag Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2021-05-26[fix] webapp.py - running without installation is not supportedMarkus Heiser
Remove extension of the sys.path (aka PYTHONPATH). Running instance directly from repository's folder is a relict from the early beginning in 2014 (fd651083f) and is no longer supported. Since commit dd46629 was merged the command line 'searx-run' exists and should be used. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2021-05-22[fix] offline engine: don't crash on time recordingAlexandre Flament
2021-05-14[fix] webapp.py: pylint: disable=assigning-non-slot for request.*Alexandre Flament
Note: actually, the code should use flask.g.* instead of request.*
2021-05-06[mod] Server-Timing header: add render fieldAlexandre Flament
Add a "render" field to the Server-Timing header This field is the time spent in the searx.webapp.render function (Jinja2 rendering) See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing
2021-05-04[mod] option to enable or disable "proxy" button next to each result (#54)Markus Heiser
* [mod] option to enable or disable "proxy" button next to each result Closes: https://github.com/searxng/searxng/issues/51 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de> Co-authored-by: Alexandre Flament <alex@al-f.net>
2021-04-27[mod] processors: show identical error messages on /search and /statsAlexandre Flament
2021-04-26[fix] debug log: UnicodeEncodeError: 'ascii' codec can't encodeMarkus Heiser
The issue exists only in the debug log:: --- Logging error --- Traceback (most recent call last): File "/usr/lib/python3.9/logging/__init__.py", line 1086, in emit stream.write(msg + self.terminator) UnicodeEncodeError: 'ascii' codec can't encode characters in position 79-89: ordinal not in range(128) Call stack: File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask/app.py", line 2464, in __call__ return self.wsgi_app(environ, start_response) File "/usr/local/searx/searx-src/searx/webapp.py", line 1316, in __call__ return self.app(environ, start_response) File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/werkzeug/middleware/proxy_fix.py", line 169, in __call__ return self.app(environ, start_response) File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/usr/local/searx/searx-src/searx/webapp.py", line 766, in search number_of_results=format_decimal(number_of_results), File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask_babel/__init__.py", line 458, in format_decimal locale = get_locale() File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask_babel/__init__.py", line 226, in get_locale rv = babel.locale_selector_func() File "/usr/local/searx/searx-src/searx/webapp.py", line 249, in get_locale logger.debug("%s uses locale `%s` from %s", request.url, locale, locale_source) Unable to print the message and arguments - possible formatting error. Use the traceback above to help find the error. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2021-04-25[mod] /stats : detail per engineAlexandre Flament
allow to submit a github issue including the technical details (exceptions, errors, warning, checker result)
2021-04-24[mod] /stats : add reliability column and sort by column linksAlexandre Flament
2021-04-24[mod] update /statsAlexandre Flament
2021-04-21[mod] oscar: /preferences , engines tab: report engine timesAlexandre Flament
* display the median time instead of the average. * add a "Reliability" column (sum up the metrics and the checker results). * the "selected language", "SafeSearch", "Time range" values are displayed as "broken" when the checker tests fail.
2021-04-21[enh] rewrite and enhance metricsAlexandre Flament
2021-04-21[mod] refactoring: processorsAlexandre Flament
Report to the user suspended engines. searx.search.processor.abstract: * manages suspend time (per network). * reports suspended time to the ResultContainer (method extend_container_if_suspended) * adds the results to the ResultContainer (method extend_container) * handles exceptions (method handle_exception)
2021-04-21Merge remote-tracking branch 'return42/fix-preference-save'Alexandre Flament
2021-04-21Merge remote-tracking branch 'return42/fix-url-bar-suggestion'Alexandre Flament
2021-04-12[httpx] replace searx.poolrequests by searx.networkAlexandre Flament
settings.yml: * outgoing.networks: * can contains network definition * propertiers: enable_http, verify, http2, max_connections, max_keepalive_connections, keepalive_expiry, local_addresses, support_ipv4, support_ipv6, proxies, max_redirects, retries * retries: 0 by default, number of times searx retries to send the HTTP request (using different IP & proxy each time) * local_addresses can be "192.168.0.1/24" (it supports IPv6) * support_ipv4 & support_ipv6: both True by default see https://github.com/searx/searx/pull/1034 * each engine can define a "network" section: * either a full network description * either reference an existing network * all HTTP requests of engine use the same HTTP configuration (it was not the case before, see proxy configuration in master)
2021-04-12[fix] redirect when saving preferencesMarkus Heiser
Erroneously commit 87e4c4762 droped the 302 redirect. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2021-04-10[enh] replace requests by httpxAlexandre Flament
2021-04-07[fix] fix PR 2656Alexandre Flament
SCRIPT_NAME remove trailing slash to avoid infinite redirect
2021-04-05Merge pull request #2656 from return42/fix-url_forAlexandre Flament
[fix] url_for(..., _external=True) in templates
2021-04-05[fix] url_for(..., _external=True) in templatesMarkus Heiser
The `url_for` function in the template context is not the one from Flask, it is the one from `webapp`. The `webapp.url_for_theme` is different from its namesake of Flask and has it quirks, when called with argument `_external=True`. The `webapp.url_for_theme` can't handle absolute URLs since it pokes a leading '/', here is the snippet of the old code:: url = url_for(endpoint, **values) if settings['server']['base_url']: if url.startswith('/'): url = url[1:] url = urljoin(settings['server']['base_url'], url) Next drawback of (Flask's) `_external=True` is, that it will not return the HTTP scheme when searx (the Flask app) listens on http and is proxied by a https server. To get the right scheme `HTTP_X_SCHEME` is needed by Flask (werkzeug). Since this is not provided in every environment (e.g. behind Apache mod_wsgi or the HTTP header is not fully set for some other reasons) it is recommended to get *script_name*, *server* and *scheme* from the configured `base_url`. If `base_url` is specified, then these values from are given preference over any Flask's generics. BTW this patch normalize to use `url_for` in the `opensearch.xml` and drop the need of `host` and `urljoin` in template's context. Signed-off-by: Markus Heiser <markus@darmarit.de>
2021-04-04[fix] publishedDate: don't try to get date from empty string or NoneMarkus Heiser
Signed-off-by: Markus Heiser <markus@darmarit.de>
2021-04-03[fix] url bar autocomplete (opensearch suggestions)Markus Heiser
Since #2593 is merged the OpenSearch-Format is buggy. The loop in [1] will change raw_text_query object and this will change also the value of `raw_text_query.query` on every `raw_text_query.changeQuery(result)`. This patch fixes this issue by storing the initial query value in `sug_prefix`. [1] https://github.com/searx/searx/blob/ac0fdc3b9670168de8061ed0e656dd66a567d741/searx/webapp.py#L804-L806 OpenSearch-Format:: [ "<query>", [ "<term 1>", "<term 2>", ... "<term n>" ], [ "<content 1>", "<content 2>", ..., "<content n>" ], [ "<url 1>", "<url 2>", ..., "<url n>" ] ] - https://www.google.com/support/enterprise/static/gsa/docs/admin/current/gsa_doc_set/xml_reference/query_suggestion.html#1080002 - https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Supporting_search_suggestions_in_search_plugins#implementing_search_suggestion_support_on_the_server Legacy-Format:: [ "<term 1>", "<term 2>", ..., "<term n>" ] - https://www.google.com/support/enterprise/static/gsa/docs/admin/current/gsa_doc_set/xml_reference/query_suggestion.html#1081079 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2021-03-22[mod] preferences: a tooltip is shown when the mouse is over the engine namesAlexandre Flament
2021-03-16[mod] replace /translations.js by embedded JSONAlexandre Flament
In webapp.py, there is a new function "get_translations" lists available translations Close #2064
2021-03-16[mod] upgrade pygmentsAlexandre Flament
add searx_extra/update/update_pygments.py to update the css style of the oscar and simple themes.