diff options
author | Roy Williams <rwilliams@lyft.com> | 2016-09-22 14:46:49 -0700 |
---|---|---|
committer | Roy Williams <rwilliams@lyft.com> | 2016-09-22 14:46:53 -0700 |
commit | 074e5f4fcf2aecd4fe648ea273da6f0d8c471fdf (patch) | |
tree | a694eb71b22d3e7249a6dd5ac52478c6c89b71c6 | |
parent | a1cd6421d095af6c7db5e5c44e14916eb555aade (diff) | |
download | simplejson-074e5f4fcf2aecd4fe648ea273da6f0d8c471fdf.tar.gz |
Remove fromhex all together
-rw-r--r-- | simplejson/compat.py | 10 | ||||
-rw-r--r-- | simplejson/decoder.py | 18 |
2 files changed, 11 insertions, 17 deletions
diff --git a/simplejson/compat.py b/simplejson/compat.py index 6dd4132..6f945cc 100644 --- a/simplejson/compat.py +++ b/simplejson/compat.py @@ -15,13 +15,6 @@ if sys.version_info[0] < 3: integer_types = (int, long) unichr = unichr reload_module = reload - try: - from binascii import unhexlify as fromhex - except ImportError: - # Python 2.5 - def fromhex(s): - return s.decode('hex') - else: PY3 = True if sys.version_info[:2] >= (3, 4): @@ -44,7 +37,4 @@ else: def unichr(s): return u(chr(s)) - def fromhex(s): - return bytes.fromhex(s) - long_type = integer_types[-1] diff --git a/simplejson/decoder.py b/simplejson/decoder.py index 545e658..29de124 100644 --- a/simplejson/decoder.py +++ b/simplejson/decoder.py @@ -4,7 +4,7 @@ from __future__ import absolute_import 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(): @@ -22,12 +22,16 @@ __all__ = ['JSONDecoder'] 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() |