[format.python] disable py code formatting for some hunks of code

Disable the python code formatting from python-black, where the readability of
code suffers by formatting.

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2021-12-27 09:16:03 +01:00
parent c849731eb1
commit fcdc2c2cd2
13 changed files with 114 additions and 68 deletions

View File

@ -39,6 +39,7 @@ def locale_to_lang_code(locale):
# wikis for some languages were moved off from the main site, we need to make # wikis for some languages were moved off from the main site, we need to make
# requests to correct URLs to be able to get results in those languages # requests to correct URLs to be able to get results in those languages
lang_urls = { lang_urls = {
# fmt: off
'all': { 'all': {
'base': 'https://wiki.archlinux.org', 'base': 'https://wiki.archlinux.org',
'search': '/index.php?title=Special:Search&offset={offset}&{query}' 'search': '/index.php?title=Special:Search&offset={offset}&{query}'
@ -63,6 +64,7 @@ lang_urls = {
'base': 'http://archtr.org/wiki', 'base': 'http://archtr.org/wiki',
'search': '/index.php?title=Özel:Ara&offset={offset}&{query}' 'search': '/index.php?title=Özel:Ara&offset={offset}&{query}'
} }
# fmt: on
} }

View File

@ -69,21 +69,25 @@ def image_url_cleanup(url_string):
def _get_url(query, language, offset, time_range): def _get_url(query, language, offset, time_range):
if time_range in time_range_dict: if time_range in time_range_dict:
search_path = search_string_with_time.format( search_path = search_string_with_time.format(
# fmt: off
query = urlencode({ query = urlencode({
'q': query, 'q': query,
'setmkt': language 'setmkt': language
}), }),
offset = offset, offset = offset,
interval = time_range_dict[time_range] interval = time_range_dict[time_range]
# fmt: on
) )
else: else:
# e.g. setmkt=de-de&setlang=de # e.g. setmkt=de-de&setlang=de
search_path = search_string.format( search_path = search_string.format(
# fmt: off
query = urlencode({ query = urlencode({
'q': query, 'q': query,
'setmkt': language 'setmkt': language
}), }),
offset = offset offset = offset
# fmt: on
) )
return base_url + search_path return base_url + search_path

View File

@ -23,9 +23,11 @@ paging = True
time_range_support = True time_range_support = True
safesearch = True safesearch = True
supported_languages = [ supported_languages = [
# fmt: off
'en', 'fr', 'ja', 'eu', 'ca', 'cs', 'eo', 'el', 'en', 'fr', 'ja', 'eu', 'ca', 'cs', 'eo', 'el',
'de', 'it', 'nl', 'es', 'oc', 'gd', 'zh', 'pt', 'de', 'it', 'nl', 'es', 'oc', 'gd', 'zh', 'pt',
'sv', 'pl', 'fi', 'ru' 'sv', 'pl', 'fi', 'ru'
# fmt: on
] ]
base_url = 'https://sepiasearch.org/api/v1/search/videos' base_url = 'https://sepiasearch.org/api/v1/search/videos'

View File

@ -92,14 +92,20 @@ WHERE {
# https://www.w3.org/TR/sparql11-query/#rSTRING_LITERAL1 # https://www.w3.org/TR/sparql11-query/#rSTRING_LITERAL1
# https://lists.w3.org/Archives/Public/public-rdf-dawg/2011OctDec/0175.html # https://lists.w3.org/Archives/Public/public-rdf-dawg/2011OctDec/0175.html
sparql_string_escape = get_string_replaces_function({'\t': '\\\t', sparql_string_escape = get_string_replaces_function(
# fmt: off
{
'\t': '\\\t',
'\n': '\\\n', '\n': '\\\n',
'\r': '\\\r', '\r': '\\\r',
'\b': '\\\b', '\b': '\\\b',
'\f': '\\\f', '\f': '\\\f',
'\"': '\\\"', '\"': '\\\"',
'\'': '\\\'', '\'': '\\\'',
'\\': '\\\\'}) '\\': '\\\\'
}
# fmt: on
)
replace_http_by_https = get_string_replaces_function({'http:': 'https:'}) replace_http_by_https = get_string_replaces_function({'http:': 'https:'})

View File

@ -17,15 +17,19 @@ from searx import logger, settings
logger = logger.getChild("plugins") logger = logger.getChild("plugins")
required_attrs = ( required_attrs = (
# fmt: off
("name", str), ("name", str),
("description", str), ("description", str),
("default_on", bool) ("default_on", bool)
# fmt: on
) )
optional_attrs = ( optional_attrs = (
# fmt: off
("js_dependencies", tuple), ("js_dependencies", tuple),
("css_dependencies", tuple), ("css_dependencies", tuple),
("preference_section", str), ("preference_section", str),
# fmt: on
) )

View File

@ -325,6 +325,7 @@ class Preferences:
super().__init__() super().__init__()
self.key_value_settings = { self.key_value_settings = {
# fmt: off
'categories': MultipleChoiceSetting( 'categories': MultipleChoiceSetting(
['general'], ['general'],
is_locked('categories'), is_locked('categories'),
@ -422,6 +423,7 @@ class Preferences:
'False': False 'False': False
} }
), ),
# fmt: on
} }
self.engines = EnginesSetting('engines', choices=engines) self.engines = EnginesSetting('engines', choices=engines)

View File

@ -25,6 +25,7 @@ from searx.metrics import counter_inc
logger = logger.getChild('searx.search.checker') logger = logger.getChild('searx.search.checker')
HTML_TAGS = [ HTML_TAGS = [
# fmt: off
'embed', 'iframe', 'object', 'param', 'picture', 'source', 'svg', 'math', 'canvas', 'noscript', 'script', 'embed', 'iframe', 'object', 'param', 'picture', 'source', 'svg', 'math', 'canvas', 'noscript', 'script',
'del', 'ins', 'area', 'audio', 'img', 'map', 'track', 'video', 'a', 'abbr', 'b', 'bdi', 'bdo', 'br', 'cite', 'del', 'ins', 'area', 'audio', 'img', 'map', 'track', 'video', 'a', 'abbr', 'b', 'bdi', 'bdo', 'br', 'cite',
'code', 'data', 'dfn', 'em', 'i', 'kdb', 'mark', 'q', 'rb', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'small', 'code', 'data', 'dfn', 'em', 'i', 'kdb', 'mark', 'q', 'rb', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'small',
@ -32,6 +33,7 @@ HTML_TAGS = [
'figcaption', 'figure', 'hr', 'li', 'ol', 'p', 'pre', 'ul', 'button', 'datalist', 'fieldset', 'form', 'input', 'figcaption', 'figure', 'hr', 'li', 'ol', 'p', 'pre', 'ul', 'button', 'datalist', 'fieldset', 'form', 'input',
'label', 'legend', 'meter', 'optgroup', 'option', 'output', 'progress', 'select', 'textarea', 'applet', 'label', 'legend', 'meter', 'optgroup', 'option', 'output', 'progress', 'select', 'textarea', 'applet',
'frame', 'frameset' 'frame', 'frameset'
# fmt: on
] ]

View File

@ -23,6 +23,7 @@ from .abstract import EngineProcessor
def default_request_params(): def default_request_params():
"""Default request parameters for ``online`` engines.""" """Default request parameters for ``online`` engines."""
return { return {
# fmt: off
'method': 'GET', 'method': 'GET',
'headers': {}, 'headers': {},
'data': {}, 'data': {},
@ -30,6 +31,7 @@ def default_request_params():
'cookies': {}, 'cookies': {},
'verify': True, 'verify': True,
'auth': None 'auth': None
# fmt: on
} }

View File

@ -616,8 +616,10 @@ def index_error(output_format, error_message):
# html # html
request.errors.append(gettext('search error')) request.errors.append(gettext('search error'))
return render( return render(
# fmt: off
'index.html', 'index.html',
selected_categories=get_selected_categories(request.preferences, request.form), selected_categories=get_selected_categories(request.preferences, request.form),
# fmt: on
) )
@ -631,8 +633,10 @@ def index():
return redirect(url_for('search') + query, 308) return redirect(url_for('search') + query, 308)
return render( return render(
# fmt: off
'index.html', 'index.html',
selected_categories=get_selected_categories(request.preferences, request.form), selected_categories=get_selected_categories(request.preferences, request.form),
# fmt: on
) )
@ -662,8 +666,10 @@ def search():
if not request.form.get('q'): if not request.form.get('q'):
if output_format == 'html': if output_format == 'html':
return render( return render(
# fmt: off
'index.html', 'index.html',
selected_categories=get_selected_categories(request.preferences, request.form), selected_categories=get_selected_categories(request.preferences, request.form),
# fmt: on
) )
return index_error(output_format, 'No query'), 400 return index_error(output_format, 'No query'), 400
@ -811,6 +817,7 @@ def search():
)) ))
return render( return render(
# fmt: off
'results.html', 'results.html',
results = results, results = results,
q=request.form['q'], q=request.form['q'],
@ -835,6 +842,7 @@ def search():
theme = get_current_theme_name(), theme = get_current_theme_name(),
favicons = global_favicons[themes.index(get_current_theme_name())], favicons = global_favicons[themes.index(get_current_theme_name())],
timeout_limit = request.form.get('timeout_limit', None) timeout_limit = request.form.get('timeout_limit', None)
# fmt: on
) )
@ -1045,6 +1053,7 @@ def preferences():
} }
return render( return render(
# fmt: off
'preferences.html', 'preferences.html',
selected_categories = get_selected_categories(request.preferences, request.form), selected_categories = get_selected_categories(request.preferences, request.form),
locales = LOCALE_NAMES, locales = LOCALE_NAMES,
@ -1071,6 +1080,7 @@ def preferences():
preferences_url_params = request.preferences.get_as_url_params(), preferences_url_params = request.preferences.get_as_url_params(),
locked_preferences = settings['preferences']['lock'], locked_preferences = settings['preferences']['lock'],
preferences = True preferences = True
# fmt: on
) )
@ -1233,12 +1243,14 @@ def stats():
engine_stats['time'] = sorted(engine_stats['time'], reverse=reverse, key=get_key) engine_stats['time'] = sorted(engine_stats['time'], reverse=reverse, key=get_key)
return render( return render(
# fmt: off
'stats.html', 'stats.html',
sort_order = sort_order, sort_order = sort_order,
engine_stats = engine_stats, engine_stats = engine_stats,
engine_reliabilities = engine_reliabilities, engine_reliabilities = engine_reliabilities,
selected_engine_name = selected_engine_name, selected_engine_name = selected_engine_name,
searx_git_branch = GIT_BRANCH, searx_git_branch = GIT_BRANCH,
# fmt: on
) )

