Skip to content

Commit

Permalink
Merge pull request #146 from rowillia/master
Browse files Browse the repository at this point in the history
Fix problems identified by `-3` flag when running in Python 2.7
  • Loading branch information
etrepum committed Sep 26, 2016
2 parents 36a4461 + 074e5f4 commit d5234f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
6 changes: 0 additions & 6 deletions simplejson/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ def u(s):
integer_types = (int, long)
unichr = unichr
reload_module = reload
def fromhex(s):
return s.decode('hex')

else:
PY3 = True
if sys.version_info[:2] >= (3, 4):
Expand All @@ -40,7 +37,4 @@ def u(s):
def unichr(s):
return u(chr(s))

def fromhex(s):
return bytes.fromhex(s)

long_type = integer_types[-1]
18 changes: 11 additions & 7 deletions simplejson/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
import sys
import struct
from .compat import fromhex, b, u, text_type, binary_type, PY3, unichr
from .compat import b, u, text_type, binary_type, PY3, unichr
from .scanner import make_scanner, JSONDecodeError

def _import_c_scanstring():
Expand All @@ -22,12 +22,16 @@ def _import_c_scanstring():
FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL

def _floatconstants():
_BYTES = fromhex('7FF80000000000007FF0000000000000')
# The struct module in Python 2.4 would get frexp() out of range here
# when an endian is specified in the format string. Fixed in Python 2.5+
if sys.byteorder != 'big':
_BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
nan, inf = struct.unpack('dd', _BYTES)
if sys.version_info < (2, 6):
_BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
# The struct module in Python 2.4 would get frexp() out of range here
# when an endian is specified in the format string. Fixed in Python 2.5+
if sys.byteorder != 'big':
_BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
nan, inf = struct.unpack('dd', _BYTES)
else:
nan = float('nan')
inf = float('inf')
return nan, inf, -inf

NaN, PosInf, NegInf = _floatconstants()
Expand Down

0 comments on commit d5234f7

Please sign in to comment.