Browse Source

[fix] compile regex in ddg_definitions

a01200356 9 years ago
parent
commit
a44faa7716
1 changed files with 4 additions and 2 deletions
  1. 4
    2
      searx/engines/duckduckgo_definitions.py

+ 4
- 2
searx/engines/duckduckgo_definitions.py View File

1
 import json
1
 import json
2
 from urllib import urlencode
2
 from urllib import urlencode
3
-from re import sub
3
+from re import compile, sub
4
 from lxml import html
4
 from lxml import html
5
 from searx.utils import html_to_text
5
 from searx.utils import html_to_text
6
 from searx.engines.xpath import extract_text
6
 from searx.engines.xpath import extract_text
8
 url = 'https://api.duckduckgo.com/'\
8
 url = 'https://api.duckduckgo.com/'\
9
     + '?{query}&format=json&pretty=0&no_redirect=1&d=1'
9
     + '?{query}&format=json&pretty=0&no_redirect=1&d=1'
10
 
10
 
11
+http_regex = compile(r'^http:')
12
+
11
 
13
 
12
 def result_to_text(url, text, htmlResult):
14
 def result_to_text(url, text, htmlResult):
13
     # TODO : remove result ending with "Meaning" or "Category"
15
     # TODO : remove result ending with "Meaning" or "Category"
106
 
108
 
107
     # to merge with wikidata's infobox
109
     # to merge with wikidata's infobox
108
     if infobox_id:
110
     if infobox_id:
109
-        infobox_id = sub(r'^http:', r'https:', infobox_id)
111
+        infobox_id = http_regex.sub('https:', infobox_id)
110
 
112
 
111
     # entity
113
     # entity
112
     entity = search_res.get('Entity', None)
114
     entity = search_res.get('Entity', None)