Skip to content

Commit d9ba665

Browse files
committed
Unicode→str kwargs hack only needed for Python <2.7.
1 parent d85343f commit d9ba665

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

github2/core.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#: Running under Python 3
1010
PY3K = sys.version_info[0] == 3 and True or False
1111

12+
#: Running under Python 2.7, or newer
13+
PY27 = sys.version_info[:2] == 3 and True or False
14+
1215
GITHUB_DATE_FORMAT = "%Y/%m/%d %H:%M:%S %z"
1316
# We need to manually mangle the timezone for commit date formatting because it
1417
# uses -xx:xx format
@@ -158,9 +161,9 @@ def get_value(self, *args, **kwargs):
158161
datatype = kwargs.pop("datatype", None)
159162
value = self.make_request(*args, **kwargs)
160163
if datatype:
161-
if not PY3K:
162-
# unicode keys are not accepted as kwargs by python, see:
163-
#http://mail-archives.apache.org/mod_mbox/qpid-dev/200609.mbox/%3C1159389941.4505.10.camel@localhost.localdomain%3E
164+
if not PY27:
165+
# unicode keys are not accepted as kwargs by python, until 2.7:
166+
# http://bugs.python.org/issue2646
164167
# So we make a local dict with the same keys but as strings:
165168
return datatype(**dict((str(k), v) for (k, v) in value.items()))
166169
else:
@@ -171,7 +174,7 @@ def get_values(self, *args, **kwargs):
171174
datatype = kwargs.pop("datatype", None)
172175
values = self.make_request(*args, **kwargs)
173176
if datatype:
174-
if not PY3K:
177+
if not PY27:
175178
# Same as above, unicode keys will blow up in **args, so we need to
176179
# create a new 'values' dict with string keys
177180
return [datatype(**dict((str(k), v) for (k, v) in value.items()))

0 commit comments

Comments
 (0)