diff options
author | Dalf <alex@al-f.net> | 2020-08-06 17:42:46 +0200 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2020-09-10 10:39:04 +0200 |
commit | 1022228d950c2a809ed613df1a515d9a6cafda7c (patch) | |
tree | d792dddea1a5b278b018ed4e024cd13340d5c1b1 /utils | |
parent | 272158944bf13503e2597018fc60a00baddec660 (diff) | |
download | searxng-1022228d950c2a809ed613df1a515d9a6cafda7c.tar.gz searxng-1022228d950c2a809ed613df1a515d9a6cafda7c.zip |
Drop Python 2 (1/n): remove unicode string and url_utils
Diffstat (limited to 'utils')
-rw-r--r-- | utils/fabfile.py | 2 | ||||
-rw-r--r-- | utils/fetch_currencies.py | 20 | ||||
-rwxr-xr-x | utils/fetch_firefox_version.py | 2 | ||||
-rw-r--r-- | utils/fetch_languages.py | 13 | ||||
-rw-r--r-- | utils/makefile.python | 10 | ||||
-rwxr-xr-x | utils/standalone_searx.py | 3 |
6 files changed, 26 insertions, 24 deletions
diff --git a/utils/fabfile.py b/utils/fabfile.py index 559e2ab6c..93f7fc536 100644 --- a/utils/fabfile.py +++ b/utils/fabfile.py @@ -1,5 +1,5 @@ from fabric.api import cd, run, sudo, put -from cStringIO import StringIO +from io import StringIO base_dir = '/usr/local' diff --git a/utils/fetch_currencies.py b/utils/fetch_currencies.py index 5605fb387..437c375db 100644 --- a/utils/fetch_currencies.py +++ b/utils/fetch_currencies.py @@ -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") diff --git a/utils/fetch_firefox_version.py b/utils/fetch_firefox_version.py index 722c48229..997a752b3 100755 --- a/utils/fetch_firefox_version.py +++ b/utils/fetch_firefox_version.py @@ -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/' diff --git a/utils/fetch_languages.py b/utils/fetch_languages.py index 77ec0bf20..0fb9d9c18 100644 --- a/utils/fetch_languages.py +++ b/utils/fetch_languages.py @@ -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() diff --git a/utils/makefile.python b/utils/makefile.python index df16acbbf..6c6696964 100644 --- a/utils/makefile.python +++ b/utils/makefile.python @@ -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()' diff --git a/utils/standalone_searx.py b/utils/standalone_searx.py index 7bc1d32ed..d43b474d7 100755 --- a/utils/standalone_searx.py +++ b/utils/standalone_searx.py @@ -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)) - |