Kaydet (Commit) d7fed370 authored tarafından Victor Stinner's avatar Victor Stinner

Cleanup json decoder: float() has builtin support of nan, +inf, -inf since Python 2.6

üst 9f94b6dc
"""Implementation of JSONDecoder """Implementation of JSONDecoder
""" """
import binascii
import re import re
import sys
import struct
from json import scanner from json import scanner
try: try:
...@@ -15,14 +12,9 @@ __all__ = ['JSONDecoder'] ...@@ -15,14 +12,9 @@ __all__ = ['JSONDecoder']
FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
def _floatconstants(): NaN = float('nan')
_BYTES = binascii.unhexlify(b'7FF80000000000007FF0000000000000') PosInf = float('inf')
if sys.byteorder != 'big': NegInf = float('-inf')
_BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
nan, inf = struct.unpack('dd', _BYTES)
return nan, inf, -inf
NaN, PosInf, NegInf = _floatconstants()
def linecol(doc, pos): def linecol(doc, pos):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment