Skip to content

Commit 8c6eb3a

Browse files
committed
Python2/3 compatibility: Changed the use of open() and StringIO to io.open() etc.
- Legacy-Id: 16458
1 parent 4ce6768 commit 8c6eb3a

115 files changed

Lines changed: 1359 additions & 690 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

changelog.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Copyright The IETF Trust 2012-2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
from __future__ import absolute_import, print_function, unicode_literals
25
import re
6+
import six
37
from tzparse import tzparse
48
from datetime import datetime as Datetime
59

@@ -44,7 +48,7 @@ def parse(logfile):
4448
inf_line = r"^ \*\*(.*)\*\* *"
4549

4650
entries = []
47-
if type(logfile) == type(''):
51+
if isinstance(logfile, six.string_types):
4852
logfile = open(logfile)
4953
entry = None
5054
for line in logfile:

ietf/api/__init__.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# Copyright The IETF Trust 2014-2019, All Rights Reserved
2-
import re
2+
# -*- coding: utf-8 -*-
3+
4+
5+
from __future__ import absolute_import, print_function, unicode_literals
6+
37
import datetime
4-
from urllib.parse import urlencode
8+
import re
9+
import six
10+
11+
from six.moves.urllib.parse import urlencode
512

613
from django.conf import settings
714
from django.core.exceptions import ObjectDoesNotExist
@@ -75,7 +82,7 @@ def convert(self, value):
7582
if value is None:
7683
return None
7784

78-
if isinstance(value, str):
85+
if isinstance(value, six.string_types):
7986
match = TIMEDELTA_REGEX.search(value)
8087

8188
if match:
@@ -90,7 +97,7 @@ def hydrate(self, bundle):
9097
value = super(TimedeltaField, self).hydrate(bundle)
9198

9299
if value and not hasattr(value, 'seconds'):
93-
if isinstance(value, str):
100+
if isinstance(value, six.string_types):
94101
try:
95102
match = TIMEDELTA_REGEX.search(value)
96103

@@ -112,14 +119,17 @@ class ToOneField(tastypie.fields.ToOneField):
112119

113120
def dehydrate(self, bundle, for_list=True):
114121
foreign_obj = None
122+
previous_obj = None
123+
attrib = None
115124

116125
if callable(self.attribute):
117126
previous_obj = bundle.obj
118127
foreign_obj = self.attribute(bundle)
119-
elif isinstance(self.attribute, str):
128+
elif isinstance(self.attribute, six.string_types):
120129
foreign_obj = bundle.obj
121130

122131
for attr in self._attrs:
132+
attrib = attr
123133
previous_obj = foreign_obj
124134
try:
125135
foreign_obj = getattr(foreign_obj, attr, None)
@@ -131,7 +141,7 @@ def dehydrate(self, bundle, for_list=True):
131141
if callable(self.attribute):
132142
raise ApiFieldError("The related resource for resource %s could not be found." % (previous_obj))
133143
else:
134-
raise ApiFieldError("The model '%r' has an empty attribute '%s' and doesn't allow a null value." % (previous_obj, attr))
144+
raise ApiFieldError("The model '%r' has an empty attribute '%s' and doesn't allow a null value." % (previous_obj, attrib))
135145
return None
136146

137147
fk_resource = self.get_related_resource(foreign_obj)

ietf/api/serializer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Copyright The IETF Trust 2018-2019, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
5+
from __future__ import absolute_import, print_function, unicode_literals
6+
27
import hashlib
38
import json
9+
import six
410

511
from django.core.cache import cache
612
from django.core.exceptions import ObjectDoesNotExist, FieldError
@@ -148,7 +154,7 @@ def end_object(self, obj):
148154
if hasattr(field_value, "_meta"):
149155
self._current[name] = self.expand_related(field_value, name)
150156
else:
151-
self._current[name] = str(field_value)
157+
self._current[name] = six.ensure_text(field_value)
152158
except ObjectDoesNotExist:
153159
pass
154160
except AttributeError:

ietf/community/views.py

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

4+
5+
from __future__ import absolute_import, print_function, unicode_literals
6+
47
import csv
5-
import uuid
68
import datetime
79
import json
10+
import six
11+
import uuid
812

913
from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect, Http404
1014
from django.shortcuts import get_object_or_404, render
1115
from django.contrib.auth.decorators import login_required
1216
from django.utils.html import strip_tags
1317

18+
import debug # pyflakes:ignore
19+
1420
from ietf.community.models import SearchRule, EmailSubscription
1521
from ietf.community.forms import SearchRuleTypeForm, SearchRuleForm, AddDocumentsForm, SubscriptionForm
1622
from ietf.community.utils import lookup_community_list, can_manage_community_list
@@ -174,7 +180,7 @@ def export_to_csv(request, username=None, acronym=None, group_type=None):
174180

175181
response['Content-Disposition'] = 'attachment; filename=%s' % filename
176182

177-
writer = csv.writer(response, dialect=csv.excel, delimiter=',')
183+
writer = csv.writer(response, dialect=csv.excel, delimiter=str(','))
178184

179185
header = [
180186
"Name",
@@ -196,7 +202,7 @@ def export_to_csv(request, username=None, acronym=None, group_type=None):
196202
row.append(e.time.strftime("%Y-%m-%d") if e else "")
197203
row.append(strip_tags(doc.friendly_state()))
198204
row.append(doc.group.acronym if doc.group else "")
199-
row.append(str(doc.ad) if doc.ad else "")
205+
row.append(six.ensure_text(doc.ad) if doc.ad else "")
200206
e = doc.latest_event()
201207
row.append(e.time.strftime("%Y-%m-%d") if e else "")
202208
writer.writerow([v.encode("utf-8") for v in row])
@@ -221,7 +227,7 @@ def feed(request, username=None, acronym=None, group_type=None):
221227

222228
host = request.get_host()
223229
feed_url = 'https://%s%s' % (host, request.get_full_path())
224-
feed_id = uuid.uuid5(uuid.NAMESPACE_URL, feed_url)
230+
feed_id = uuid.uuid5(uuid.NAMESPACE_URL, str(feed_url))
225231
title = '%s RSS Feed' % clist.long_name()
226232
if significant:
227233
subtitle = 'Significant document changes'

0 commit comments

Comments
 (0)