forked from Icycoide/searxng
[format.python] initial formatting of the python code
This patch was generated by black [1]:: make format.python [1] https://github.com/psf/black Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
fcdc2c2cd2
commit
3d96a9839a
184 changed files with 2800 additions and 2836 deletions
|
@ -51,11 +51,7 @@ def sync_resource(base_path, resource_path, name, target_dir, plugin_dir):
|
|||
dep_stat = stat(dep_path)
|
||||
utime(resource_path, ns=(dep_stat.st_atime_ns, dep_stat.st_mtime_ns))
|
||||
except IOError:
|
||||
logger.critical(
|
||||
"failed to copy plugin resource {0} for plugin {1}".format(
|
||||
file_name, name
|
||||
)
|
||||
)
|
||||
logger.critical("failed to copy plugin resource {0} for plugin {1}".format(file_name, name))
|
||||
sys.exit(3)
|
||||
|
||||
# returning with the web path of the resource
|
||||
|
@ -66,36 +62,28 @@ def prepare_package_resources(plugin, plugin_module_name):
|
|||
plugin_base_path = dirname(abspath(plugin.__file__))
|
||||
|
||||
plugin_dir = plugin_module_name
|
||||
target_dir = join(
|
||||
settings["ui"]["static_path"], "plugins/external_plugins", plugin_dir
|
||||
)
|
||||
target_dir = join(settings["ui"]["static_path"], "plugins/external_plugins", plugin_dir)
|
||||
try:
|
||||
makedirs(target_dir, exist_ok=True)
|
||||
except IOError:
|
||||
logger.critical(
|
||||
"failed to create resource directory {0} for plugin {1}".format(
|
||||
target_dir, plugin_module_name
|
||||
)
|
||||
)
|
||||
logger.critical("failed to create resource directory {0} for plugin {1}".format(target_dir, plugin_module_name))
|
||||
sys.exit(3)
|
||||
|
||||
resources = []
|
||||
|
||||
if hasattr(plugin, "js_dependencies"):
|
||||
resources.extend(map(basename, plugin.js_dependencies))
|
||||
plugin.js_dependencies = ([
|
||||
sync_resource(
|
||||
plugin_base_path, x, plugin_module_name, target_dir, plugin_dir
|
||||
) for x in plugin.js_dependencies
|
||||
])
|
||||
plugin.js_dependencies = [
|
||||
sync_resource(plugin_base_path, x, plugin_module_name, target_dir, plugin_dir)
|
||||
for x in plugin.js_dependencies
|
||||
]
|
||||
|
||||
if hasattr(plugin, "css_dependencies"):
|
||||
resources.extend(map(basename, plugin.css_dependencies))
|
||||
plugin.css_dependencies = ([
|
||||
sync_resource(
|
||||
plugin_base_path, x, plugin_module_name, target_dir, plugin_dir
|
||||
) for x in plugin.css_dependencies
|
||||
])
|
||||
plugin.css_dependencies = [
|
||||
sync_resource(plugin_base_path, x, plugin_module_name, target_dir, plugin_dir)
|
||||
for x in plugin.css_dependencies
|
||||
]
|
||||
|
||||
for f in listdir(target_dir):
|
||||
if basename(f) not in resources:
|
||||
|
@ -104,9 +92,7 @@ def prepare_package_resources(plugin, plugin_module_name):
|
|||
remove(resource_path)
|
||||
except IOError:
|
||||
logger.critical(
|
||||
"failed to remove unused resource file {0} for plugin {1}".format(
|
||||
resource_path, plugin_module_name
|
||||
)
|
||||
"failed to remove unused resource file {0} for plugin {1}".format(resource_path, plugin_module_name)
|
||||
)
|
||||
sys.exit(3)
|
||||
|
||||
|
@ -137,9 +123,7 @@ def load_plugin(plugin_module_name, external):
|
|||
|
||||
for plugin_attr, plugin_attr_type in required_attrs:
|
||||
if not hasattr(plugin, plugin_attr):
|
||||
logger.critical(
|
||||
'%s: missing attribute "%s", cannot load plugin', plugin, plugin_attr
|
||||
)
|
||||
logger.critical('%s: missing attribute "%s", cannot load plugin', plugin, plugin_attr)
|
||||
sys.exit(3)
|
||||
attr = getattr(plugin, plugin_attr)
|
||||
if not isinstance(attr, plugin_attr_type):
|
||||
|
@ -152,9 +136,7 @@ def load_plugin(plugin_module_name, external):
|
|||
sys.exit(3)
|
||||
|
||||
for plugin_attr, plugin_attr_type in optional_attrs:
|
||||
if not hasattr(plugin, plugin_attr) or not isinstance(
|
||||
getattr(plugin, plugin_attr), plugin_attr_type
|
||||
):
|
||||
if not hasattr(plugin, plugin_attr) or not isinstance(getattr(plugin, plugin_attr), plugin_attr_type):
|
||||
setattr(plugin, plugin_attr, plugin_attr_type())
|
||||
|
||||
if not hasattr(plugin, "preference_section"):
|
||||
|
@ -164,19 +146,12 @@ def load_plugin(plugin_module_name, external):
|
|||
if plugin.preference_section == "query":
|
||||
for plugin_attr in ("query_keywords", "query_examples"):
|
||||
if not hasattr(plugin, plugin_attr):
|
||||
logger.critical(
|
||||
'missing attribute "{0}", cannot load plugin: {1}'.format(
|
||||
plugin_attr, plugin
|
||||
)
|
||||
)
|
||||
logger.critical('missing attribute "{0}", cannot load plugin: {1}'.format(plugin_attr, plugin))
|
||||
sys.exit(3)
|
||||
|
||||
if settings.get("enabled_plugins"):
|
||||
# searx compatibility: plugin.name in settings['enabled_plugins']
|
||||
plugin.default_on = (
|
||||
plugin.name in settings["enabled_plugins"]
|
||||
or plugin.id in settings["enabled_plugins"]
|
||||
)
|
||||
plugin.default_on = plugin.name in settings["enabled_plugins"] or plugin.id in settings["enabled_plugins"]
|
||||
|
||||
# copy ressources if this is an external plugin
|
||||
if external:
|
||||
|
@ -193,9 +168,7 @@ def load_and_initialize_plugin(plugin_module_name, external, init_args):
|
|||
try:
|
||||
return plugin if plugin.init(*init_args) else None
|
||||
except Exception: # pylint: disable=broad-except
|
||||
plugin.logger.exception(
|
||||
"Exception while calling init, the plugin is disabled"
|
||||
)
|
||||
plugin.logger.exception("Exception while calling init, the plugin is disabled")
|
||||
return None
|
||||
return plugin
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ def on_result(request, search, result):
|
|||
if doi and len(doi) < 50:
|
||||
for suffix in ('/', '.pdf', '.xml', '/full', '/meta', '/abstract'):
|
||||
if doi.endswith(suffix):
|
||||
doi = doi[:-len(suffix)]
|
||||
doi = doi[: -len(suffix)]
|
||||
result['url'] = get_doi_resolver(request.preferences) + doi
|
||||
result['parsed_url'] = urlparse(result['url'])
|
||||
return True
|
||||
|
|
|
@ -15,9 +15,11 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
|||
(C) 2015 by Adam Tauber, <asciimoo@gmail.com>
|
||||
'''
|
||||
from flask_babel import gettext
|
||||
|
||||
name = gettext('Search on category select')
|
||||
description = gettext('Perform search immediately if a category selected. '
|
||||
'Disable to select multiple categories. (JavaScript required)')
|
||||
description = gettext(
|
||||
'Perform search immediately if a category selected. ' 'Disable to select multiple categories. (JavaScript required)'
|
||||
)
|
||||
default_on = True
|
||||
preference_section = 'ui'
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
|||
'''
|
||||
from flask_babel import gettext
|
||||
import re
|
||||
|
||||
name = gettext('Self Informations')
|
||||
description = gettext('Displays your IP if the query is "ip" and your user agent if the query contains "user agent".')
|
||||
default_on = True
|
||||
|
|
|
@ -19,10 +19,12 @@ from flask_babel import gettext
|
|||
import re
|
||||
from urllib.parse import urlunparse, parse_qsl, urlencode
|
||||
|
||||
regexes = {re.compile(r'utm_[^&]+'),
|
||||
re.compile(r'(wkey|wemail)[^&]*'),
|
||||
re.compile(r'(_hsenc|_hsmi|hsCtaTracking|__hssc|__hstc|__hsfp)[^&]*'),
|
||||
re.compile(r'&$')}
|
||||
regexes = {
|
||||
re.compile(r'utm_[^&]+'),
|
||||
re.compile(r'(wkey|wemail)[^&]*'),
|
||||
re.compile(r'(_hsenc|_hsmi|hsCtaTracking|__hssc|__hstc|__hsfp)[^&]*'),
|
||||
re.compile(r'&$'),
|
||||
}
|
||||
|
||||
name = gettext('Tracker URL remover')
|
||||
description = gettext('Remove trackers arguments from the returned URL')
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
from flask_babel import gettext
|
||||
|
||||
name = gettext('Vim-like hotkeys')
|
||||
description = gettext('Navigate search results with Vim-like hotkeys '
|
||||
'(JavaScript required). '
|
||||
'Press "h" key on main or result page to get help.')
|
||||
description = gettext(
|
||||
'Navigate search results with Vim-like hotkeys '
|
||||
'(JavaScript required). '
|
||||
'Press "h" key on main or result page to get help.'
|
||||
)
|
||||
default_on = False
|
||||
preference_section = 'ui'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue