Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in / Register
Toggle navigation
M
my-spot
Project
Project
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
12
Issues
12
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
Packages
Packages
Container Registry
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
e
cloud
my-spot
Commits
6e676cc0
Commit
6e676cc0
authored
Mar 30, 2019
by
Nicolas Gelot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce flake8 check for main module
parent
a9e2a3a0
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
45 additions
and
47 deletions
+45
-47
manage.sh
manage.sh
+1
-0
requirements-dev.txt
requirements-dev.txt
+2
-1
arxiv.py
searx/engines/arxiv.py
+1
-1
pubmed.py
searx/engines/pubmed.py
+1
-1
wikidata.py
searx/engines/wikidata.py
+1
-1
query.py
searx/query.py
+15
-15
utils.py
searx/utils.py
+6
-5
webapp.py
searx/webapp.py
+18
-23
No files found.
manage.sh
View file @
6e676cc0
...
...
@@ -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
()
{
...
...
requirements-dev.txt
View file @
6e676cc0
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
...
...
searx/engines/arxiv.py
View file @
6e676cc0
...
...
@@ -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'
)
...
...
searx/engines/pubmed.py
View file @
6e676cc0
...
...
@@ -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
,
...
...
searx/engines/wikidata.py
View file @
6e676cc0
...
...
@@ -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
:
...
...
searx/query.py
View file @
6e676cc0
...
...
@@ -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
):
...
...
searx/utils.py
View file @
6e676cc0
...
...
@@ -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
...
...
searx/webapp.py
View file @
6e676cc0
...
...
@@ -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'
])
...
...
Write
Preview
Markdown
is supported
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