Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Nov 30, 2018
1 parent 93b5953 commit bbdfd4d
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions msgpack/fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import struct
import warnings

if sys.version_info[0] == 3:
PY3 = True

if sys.version_info[0] == 2:
PY2 = True
int_types = (int, long)
def dict_iteritems(d):
return d.iteritems()
else:
PY2 = False
int_types = int
Unicode = str
unicode = str
xrange = range
def dict_iteritems(d):
return d.items()
else:
PY3 = False
int_types = (int, long)
Unicode = unicode
def dict_iteritems(d):
return d.iteritems()

if sys.version_info < (3, 5):
# Ugly hack...
Expand Down Expand Up @@ -97,7 +97,7 @@ def _get_data_from_buffer(obj):
view = memoryview(obj)
except TypeError:
# try to use legacy buffer protocol if 2.7, otherwise re-raise
if not PY3:
if PY2:
view = memoryview(buffer(obj))
warnings.warn("using old buffer interface to unpack %s; "
"this leads to unpacking errors if slicing is used and "
Expand Down Expand Up @@ -639,7 +639,7 @@ def _unpack(self, execute=EX_CONSTRUCT):
ret = {}
for _ in xrange(n):
key = self._unpack(EX_CONSTRUCT)
if self._strict_map_key and type(key) not in (Unicode, bytes):
if self._strict_map_key and type(key) not in (unicode, bytes):
raise ValueError("%s is not allowed for map key" % str(type(key)))
ret[key] = self._unpack(EX_CONSTRUCT)
if self._object_hook is not None:
Expand Down Expand Up @@ -819,7 +819,7 @@ def _pack(self, obj, nest_limit=DEFAULT_RECURSE_LIMIT,
raise ValueError("%s is too large" % type(obj).__name__)
self._pack_bin_header(n)
return self._buffer.write(obj)
if check(obj, Unicode):
if check(obj, unicode):
if self._encoding is None:
raise TypeError(
"Can't encode unicode string: "
Expand Down Expand Up @@ -1006,7 +1006,7 @@ def reset(self):

def getbuffer(self):
"""Return view of internal buffer."""
if USING_STRINGBUILDER or not PY3:
if USING_STRINGBUILDER or PY2:
return memoryview(self.bytes())
else:
return self._buffer.getbuffer()

0 comments on commit bbdfd4d

Please sign in to comment.