Skip to content

Commit d2ad86c

Browse files
committed
Python 2/3 changes pulled from the production server after the switch to python 3.
- Legacy-Id: 17327
1 parent cf56beb commit d2ad86c

5 files changed

Lines changed: 19 additions & 8 deletions

File tree

ietf/bin/iana-protocols-updates

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ from ietf.sync.iana import fetch_protocol_page, parse_protocol_page, update_rfc_
2323

2424
def chunks(l, n):
2525
"""Split list l up in chunks of max size n."""
26-
return (l[i:i+n] for i in xrange(0, len(l), n))
26+
return (l[i:i+n] for i in range(0, len(l), n))
2727

2828
syslog.syslog("Updating history log with new RFC entries from IANA protocols page %s" % settings.IANA_SYNC_PROTOCOLS_URL)
2929

ietf/idindex/generate_all_id2_txt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@
3737

3838
from __future__ import absolute_import, print_function, unicode_literals
3939

40+
import locale
4041
import os
4142
import six
4243
import sys
44+
4345
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings")
4446

4547
import django

ietf/sync/iana.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2012-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2012-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -13,7 +13,7 @@
1313
from six.moves.urllib.request import Request, urlopen
1414

1515
from django.conf import settings
16-
from django.utils.encoding import force_str
16+
from django.utils.encoding import smart_bytes, force_str
1717
from django.utils.http import urlquote
1818

1919
import debug # pyflakes:ignore
@@ -31,14 +31,14 @@
3131

3232
def fetch_protocol_page(url):
3333
f = urlopen(settings.IANA_SYNC_PROTOCOLS_URL)
34-
text = f.read()
34+
text = force_str(f.read())
3535
f.close()
3636
return text
3737

3838
def parse_protocol_page(text):
3939
"""Parse IANA protocols page to extract referenced RFCs (as
4040
rfcXXXX document names)."""
41-
matches = re.findall('RFC [0-9]+', text)
41+
matches = re.findall('RFC [0-9]+', force_str(text))
4242
res = set()
4343
for m in matches:
4444
res.add("rfc" + m[len("RFC "):])
@@ -78,7 +78,7 @@ def fetch_changes_json(url, start, end):
7878
# HTTP basic auth
7979
username = "ietfsync"
8080
password = settings.IANA_SYNC_PASSWORD
81-
request.add_header("Authorization", "Basic %s" % base64.encodestring("%s:%s" % (username, password)).replace("\n", ""))
81+
request.add_header("Authorization", "Basic %s" % force_str(base64.encodestring(smart_bytes("%s:%s" % (username, password)))).replace("\n", ""))
8282
f = urlopen(request)
8383
text = f.read()
8484
f.close()

ietf/sync/views.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright The IETF Trust 2012-2020, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
15
import datetime
26
import subprocess
37
import os
@@ -73,10 +77,13 @@ def notify(request, org, notification):
7377

7478
if request.method == "POST":
7579
def runscript(name):
76-
cmd = ["python", os.path.join(SYNC_BIN_PATH, name)]
80+
python = os.path.join(settings.BASE_DIR, "env", "bin", "python")
81+
cmd = [python, os.path.join(SYNC_BIN_PATH, name)]
7782
cmdstring = " ".join(cmd)
7883
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
7984
out, err = p.communicate()
85+
out = out.decode('utf-8')
86+
err = err.decode('utf-8')
8087
if p.returncode:
8188
log("Subprocess error %s when running '%s': %s %s" % (p.returncode, cmd, err, out))
8289
raise subprocess.CalledProcessError(p.returncode, cmdstring, "\n".join([err, out]))

ietf/utils/management/commands/update_external_command_info.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2017-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2017-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -30,6 +30,8 @@ def handle(self, *filenames, **options):
3030
for c in VersionInfo.objects.filter(used=True):
3131
cmd = "%s %s" % (c.command, c.switch)
3232
code, out, err = pipe(cmd)
33+
out = out.decode('utf-8')
34+
err = err.decode('utf-8')
3335
if code != 0:
3436
sys.stderr.write("Command '%s' retuned %s: \n%s\n%s\n" % (cmd, code, out, err))
3537
else:

0 commit comments

Comments
 (0)