]> granicus.if.org Git - python/commitdiff
Cleanup json decoder: float() has builtin support of nan, +inf, -inf since Python 2.6
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 28 Nov 2012 23:12:40 +0000 (00:12 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 28 Nov 2012 23:12:40 +0000 (00:12 +0100)
Lib/json/decoder.py

index 07fd696400b3f05b929b557273f5ff5b7e6142e8..9b7438cd5b7bbf997aeee75a673864077c8afd21 100644 (file)
@@ -1,9 +1,6 @@
 """Implementation of JSONDecoder
 """
-import binascii
 import re
-import sys
-import struct
 
 from json import scanner
 try:
@@ -15,14 +12,9 @@ __all__ = ['JSONDecoder']
 
 FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
 
-def _floatconstants():
-    _BYTES = binascii.unhexlify(b'7FF80000000000007FF0000000000000')
-    if sys.byteorder != 'big':
-        _BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
-    nan, inf = struct.unpack('dd', _BYTES)
-    return nan, inf, -inf
-
-NaN, PosInf, NegInf = _floatconstants()
+NaN = float('nan')
+PosInf = float('inf')
+NegInf = float('-inf')
 
 
 def linecol(doc, pos):