View File

@ -55,7 +55,9 @@ NOT_A_DESCRIPTION = [
] ]
SKIP_ENGINE_SOURCE = [ SKIP_ENGINE_SOURCE = [
# fmt: off
('gitlab', 'wikidata') # descriptions are about wikipedia disambiguation pages ('gitlab', 'wikidata') # descriptions are about wikipedia disambiguation pages
# fmt: on
] ]
LANGUAGES = LOCALE_NAMES.keys() LANGUAGES = LOCALE_NAMES.keys()

View File

@ -19,10 +19,12 @@ NORMAL_REGEX = re.compile('^[0-9]+\.[0-9](\.[0-9])?$')
# #
useragents = { useragents = {
# fmt: off
"versions": (), "versions": (),
"os": ('Windows NT 10.0; Win64; x64', "os": ('Windows NT 10.0; Win64; x64',
'X11; Linux x86_64'), 'X11; Linux x86_64'),
"ua": "Mozilla/5.0 ({os}; rv:{version}) Gecko/20100101 Firefox/{version}" "ua": "Mozilla/5.0 ({os}; rv:{version}) Gecko/20100101 Firefox/{version}",
# fmt: on
} }

View File

@ -26,6 +26,7 @@ class LogicodevStyle(Style): # pylint: disable=R0903
background_color = '#282C34' background_color = '#282C34'
styles = { styles = {
# fmt: off
Comment: "#556366 italic", Comment: "#556366 italic",
Comment.Multiline: "#556366 italic", Comment.Multiline: "#556366 italic",
Comment.Preproc: "#BC7A00", Comment.Preproc: "#BC7A00",
@ -51,13 +52,13 @@ class LogicodevStyle(Style): # pylint: disable=R0903
Keyword.Type: "#D46C72", Keyword.Type: "#D46C72",
Literal.Number: "#D19A66", Literal.Number: "#D19A66",
Literal.String: "#86C372", Literal.String: "#86C372",
Literal.String.Backtick:"#86C372", Literal.String.Backtick: "#86C372",
Literal.String.Char: "#86C372", Literal.String.Char: "#86C372",
Literal.String.Doc: "#86C372 italic", Literal.String.Doc: "#86C372 italic",
Literal.String.Double: "#86C372", Literal.String.Double: "#86C372",
Literal.String.Escape: "#BB6622 bold", Literal.String.Escape: "#BB6622 bold",
Literal.String.Heredoc: "#86C372", Literal.String.Heredoc: "#86C372",
Literal.String.Interpol:"#BB6688 bold", Literal.String.Interpol: "#BB6688 bold",
Literal.String.Other: "#BE74D5", Literal.String.Other: "#BE74D5",
Literal.String.Regex: "#BB6688", Literal.String.Regex: "#BB6688",
Literal.String.Single: "#86C372", Literal.String.Single: "#86C372",
@ -81,6 +82,7 @@ class LogicodevStyle(Style): # pylint: disable=R0903
Operator: "#D19A66", Operator: "#D19A66",
Operator.Word: "#AA22FF bold", Operator.Word: "#AA22FF bold",
Text.Whitespace: "#D7DAE0", Text.Whitespace: "#D7DAE0",
# fmt: on
} }

View File

@ -8,10 +8,14 @@ def fake_result(url='https://aa.bb/cc?dd=ee#ff',
title='aaa', title='aaa',
content='bbb', content='bbb',
engine='wikipedia', **kwargs): engine='wikipedia', **kwargs):
result = {'url': url, result = {
# fmt: off
'url': url,
'title': title, 'title': title,
'content': content, 'content': content,
'engine': engine} 'engine': engine,
# fmt: on
}
result.update(kwargs) result.update(kwargs)
return result return result