Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
infra
spot
Commits
cc26dde7
Commit
cc26dde7
authored
Jan 16, 2019
by
Nicolas Gelot
Browse files
Update pep8 tools to pycodestyle
pep8 is deprecated, it is replaced by pycodestyle.
parent
bbb5e68b
Changes
13
Hide whitespace changes
Inline
Side-by-side
manage.sh
View file @
cc26dde7
...
...
@@ -35,7 +35,8 @@ pep8_check() {
# ignored rules:
# E402 module level import not at top of file
# W503 line break before binary operator
pep8
--exclude
=
searx/static
--max-line-length
=
120
--ignore
"E402,W503"
"
$SEARX_DIR
"
"
$BASE_DIR
/tests"
# E722 do not use bare 'except'
pycodestyle
--exclude
=
searx/static
--max-line-length
=
120
--ignore
"E402,W503,E722"
"
$SEARX_DIR
"
"
$BASE_DIR
/tests"
}
unit_tests
()
{
...
...
requirements-dev.txt
View file @
cc26dde7
babel==2.3.4
mock==2.0.0
p
ep8==1.7
.0
p
ycodestyle==2.4
.0
mockredispy==2.9.3
pytest==4.1.0
pytest-cov==2.6.1
searx/__init__.py
View file @
cc26dde7
...
...
@@ -23,7 +23,7 @@ from io import open
from
ssl
import
OPENSSL_VERSION_INFO
,
OPENSSL_VERSION
try
:
from
yaml
import
load
except
:
except
ImportError
:
from
sys
import
exit
,
stderr
stderr
.
write
(
'[E] install pyyaml
\n
'
)
exit
(
2
)
...
...
@@ -38,6 +38,7 @@ def check_settings_yml(file_name):
else
:
return
None
# find location of settings.yml
if
'SEARX_SETTINGS_PATH'
in
environ
:
# if possible set path to settings using the
...
...
searx/engines/bing_images.py
View file @
cc26dde7
...
...
@@ -116,7 +116,7 @@ def _fetch_supported_languages(resp):
regions
=
dom
.
xpath
(
regions_xpath
)
for
region
in
regions
:
code
=
re
.
search
(
'setmkt=[^
\
&]+'
,
region
).
group
()[
7
:]
code
=
re
.
search
(
'setmkt=[^&]+'
,
region
).
group
()[
7
:]
if
code
==
'nb-NO'
:
code
=
'no-NO'
...
...
searx/engines/genius.py
View file @
cc26dde7
...
...
@@ -72,6 +72,7 @@ def parse_album(hit):
result
.
update
({
'content'
:
'Released: {}'
.
format
(
year
)})
return
result
parse
=
{
'lyric'
:
parse_lyric
,
'song'
:
parse_lyric
,
'artist'
:
parse_artist
,
'album'
:
parse_album
}
...
...
searx/engines/google.py
View file @
cc26dde7
...
...
@@ -89,9 +89,8 @@ url_map = 'https://www.openstreetmap.org/'\
# search-url
search_path
=
'/search'
search_url
=
(
'https://{hostname}'
+
search_path
+
'?{query}&start={offset}&gws_rd=cr&gbv=1&lr={lang}&hl={lang_short}&ei=x'
)
search_url
=
(
'https://{hostname}'
+
search_path
+
'?{query}'
'&start={offset}&gws_rd=cr&gbv=1&lr={lang}&hl={lang_short}&ei=x'
)
time_range_search
=
"&tbs=qdr:{range}"
time_range_dict
=
{
'day'
:
'd'
,
...
...
searx/engines/google_videos.py
View file @
cc26dde7
...
...
@@ -76,11 +76,11 @@ def response(resp):
# get thumbnails
script
=
str
(
dom
.
xpath
(
'//script[contains(., "_setImagesSrc")]'
)[
0
].
text
)
id
=
result
.
xpath
(
'.//div[@class="s"]//img/@id'
)[
0
]
thumbnails_data
=
re
.
findall
(
's=
\'
(.*?)(?:
\\\\
[a-z,1-9,
\\\\
]+
\'
|
\'
)\;var ii=\[(?:|[
\'
vidthumb\d+
\'
,]+)
\'
'
+
id
,
thumbnails_data
=
re
.
findall
(
r
's=\'(.*?)(?:\\\\[a-z,1-9,\\\\]+\'|\')\;var ii=\[(?:|[\'vidthumb\d+\',]+)\''
+
id
,
script
)
tmp
=
[]
if
len
(
thumbnails_data
)
!=
0
:
tmp
=
re
.
findall
(
'(data:image/jpeg;base64,[a-z,A-Z,0-9,/,\+]+)'
,
thumbnails_data
[
0
])
tmp
=
re
.
findall
(
r
'(data:image/jpeg;base64,[a-z,A-Z,0-9,/,\+]+)'
,
thumbnails_data
[
0
])
thumbnail
=
''
if
len
(
tmp
)
!=
0
:
thumbnail
=
tmp
[
-
1
]
...
...
searx/engines/swisscows.py
View file @
cc26dde7
...
...
@@ -28,10 +28,10 @@ search_string = '?{query}&page={page}'
supported_languages_url
=
base_url
# regex
regex_json
=
re
.
compile
(
'initialData: {"Request":(.|
\n
)*},\s*environment'
)
regex_json_remove_start
=
re
.
compile
(
'^initialData:\s*'
)
regex_json_remove_end
=
re
.
compile
(
',\s*environment$'
)
regex_img_url_remove_start
=
re
.
compile
(
'^https?://i\.swisscows\.ch/\?link='
)
regex_json
=
re
.
compile
(
r
'initialData: {"Request":(.|\n)*},\s*environment'
)
regex_json_remove_start
=
re
.
compile
(
r
'^initialData:\s*'
)
regex_json_remove_end
=
re
.
compile
(
r
',\s*environment$'
)
regex_img_url_remove_start
=
re
.
compile
(
r
'^https?://i\.swisscows\.ch/\?link='
)
# do search-request
...
...
searx/query.py
View file @
cc26dde7
...
...
@@ -49,7 +49,7 @@ class RawTextQuery(object):
self
.
query_parts
=
[]
# split query, including whitespaces
raw_query_parts
=
re
.
split
(
r
'(\s+)'
if
isinstance
(
self
.
query
,
str
)
else
b
'(\s+)'
,
self
.
query
)
raw_query_parts
=
re
.
split
(
r
'(\s+)'
if
isinstance
(
self
.
query
,
str
)
else
r
'(\s+)'
.
encode
()
,
self
.
query
)
parse_next
=
True
...
...
searx/results.py
View file @
cc26dde7
...
...
@@ -171,7 +171,7 @@ class ResultContainer(object):
continue
try
:
result
[
'url'
]
=
result
[
'url'
]
except
:
except
KeyError
:
pass
if
'title'
in
result
and
not
isinstance
(
result
[
'title'
],
str
):
continue
...
...
searx/utils.py
View file @
cc26dde7
...
...
@@ -6,6 +6,7 @@ import re
from
babel.core
import
get_global
from
babel.dates
import
format_date
from
babel
import
UnknownLocaleError
from
codecs
import
getincrementalencoder
from
imp
import
load_source
from
numbers
import
Number
...
...
@@ -205,7 +206,7 @@ def format_date_by_locale(date, locale_string):
# to avoid crashing if locale is not supported by babel
try
:
formatted_date
=
format_date
(
date
,
locale
=
locale_string
)
except
:
except
UnknownLocaleError
:
formatted_date
=
format_date
(
date
,
"YYYY-MM-dd"
)
return
formatted_date
...
...
@@ -255,7 +256,7 @@ def get_torrent_size(filesize, filesize_multiplier):
filesize
=
int
(
filesize
*
1000
*
1000
)
elif
filesize_multiplier
==
'KiB'
:
filesize
=
int
(
filesize
*
1000
)
except
:
except
ValueError
:
filesize
=
None
return
filesize
...
...
searx/webapp.py
View file @
cc26dde7
...
...
@@ -40,8 +40,9 @@ logger = logger.getChild('webapp')
try
:
from
pygments
import
highlight
from
pygments.lexers
import
get_lexer_by_name
from
pygments.util
import
ClassNotFound
from
pygments.formatters
import
HtmlFormatter
except
:
except
ImportError
:
logger
.
critical
(
"cannot import dependency: pygments"
)
from
sys
import
exit
...
...
@@ -178,7 +179,7 @@ def code_highlighter(codelines, language=None):
try
:
# find lexer by programing language
lexer
=
get_lexer_by_name
(
language
,
stripall
=
True
)
except
:
except
ClassNotFound
:
# if lexer is not found, using default one
logger
.
debug
(
'highlighter cannot find lexer for {0}'
.
format
(
language
))
lexer
=
get_lexer_by_name
(
'text'
,
stripall
=
True
)
...
...
tests/unit/engines/test_currency_convert.py
View file @
cc26dde7
...
...
@@ -48,8 +48,11 @@ class TestCurrencyConvertEngine(TestCase):
results
=
currency_convert
.
response
(
response
)
self
.
assertEqual
(
type
(
results
),
list
)
self
.
assertEqual
(
len
(
results
),
1
)
self
.
assertEqual
(
results
[
0
][
'answer'
],
'10.0 GBP = 5.0 USD, 1 GBP (pound sterling)'
+
' = 0.5 USD (United States dollar)'
)
self
.
assertEqual
(
results
[
0
][
'answer'
],
(
'10.0 GBP = 5.0 USD, 1 GBP (pound sterling)'
' = 0.5 USD (United States dollar)'
)
)
target_url
=
'https://duckduckgo.com/js/spice/currency/1/{}/{}'
.
format
(
dicto
[
'from'
],
dicto
[
'to'
])
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment