Commit 6e676cc0 authored by Nicolas Gelot's avatar Nicolas Gelot

Introduce flake8 check for main module

parent a9e2a3a0
......@@ -38,6 +38,7 @@ pep8_check() {
# W503 line break before binary operator
# E722 do not use bare 'except'
pycodestyle --exclude=searx/static --max-line-length=120 --ignore "E402,W503,E722" "$SEARX_DIR" "$BASE_DIR/tests"
flake8 --ignore=E722 $SEARX_DIR/*.py
}
unit_tests() {
......
babel==2.3.4
mock==2.0.0
pycodestyle==2.4.0
pycodestyle==2.5.0
flake8==3.7.7
mockredispy==2.9.3
pytest==4.1.0
pytest-cov==2.6.1
......
......@@ -61,7 +61,7 @@ def response(resp):
content = content_string.format(doi_content="", abstract_content=abstract)
if len(content) > 300:
content = content[0:300] + "..."
content = content[0:300] + "..."
# TODO: center snippet on query term
publishedDate = datetime.strptime(entry.xpath('.//published')[0].text, '%Y-%m-%dT%H:%M:%SZ')
......
......@@ -81,7 +81,7 @@ def response(resp):
pass
if len(content) > 300:
content = content[0:300] + "..."
content = content[0:300] + "..."
# TODO: center snippet on query term
res_dict = {'url': url,
......
......@@ -374,7 +374,7 @@ def add_url(urls, result, property_id=None, default_label=None, url_prefix=None,
# wiki links don't have property in wikidata page
if link_type and 'wiki' in link_type:
links.append(get_wikilink(result, link_type))
links.append(get_wikilink(result, link_type))
else:
dom_element = result.xpath(property_xpath.replace('{propertyid}', property_id))
if dom_element:
......
......@@ -22,7 +22,6 @@ from searx.engines import (
categories, engines, engine_shortcuts
)
import re
import sys
VALID_LANGUAGE_CODE = re.compile(r'^[a-z]{2,3}(-[a-zA-Z]{2})?$')
......@@ -78,20 +77,21 @@ class RawTextQuery(object):
# if correct language-code is found
# set it as new search-language
if (lang == lang_id
or lang == lang_name
or lang == english_name
or lang.replace('-', ' ') == country)\
and lang not in self.languages:
parse_next = True
lang_parts = lang_id.split('-')
if len(lang_parts) == 2:
self.languages.append(lang_parts[0] + '-' + lang_parts[1].upper())
else:
self.languages.append(lang_id)
# to ensure best match (first match is not necessarily the best one)
if lang == lang_id:
break
if (
lang in [lang_id, lang_name, english_name]
or lang.replace("-", " ") == country # noqa
) and lang not in self.languages:
parse_next = True
lang_parts = lang_id.split("-")
if len(lang_parts) == 2:
self.languages.append(
lang_parts[0] + "-" + lang_parts[1].upper()
)
else:
self.languages.append(lang_id)
# to ensure best match (first match is not necessarily the best one)
if lang == lang_id:
break
# user may set a valid, yet not selectable language
if VALID_LANGUAGE_CODE.match(lang):
......
......@@ -11,7 +11,7 @@ from codecs import getincrementalencoder
from imp import load_source
from numbers import Number
from os.path import splitext, join
from io import open
from pathlib import Path
from random import choice
import sys
import json
......@@ -19,7 +19,6 @@ import json
from searx import settings
from searx.version import VERSION_STRING
from searx.languages import language_codes
from searx import settings
from searx import logger
from io import StringIO
......@@ -31,8 +30,10 @@ logger = logger.getChild('utils')
blocked_tags = ('script',
'style')
useragents = json.loads(open(os.path.dirname(os.path.realpath(__file__))
+ "/data/useragents.json", 'r', encoding='utf-8').read())
useragents = json.load(open(
Path(__file__).parent / "data" / "useragents.json",
encoding='utf-8')
)
def searx_useragent():
......@@ -161,7 +162,7 @@ def get_resources_directory(searx_directory, subdirectory, resources_directory):
if not resources_directory:
resources_directory = os.path.join(searx_directory, subdirectory)
if not os.path.isdir(resources_directory):
raise Exception(directory + " is not a directory")
raise Exception(resources_directory + " is not a directory")
return resources_directory
......
......@@ -17,17 +17,10 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
(C) 2013- by Adam Tauber, <asciimoo@gmail.com>
'''
if __name__ == '__main__':
from sys import path
from os.path import realpath, dirname
path.append(realpath(dirname(realpath(__file__)) + '/../'))
import hashlib
import hmac
import json
import os
import sys
import time
import copy
......@@ -35,7 +28,6 @@ import requests
from searx import logger
logger = logger.getChild('webapp')
from pygments import highlight
from pygments.lexers import get_lexer_by_name
......@@ -75,11 +67,11 @@ from searx.url_utils import urlencode, urlparse, urljoin
from searx.utils import new_hmac
import threading
from io import StringIO
# serve pages with HTTP/1.1
from werkzeug.serving import WSGIRequestHandler
logger = logger.getChild('webapp')
WSGIRequestHandler.protocol_version = "HTTP/{}".format(settings['server'].get('http_protocol_version', '1.0'))
# about static
......@@ -306,10 +298,11 @@ def render(template_name, override_theme=None, **kwargs):
if 'categories' not in kwargs:
kwargs['categories'] = ['general']
kwargs['categories'].extend(x for x in
sorted(categories.keys())
if x != 'general'
and x in enabled_categories)
kwargs["categories"].extend(
x
for x in sorted(categories.keys())
if x != "general" and x in enabled_categories
)
if 'all_categories' not in kwargs:
kwargs['all_categories'] = ['general']
......@@ -415,7 +408,7 @@ def pre_request():
else:
try:
preferences.parse_dict(request.form)
except Exception as e:
except Exception:
logger.exception('invalid settings')
request.errors.append(gettext('Invalid settings'))
......@@ -431,8 +424,9 @@ def pre_request():
allowed_plugins = preferences.plugins.get_enabled()
disabled_plugins = preferences.plugins.get_disabled()
for plugin in plugins:
if ((plugin.default_on and plugin.id not in disabled_plugins)
or plugin.id in allowed_plugins):
if (
plugin.default_on and plugin.id not in disabled_plugins
) or plugin.id in allowed_plugins:
request.user_plugins.append(plugin)
......@@ -631,7 +625,6 @@ def preferences():
# render preferences
image_proxy = request.preferences.get_value('image_proxy')
lang = request.preferences.get_value('language')
disabled_engines = request.preferences.engines.get_disabled()
allowed_plugins = request.preferences.plugins.get_enabled()
......@@ -677,11 +670,13 @@ def preferences():
def _is_selected_language_supported(engine, preferences):
language = preferences.get_value('language')
return (language == 'all'
or match_language(language,
getattr(engine, 'supported_languages', []),
getattr(engine, 'language_aliases', {}), None))
language = preferences.get_value("language")
return language == "all" or match_language(
language,
getattr(engine, "supported_languages", []),
getattr(engine, "language_aliases", {}),
None,
)
@app.route('/image_proxy', methods=['GET'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment