diff options
author | Alexandre Flament <alex@al-f.net> | 2021-05-28 18:45:22 +0200 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2021-06-01 08:10:15 +0200 |
commit | 4b07df62e5906e98315e9e856db8f39b2f28f36e (patch) | |
tree | 8ab5a8d8e012aabfe55d01f3157ec7bff897c8d3 /searx/utils.py | |
parent | 856729226d5822a3285483689f9f8ba5c2bafc07 (diff) | |
download | searxng-4b07df62e5906e98315e9e856db8f39b2f28f36e.tar.gz searxng-4b07df62e5906e98315e9e856db8f39b2f28f36e.zip |
[mod] move all default settings into searx.settings_defaults
Diffstat (limited to 'searx/utils.py')
-rw-r--r-- | searx/utils.py | 55 |
1 files changed, 1 insertions, 54 deletions
diff --git a/searx/utils.py b/searx/utils.py index ad69816ce..bf9957df4 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -8,7 +8,6 @@ from os.path import splitext, join from random import choice from html.parser import HTMLParser from urllib.parse import urljoin, urlparse -from collections.abc import Mapping from lxml import html from lxml.etree import ElementBase, XPath, XPathError, XPathSyntaxError, _ElementStringResult, _ElementUnicodeResult @@ -46,7 +45,7 @@ def searx_useragent(): """Return the searx User Agent""" return 'searx/{searx_version} {suffix}'.format( searx_version=VERSION_STRING, - suffix=settings['outgoing'].get('useragent_suffix', '')).strip() + suffix=settings['outgoing']['useragent_suffix'].strip()) def gen_useragent(os=None): @@ -501,58 +500,6 @@ def get_engine_from_settings(name): return {} -NOT_EXISTS = object() -"""Singleton used by :py:obj:`get_value` if a key does not exists.""" - - -def get_value(dictionary, *keys, default=NOT_EXISTS): - """Return the value from a *deep* mapping type (e.g. the ``settings`` object - from yaml). If the path to the *key* does not exists a :py:obj:`NOT_EXISTS` - is returned (non ``KeyError`` exception is raised). - - .. code: python - - >>> from searx import settings - >>> from searx.utils import get_value, NOT_EXISTS - >>> get_value(settings, 'checker', 'additional_tests', 'rosebud', 'result_container') - ['not_empty', ['one_title_contains', 'citizen kane']] - - >>> get_value(settings, 'search', 'xxx') is NOT_EXISTS - True - >>> get_value(settings, 'search', 'formats') - ['html', 'csv', 'json', 'rss'] - - The list returned from the ``search.format`` key is not a mapping type, you - can't traverse along non-mapping types. If you try it, you will get a - :py:ref:`NOT_EXISTS`: - - .. code: python - - >>> get_value(settings, 'search', 'format', 'csv') is NOT_EXISTS - True - >>> get_value(settings, 'search', 'formats')[1] - 'csv' - - For convenience you can replace :py:ref:`NOT_EXISTS` by a default value of - your choice: - - .. code: python - - if 'csv' in get_value(settings, 'search', 'formats', default=[]): - print("csv format is denied") - - """ - - obj = dictionary - for k in keys: - if not isinstance(obj, Mapping): - raise TypeError("expected mapping type, got %s" % type(obj)) - obj = obj.get(k, default) - if obj is default: - return obj - return obj - - def get_xpath(xpath_spec): """Return cached compiled XPath |