From d2ad86c5df6fcae8eb23199ec33f9b6edcba598a Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Sun, 23 Feb 2020 01:34:52 +0000 Subject: [PATCH] Python 2/3 changes pulled from the production server after the switch to python 3. - Legacy-Id: 17327 --- ietf/bin/iana-protocols-updates | 2 +- ietf/idindex/generate_all_id2_txt.py | 2 ++ ietf/sync/iana.py | 10 +++++----- ietf/sync/views.py | 9 ++++++++- .../commands/update_external_command_info.py | 4 +++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/ietf/bin/iana-protocols-updates b/ietf/bin/iana-protocols-updates index 0c87ccace..ab1caed81 100755 --- a/ietf/bin/iana-protocols-updates +++ b/ietf/bin/iana-protocols-updates @@ -23,7 +23,7 @@ from ietf.sync.iana import fetch_protocol_page, parse_protocol_page, update_rfc_ def chunks(l, n): """Split list l up in chunks of max size n.""" - return (l[i:i+n] for i in xrange(0, len(l), n)) + return (l[i:i+n] for i in range(0, len(l), n)) syslog.syslog("Updating history log with new RFC entries from IANA protocols page %s" % settings.IANA_SYNC_PROTOCOLS_URL) diff --git a/ietf/idindex/generate_all_id2_txt.py b/ietf/idindex/generate_all_id2_txt.py index 47e379e5c..6d116bae0 100755 --- a/ietf/idindex/generate_all_id2_txt.py +++ b/ietf/idindex/generate_all_id2_txt.py @@ -37,9 +37,11 @@ from __future__ import absolute_import, print_function, unicode_literals +import locale import os import six import sys + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings") import django diff --git a/ietf/sync/iana.py b/ietf/sync/iana.py index 972f2dda6..b68f9758b 100644 --- a/ietf/sync/iana.py +++ b/ietf/sync/iana.py @@ -1,4 +1,4 @@ -# Copyright The IETF Trust 2012-2019, All Rights Reserved +# Copyright The IETF Trust 2012-2020, All Rights Reserved # -*- coding: utf-8 -*- @@ -13,7 +13,7 @@ import re from six.moves.urllib.request import Request, urlopen from django.conf import settings -from django.utils.encoding import force_str +from django.utils.encoding import smart_bytes, force_str from django.utils.http import urlquote import debug # pyflakes:ignore @@ -31,14 +31,14 @@ from ietf.utils.timezone import local_timezone_to_utc, email_time_to_local_timez def fetch_protocol_page(url): f = urlopen(settings.IANA_SYNC_PROTOCOLS_URL) - text = f.read() + text = force_str(f.read()) f.close() return text def parse_protocol_page(text): """Parse IANA protocols page to extract referenced RFCs (as rfcXXXX document names).""" - matches = re.findall('RFC [0-9]+', text) + matches = re.findall('RFC [0-9]+', force_str(text)) res = set() for m in matches: res.add("rfc" + m[len("RFC "):]) @@ -78,7 +78,7 @@ def fetch_changes_json(url, start, end): # HTTP basic auth username = "ietfsync" password = settings.IANA_SYNC_PASSWORD - request.add_header("Authorization", "Basic %s" % base64.encodestring("%s:%s" % (username, password)).replace("\n", "")) + request.add_header("Authorization", "Basic %s" % force_str(base64.encodestring(smart_bytes("%s:%s" % (username, password)))).replace("\n", "")) f = urlopen(request) text = f.read() f.close() diff --git a/ietf/sync/views.py b/ietf/sync/views.py index 0439f2a7a..0504e412f 100644 --- a/ietf/sync/views.py +++ b/ietf/sync/views.py @@ -1,3 +1,7 @@ +# Copyright The IETF Trust 2012-2020, All Rights Reserved +# -*- coding: utf-8 -*- + + import datetime import subprocess import os @@ -73,10 +77,13 @@ def notify(request, org, notification): if request.method == "POST": def runscript(name): - cmd = ["python", os.path.join(SYNC_BIN_PATH, name)] + python = os.path.join(settings.BASE_DIR, "env", "bin", "python") + cmd = [python, os.path.join(SYNC_BIN_PATH, name)] cmdstring = " ".join(cmd) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() + out = out.decode('utf-8') + err = err.decode('utf-8') if p.returncode: log("Subprocess error %s when running '%s': %s %s" % (p.returncode, cmd, err, out)) raise subprocess.CalledProcessError(p.returncode, cmdstring, "\n".join([err, out])) diff --git a/ietf/utils/management/commands/update_external_command_info.py b/ietf/utils/management/commands/update_external_command_info.py index 7e63d7c65..c7b3497ad 100644 --- a/ietf/utils/management/commands/update_external_command_info.py +++ b/ietf/utils/management/commands/update_external_command_info.py @@ -1,4 +1,4 @@ -# Copyright The IETF Trust 2017-2019, All Rights Reserved +# Copyright The IETF Trust 2017-2020, All Rights Reserved # -*- coding: utf-8 -*- @@ -30,6 +30,8 @@ class Command(BaseCommand): for c in VersionInfo.objects.filter(used=True): cmd = "%s %s" % (c.command, c.switch) code, out, err = pipe(cmd) + out = out.decode('utf-8') + err = err.decode('utf-8') if code != 0: sys.stderr.write("Command '%s' retuned %s: \n%s\n%s\n" % (cmd, code, out, err)) else: