mirror of
https://github.com/searxng/searxng.git
synced 2025-07-23 13:19:17 +02:00
Drop Python 2 (1/n): remove unicode string and url_utils
This commit is contained in:
parent
272158944b
commit
1022228d95
112 changed files with 388 additions and 535 deletions
2
utils/fabfile.py
vendored
2
utils/fabfile.py
vendored
|
@ -1,5 +1,5 @@
|
|||
from fabric.api import cd, run, sudo, put
|
||||
from cStringIO import StringIO
|
||||
from io import StringIO
|
||||
|
||||
|
||||
base_dir = '/usr/local'
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
import json
|
||||
import re
|
||||
import unicodedata
|
||||
import string
|
||||
from urllib import urlencode
|
||||
from urllib.parse import urlencode
|
||||
from requests import get
|
||||
|
||||
languages = {'de', 'en', 'es', 'fr', 'hu', 'it', 'nl', 'jp'}
|
||||
|
@ -39,7 +39,7 @@ def add_currency_name(name, iso4217):
|
|||
|
||||
db_names = db['names']
|
||||
|
||||
if not isinstance(iso4217, basestring):
|
||||
if not isinstance(iso4217, str):
|
||||
print("problem", name, iso4217)
|
||||
return
|
||||
|
||||
|
@ -126,7 +126,7 @@ def wdq_query(query):
|
|||
url = url_wmflabs_template + query
|
||||
htmlresponse = get(url)
|
||||
jsonresponse = json.loads(htmlresponse.content)
|
||||
qlist = map(add_q, jsonresponse.get('items', {}))
|
||||
qlist = list(map(add_q, jsonresponse.get('items', {})))
|
||||
error = jsonresponse.get('status', {}).get('error', None)
|
||||
if error is not None and error != 'OK':
|
||||
print("error for query '" + query + "' :" + error)
|
||||
|
@ -150,12 +150,12 @@ for q in wmflabs_queries:
|
|||
wdq_query(q)
|
||||
|
||||
# static
|
||||
add_currency_name(u"euro", 'EUR')
|
||||
add_currency_name(u"euros", 'EUR')
|
||||
add_currency_name(u"dollar", 'USD')
|
||||
add_currency_name(u"dollars", 'USD')
|
||||
add_currency_name(u"peso", 'MXN')
|
||||
add_currency_name(u"pesos", 'MXN')
|
||||
add_currency_name("euro", 'EUR')
|
||||
add_currency_name("euros", 'EUR')
|
||||
add_currency_name("dollar", 'USD')
|
||||
add_currency_name("dollars", 'USD')
|
||||
add_currency_name("peso", 'MXN')
|
||||
add_currency_name("pesos", 'MXN')
|
||||
|
||||
# write
|
||||
f = open("currencies.json", "wb")
|
||||
|
|
|
@ -9,9 +9,9 @@ path.append(realpath(dirname(realpath(__file__)) + '/../'))
|
|||
import json
|
||||
import requests
|
||||
import re
|
||||
from urllib.parse import urlparse, urljoin
|
||||
from distutils.version import LooseVersion, StrictVersion
|
||||
from lxml import html
|
||||
from searx.url_utils import urlparse, urljoin
|
||||
from searx import searx_dir
|
||||
|
||||
URL = 'https://ftp.mozilla.org/pub/firefox/releases/'
|
||||
|
|
|
@ -174,14 +174,17 @@ def write_languages_file(languages):
|
|||
+ '# this file is generated automatically by utils/update_search_languages.py\n'\
|
||||
+ '\nlanguage_codes = ('
|
||||
for code in sorted(languages):
|
||||
file_content += '\n (u"' + code + '"'\
|
||||
+ ', u"' + languages[code]['name'].split(' (')[0] + '"'\
|
||||
+ ', u"' + languages[code].get('country', '') + '"'\
|
||||
+ ', u"' + languages[code].get('english_name', '').split(' (')[0] + '"),'
|
||||
if 'name' in languages[code]:
|
||||
file_content += '\n ("' + code + '"'\
|
||||
+ ', "' + languages[code]['name'].split(' (')[0] + '"'\
|
||||
+ ', "' + languages[code].get('country', '') + '"'\
|
||||
+ ', "' + languages[code].get('english_name', '').split(' (')[0] + '"),'
|
||||
else:
|
||||
print('ignore ',languages[code])
|
||||
# remove last comma
|
||||
file_content = file_content[:-1]
|
||||
file_content += '\n)\n'
|
||||
new_file.write(file_content.encode('utf8'))
|
||||
new_file.write(file_content.encode())
|
||||
new_file.close()
|
||||
|
||||
|
||||
|
|
|
@ -69,11 +69,11 @@ python-help::
|
|||
@echo ' py[un]install - [un]install python objects in editable mode'
|
||||
@echo ' upload-pypi - upload $(PYDIST)/* files to PyPi'
|
||||
@echo 'options:'
|
||||
@echo ' make PY=2 [targets] => to eval targets with python 2 ($(PY))'
|
||||
@echo ' make PIP_INST= => to set/unset pip install options ($(PIP_INST))'
|
||||
@echo ' make TEST=. => choose test from $(TEST_FOLDER) (default "." runs all)'
|
||||
@echo ' make DEBUG= => target "debug": do not invoke PDB on errors'
|
||||
@echo ' make PY_SETUP_EXTRAS => also install extras_require from setup.py \[develop,test\]'
|
||||
@echo ' make PY=3.7 [targets] => to eval targets with python 3.7 ($(PY))'
|
||||
@echo ' make PIP_INST= => to set/unset pip install options ($(PIP_INST))'
|
||||
@echo ' make TEST=. => choose test from $(TEST_FOLDER) (default "." runs all)'
|
||||
@echo ' make DEBUG= => target "debug": do not invoke PDB on errors'
|
||||
@echo ' make PY_SETUP_EXTRAS => also install extras_require from setup.py \[develop,test\]'
|
||||
@echo ' when using target "pydebug", set breakpoints within py-source by adding::'
|
||||
@echo ' DEBUG()'
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ args = parser.parse_args()
|
|||
# search results for the query
|
||||
form = {
|
||||
"q":args.query,
|
||||
"categories":args.category.decode('utf-8'),
|
||||
"categories":args.category.decode(),
|
||||
"pageno":str(args.pageno),
|
||||
"language":args.lang,
|
||||
"time_range":args.timerange
|
||||
|
@ -101,4 +101,3 @@ result_container_json = {
|
|||
}
|
||||
sys.stdout = codecs.getwriter("UTF-8")(sys.stdout)
|
||||
sys.stdout.write(dumps(result_container_json, sort_keys=True, indent=4, ensure_ascii=False, encoding="utf-8", default=json_serial))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue