summaryrefslogtreecommitdiffstats
path: root/Lib/json
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-05-08 17:18:53 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-05-08 17:18:53 (GMT)
commite4ca8156ef146174c64d537d9fa07a880231e699 (patch)
treee05fd2566f4d7449249d033a80c2895a2112185c /Lib/json
parente580f5c55af033ee3d1e6d7b841fe3d144a91ae5 (diff)
downloadcpython-e4ca8156ef146174c64d537d9fa07a880231e699.zip
cpython-e4ca8156ef146174c64d537d9fa07a880231e699.tar.gz
cpython-e4ca8156ef146174c64d537d9fa07a880231e699.tar.bz2
Merged revisions 62805,62811,62841-62842,62848-62849,62853-62854 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r62805 | christian.heimes | 2008-05-07 01:59:53 +0200 (Wed, 07 May 2008) | 1 line Re-added getbuildinfo.c solution item ........ r62811 | benjamin.peterson | 2008-05-07 04:23:43 +0200 (Wed, 07 May 2008) | 2 lines update .bzrignore ........ r62841 | christian.heimes | 2008-05-08 00:54:17 +0200 (Thu, 08 May 2008) | 1 line Replace more float hacks with correct math functions ........ r62842 | benjamin.peterson | 2008-05-08 01:11:54 +0200 (Thu, 08 May 2008) | 2 lines Practice EAFP, and revert 62787 ........ r62848 | raymond.hettinger | 2008-05-08 06:35:20 +0200 (Thu, 08 May 2008) | 1 line Frozensets do not benefit from autoconversion. ........ r62849 | raymond.hettinger | 2008-05-08 06:36:12 +0200 (Thu, 08 May 2008) | 1 line The __all__ variable forgot to expose the gcd() function. ........ r62853 | raymond.hettinger | 2008-05-08 09:23:30 +0200 (Thu, 08 May 2008) | 1 line Fix-up the enumerate type example and move it to the end. ........ r62854 | ronald.oussoren | 2008-05-08 12:34:39 +0200 (Thu, 08 May 2008) | 3 lines Fix for issue 1770190: platform.mac_ver() now returns the right version on OSX 10.4.10 ........
Diffstat (limited to 'Lib/json')
-rw-r--r--Lib/json/encoder.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py
index 4cb3660..fa744c9 100644
--- a/Lib/json/encoder.py
+++ b/Lib/json/encoder.py
@@ -2,6 +2,7 @@
"""
import re
+import math
try:
from _json import encode_basestring_ascii as c_encode_basestring_ascii
@@ -25,20 +26,19 @@ ESCAPE_DCT = {
for i in range(0x20):
ESCAPE_DCT.setdefault(chr(i), '\\u{0:04x}'.format(i))
-# Assume this produces an infinity on all machines (probably not guaranteed)
-INFINITY = float('1e66666')
FLOAT_REPR = repr
def floatstr(o, allow_nan=True):
# Check for specials. Note that this type of test is processor- and/or
# platform-specific, so do tests which don't depend on the internals.
- if o != o:
+ if math.isnan(o):
text = 'NaN'
- elif o == INFINITY:
- text = 'Infinity'
- elif o == -INFINITY:
- text = '-Infinity'
+ elif math.isinf(o):
+ if math.copysign(1., o) == 1.:
+ text = 'Infinity'
+ else:
+ text = '-Infinity'
else:
return FLOAT_REPR(o)