Ver código fonte

[fix] pep8 compatibilty

Adam Tauber 9 anos atrás
pai
commit
bd22e9a336

+ 4
- 1
manage.sh Ver arquivo

@@ -16,7 +16,10 @@ update_dev_packages() {
16 16
 
17 17
 pep8_check() {
18 18
     echo '[!] Running pep8 check'
19
-    pep8 --max-line-length=120 "$SEARX_DIR" "$BASE_DIR/tests"
19
+    # ignored rules:
20
+    #  E402 module level import not at top of file
21
+    #  W503 line break before binary operator
22
+    pep8 --max-line-length=120 --ignore "E402,W503" "$SEARX_DIR" "$BASE_DIR/tests"
20 23
 }
21 24
 
22 25
 unit_tests() {

+ 1
- 1
requirements-dev.txt Ver arquivo

@@ -1,7 +1,7 @@
1 1
 babel==2.2.0
2
-flake8==2.5.1
3 2
 mock==1.0.1
4 3
 nose2[coverage-plugin]
4
+pep8==1.7.0
5 5
 plone.testing==4.0.15
6 6
 robotframework-selenium2library==1.7.4
7 7
 robotsuite==1.7.0

+ 2
- 4
searx/autocomplete.py Ver arquivo

@@ -114,8 +114,7 @@ def dbpedia(query):
114 114
     # dbpedia autocompleter, no HTTPS
115 115
     autocomplete_url = 'http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?'
116 116
 
117
-    response = get(autocomplete_url
118
-                   + urlencode(dict(QueryString=query)))
117
+    response = get(autocomplete_url + urlencode(dict(QueryString=query)))
119 118
 
120 119
     results = []
121 120
 
@@ -141,8 +140,7 @@ def google(query):
141 140
     # google autocompleter
142 141
     autocomplete_url = 'https://suggestqueries.google.com/complete/search?client=toolbar&'
143 142
 
144
-    response = get(autocomplete_url
145
-                   + urlencode(dict(q=query)))
143
+    response = get(autocomplete_url + urlencode(dict(q=query)))
146 144
 
147 145
     results = []
148 146
 

+ 1
- 1
searx/engines/blekko_images.py Ver arquivo

@@ -37,7 +37,7 @@ def request(query, params):
37 37
                           c=c)
38 38
 
39 39
     if params['pageno'] != 1:
40
-        params['url'] += '&page={pageno}'.format(pageno=(params['pageno']-1))
40
+        params['url'] += '&page={pageno}'.format(pageno=(params['pageno'] - 1))
41 41
 
42 42
     # let Blekko know we wan't have profiling
43 43
     params['cookies']['tag_lesslogging'] = '1'

+ 1
- 1
searx/engines/btdigg.py Ver arquivo

@@ -29,7 +29,7 @@ search_url = url + '/search?q={search_term}&p={pageno}'
29 29
 # do search-request
30 30
 def request(query, params):
31 31
     params['url'] = search_url.format(search_term=quote(query),
32
-                                      pageno=params['pageno']-1)
32
+                                      pageno=params['pageno'] - 1)
33 33
 
34 34
     return params
35 35
 

+ 1
- 1
searx/engines/deviantart.py Ver arquivo

@@ -24,7 +24,7 @@ paging = True
24 24
 
25 25
 # search-url
26 26
 base_url = 'https://www.deviantart.com/'
27
-search_url = base_url+'browse/all/?offset={offset}&{query}'
27
+search_url = base_url + 'browse/all/?offset={offset}&{query}'
28 28
 
29 29
 
30 30
 # do search-request

+ 1
- 1
searx/engines/digg.py Ver arquivo

@@ -22,7 +22,7 @@ paging = True
22 22
 
23 23
 # search-url
24 24
 base_url = 'https://digg.com/'
25
-search_url = base_url+'api/search/{query}.json?position={position}&format=html'
25
+search_url = base_url + 'api/search/{query}.json?position={position}&format=html'
26 26
 
27 27
 # specific xpath variables
28 28
 results_xpath = '//article'

+ 1
- 1
searx/engines/faroo.py Ver arquivo

@@ -88,7 +88,7 @@ def response(resp):
88 88
     for result in search_res['results']:
89 89
         if result['news']:
90 90
             # timestamp (milliseconds since 1970)
91
-            publishedDate = datetime.datetime.fromtimestamp(result['date']/1000.0)  # noqa
91
+            publishedDate = datetime.datetime.fromtimestamp(result['date'] / 1000.0)  # noqa
92 92
 
93 93
             # append news result
94 94
             results.append({'url': result['url'],

+ 2
- 2
searx/engines/searchcode_code.py Ver arquivo

@@ -20,7 +20,7 @@ paging = True
20 20
 
21 21
 # search-url
22 22
 url = 'https://searchcode.com/'
23
-search_url = url+'api/codesearch_I/?{query}&p={pageno}'
23
+search_url = url + 'api/codesearch_I/?{query}&p={pageno}'
24 24
 
25 25
 # special code-endings which are not recognised by the file ending
26 26
 code_endings = {'cs': 'c#',
@@ -32,7 +32,7 @@ code_endings = {'cs': 'c#',
32 32
 # do search-request
33 33
 def request(query, params):
34 34
     params['url'] = search_url.format(query=urlencode({'q': query}),
35
-                                      pageno=params['pageno']-1)
35
+                                      pageno=params['pageno'] - 1)
36 36
 
37 37
     # Disable SSL verification
38 38
     # error: (60) SSL certificate problem: unable to get local issuer

+ 2
- 2
searx/engines/searchcode_doc.py Ver arquivo

@@ -19,13 +19,13 @@ paging = True
19 19
 
20 20
 # search-url
21 21
 url = 'https://searchcode.com/'
22
-search_url = url+'api/search_IV/?{query}&p={pageno}'
22
+search_url = url + 'api/search_IV/?{query}&p={pageno}'
23 23
 
24 24
 
25 25
 # do search-request
26 26
 def request(query, params):
27 27
     params['url'] = search_url.format(query=urlencode({'q': query}),
28
-                                      pageno=params['pageno']-1)
28
+                                      pageno=params['pageno'] - 1)
29 29
 
30 30
     # Disable SSL verification
31 31
     # error: (60) SSL certificate problem: unable to get local issuer

+ 1
- 1
searx/engines/stackoverflow.py Ver arquivo

@@ -22,7 +22,7 @@ paging = True
22 22
 
23 23
 # search-url
24 24
 url = 'https://stackoverflow.com/'
25
-search_url = url+'search?{query}&page={pageno}'
25
+search_url = url + 'search?{query}&page={pageno}'
26 26
 
27 27
 # specific xpath variables
28 28
 results_xpath = '//div[contains(@class,"question-summary")]'

+ 4
- 4
searx/engines/startpage.py Ver arquivo

@@ -90,8 +90,8 @@ def response(resp):
90 90
 
91 91
         # check if search result starts with something like: "2 Sep 2014 ... "
92 92
         if re.match("^([1-9]|[1-2][0-9]|3[0-1]) [A-Z][a-z]{2} [0-9]{4} \.\.\. ", content):
93
-            date_pos = content.find('...')+4
94
-            date_string = content[0:date_pos-5]
93
+            date_pos = content.find('...') + 4
94
+            date_string = content[0:date_pos - 5]
95 95
             published_date = parser.parse(date_string, dayfirst=True)
96 96
 
97 97
             # fix content string
@@ -99,8 +99,8 @@ def response(resp):
99 99
 
100 100
         # check if search result starts with something like: "5 days ago ... "
101 101
         elif re.match("^[0-9]+ days? ago \.\.\. ", content):
102
-            date_pos = content.find('...')+4
103
-            date_string = content[0:date_pos-5]
102
+            date_pos = content.find('...') + 4
103
+            date_string = content[0:date_pos - 5]
104 104
 
105 105
             # calculate datetime
106 106
             published_date = datetime.now() - timedelta(days=int(re.match(r'\d+', date_string).group()))

+ 2
- 2
searx/engines/wikidata.py Ver arquivo

@@ -295,7 +295,7 @@ def get_geolink(claims, propertyName, defaultValue=''):
295 295
     if precision < 0.0003:
296 296
         zoom = 19
297 297
     else:
298
-        zoom = int(15 - precision*8.8322 + precision*precision*0.625447)
298
+        zoom = int(15 - precision * 8.8322 + precision * precision * 0.625447)
299 299
 
300 300
     url = url_map\
301 301
         .replace('{latitude}', str(value.get('latitude', 0)))\
@@ -318,6 +318,6 @@ def get_wikilink(result, wikiid):
318 318
 
319 319
 def get_wiki_firstlanguage(result, wikipatternid):
320 320
     for k in result.get('sitelinks', {}).keys():
321
-        if k.endswith(wikipatternid) and len(k) == (2+len(wikipatternid)):
321
+        if k.endswith(wikipatternid) and len(k) == (2 + len(wikipatternid)):
322 322
             return k[0:2]
323 323
     return None

+ 1
- 1
searx/engines/www1x.py Ver arquivo

@@ -22,7 +22,7 @@ paging = False
22 22
 
23 23
 # search-url
24 24
 base_url = 'https://1x.com'
25
-search_url = base_url+'/backend/search.php?{query}'
25
+search_url = base_url + '/backend/search.php?{query}'
26 26
 
27 27
 
28 28
 # do search-request

+ 2
- 2
searx/engines/xpath.py Ver arquivo

@@ -43,7 +43,7 @@ def extract_url(xpath_results, search_url):
43 43
     if url.startswith('//'):
44 44
         # add http or https to this kind of url //example.com/
45 45
         parsed_search_url = urlparse(search_url)
46
-        url = parsed_search_url.scheme+url
46
+        url = parsed_search_url.scheme + url
47 47
     elif url.startswith('/'):
48 48
         # fix relative url to the search engine
49 49
         url = urljoin(search_url, url)
@@ -69,7 +69,7 @@ def normalize_url(url):
69 69
         p = parsed_url.path
70 70
         mark = p.find('/**')
71 71
         if mark != -1:
72
-            return unquote(p[mark+3:]).decode('utf-8')
72
+            return unquote(p[mark + 3:]).decode('utf-8')
73 73
 
74 74
     return url
75 75
 

+ 1
- 1
searx/engines/yandex.py Ver arquivo

@@ -38,7 +38,7 @@ content_xpath = './/div[@class="serp-item__text"]//text()'
38 38
 def request(query, params):
39 39
     lang = params['language'].split('_')[0]
40 40
     host = base_url.format(tld=language_map.get(lang) or default_tld)
41
-    params['url'] = host + search_url.format(page=params['pageno']-1,
41
+    params['url'] = host + search_url.format(page=params['pageno'] - 1,
42 42
                                              query=urlencode({'text': query}))
43 43
     return params
44 44
 

+ 2
- 2
searx/plugins/https_rewrite.py Ver arquivo

@@ -103,10 +103,10 @@ def load_single_https_ruleset(rules_path):
103 103
             # into a valid python regex group
104 104
             rule_from = ruleset.attrib['from'].replace('$', '\\')
105 105
             if rule_from.endswith('\\'):
106
-                rule_from = rule_from[:-1]+'$'
106
+                rule_from = rule_from[:-1] + '$'
107 107
             rule_to = ruleset.attrib['to'].replace('$', '\\')
108 108
             if rule_to.endswith('\\'):
109
-                rule_to = rule_to[:-1]+'$'
109
+                rule_to = rule_to[:-1] + '$'
110 110
 
111 111
             # TODO, not working yet because of the hack above,
112 112
             # currently doing that in webapp.py

+ 1
- 1
searx/poolrequests.py Ver arquivo

@@ -92,7 +92,7 @@ def head(url, **kwargs):
92 92
     return request('head', url, **kwargs)
93 93
 
94 94
 
95
-def post(url, data=None,  **kwargs):
95
+def post(url, data=None, **kwargs):
96 96
     return request('post', url, data=data, **kwargs)
97 97
 
98 98