Browse Source

[fix] pep8 compatibility

Adam Tauber 10 years ago
parent
commit
b0fd71b7b3
2 changed files with 22 additions and 18 deletions
  1. 7
    6
      searx/engines/yahoo_news.py
  2. 15
    12
      searx/https_rewrite.py

+ 7
- 6
searx/engines/yahoo_news.py View File

@@ -1,8 +1,9 @@
1
-## Yahoo (News)
2
-# 
1
+# Yahoo (News)
2
+#
3 3
 # @website     https://news.yahoo.com
4
-# @provide-api yes (https://developer.yahoo.com/boss/search/), $0.80/1000 queries
5
-# 
4
+# @provide-api yes (https://developer.yahoo.com/boss/search/)
5
+#              $0.80/1000 queries
6
+#
6 7
 # @using-api   no (because pricing)
7 8
 # @results     HTML (using search portal)
8 9
 # @stable      no (HTML can change)
@@ -22,7 +23,7 @@ paging = True
22 23
 language_support = True
23 24
 
24 25
 # search-url
25
-search_url = 'https://news.search.yahoo.com/search?{query}&b={offset}&fl=1&vl=lang_{lang}'
26
+search_url = 'https://news.search.yahoo.com/search?{query}&b={offset}&fl=1&vl=lang_{lang}'  # noqa
26 27
 
27 28
 # specific xpath variables
28 29
 results_xpath = '//div[@class="res"]'
@@ -41,7 +42,7 @@ def request(query, params):
41 42
         language = 'en'
42 43
     else:
43 44
         language = params['language'].split('_')[0]
44
-    
45
+
45 46
     params['url'] = search_url.format(offset=offset,
46 47
                                       query=urlencode({'p': query}),
47 48
                                       lang=language)

+ 15
- 12
searx/https_rewrite.py View File

@@ -45,11 +45,9 @@ def load_single_https_ruleset(filepath):
45 45
     # get root node
46 46
     root = tree.getroot()
47 47
 
48
-    #print(etree.tostring(tree))
49
-
50 48
     # check if root is a node with the name ruleset
51 49
     # TODO improve parsing
52
-    if root.tag != 'ruleset':        
50
+    if root.tag != 'ruleset':
53 51
         return ()
54 52
 
55 53
     # check if rule is deactivated by default
@@ -68,36 +66,39 @@ def load_single_https_ruleset(filepath):
68 66
     for ruleset in root:
69 67
         # this child define a target
70 68
         if ruleset.tag == 'target':
71
-            # check if required tags available 
69
+            # check if required tags available
72 70
             if not ruleset.attrib.get('host'):
73 71
                 continue
74 72
 
75 73
             # convert host-rule to valid regex
76
-            host = ruleset.attrib.get('host').replace('.', '\.').replace('*', '.*')
74
+            host = ruleset.attrib.get('host')\
75
+                .replace('.', '\.').replace('*', '.*')
77 76
 
78 77
             # append to host list
79 78
             hosts.append(host)
80 79
 
81 80
         # this child define a rule
82 81
         elif ruleset.tag == 'rule':
83
-            # check if required tags available 
82
+            # check if required tags available
84 83
             if not ruleset.attrib.get('from')\
85 84
                or not ruleset.attrib.get('to'):
86 85
                 continue
87 86
 
88
-            # TODO hack, which convert a javascript regex group into a valid python regex group
87
+            # TODO hack, which convert a javascript regex group
88
+            # into a valid python regex group
89 89
             rule_from = ruleset.attrib.get('from').replace('$', '\\')
90 90
             rule_to = ruleset.attrib.get('to').replace('$', '\\')
91 91
 
92
-            # TODO, not working yet because of the hack above, currently doing that in webapp.py
93
-            #rule_from_rgx = re.compile(rule_from, re.I)
92
+            # TODO, not working yet because of the hack above,
93
+            # currently doing that in webapp.py
94
+            # rule_from_rgx = re.compile(rule_from, re.I)
94 95
 
95 96
             # append rule
96 97
             rules.append((rule_from, rule_to))
97 98
 
98 99
         # this child define an exclusion
99 100
         elif ruleset.tag == 'exclusion':
100
-            # check if required tags available 
101
+            # check if required tags available
101 102
             if not ruleset.attrib.get('pattern'):
102 103
                 continue
103 104
 
@@ -124,7 +125,9 @@ def load_https_rules(rules_path):
124 125
         rules_path += '/'
125 126
 
126 127
     # search all xml files which are stored in the https rule directory
127
-    xml_files = [ join(rules_path,f) for f in listdir(rules_path) if isfile(join(rules_path,f)) and f[-4:] == '.xml' ]
128
+    xml_files = [join(rules_path, f)
129
+                 for f in listdir(rules_path)
130
+                 if isfile(join(rules_path, f)) and f[-4:] == '.xml']
128 131
 
129 132
     # load xml-files
130 133
     for ruleset_file in xml_files:
@@ -137,5 +140,5 @@ def load_https_rules(rules_path):
137 140
 
138 141
         # append ruleset
139 142
         https_rules.append(ruleset)
140
-        
143
+
141 144
     print(' * {n} https-rules loaded'.format(n=len(https_rules)))