summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2011-01-17 01:28:48 +0000
committerBob Ippolito <bob@redivi.com>2011-01-17 01:28:48 +0000
commit87da37553cb14c06656e62d6bdc29128d7c5ca96 (patch)
tree0d726679368372303e71f88aaff3397aa053920d
parentdb980b6827239e264cf9626e2c4a7947d4f746f2 (diff)
downloadsimplejson-87da37553cb14c06656e62d6bdc29128d7c5ca96.tar.gz
http://code.google.com/p/simplejson/issues/detail?id=87
git-svn-id: http://simplejson.googlecode.com/svn/trunk@241 a4795897-2c25-0410-b006-0d3caba88fa1
-rw-r--r--CHANGES.txt4
-rw-r--r--docs/genindex.html2
-rw-r--r--docs/index.html2
-rw-r--r--docs/search.html2
-rw-r--r--docs/searchindex.json2
-rw-r--r--simplejson/__init__.py3
-rw-r--r--simplejson/tests/test_decimal.py31
7 files changed, 33 insertions, 13 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 10f8218..2824c42 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,7 +1,9 @@
-Version 2.1.3 released XXXX-XX-XX
+Version 2.1.3 released 2011-01-17
* Support the sort_keys option in C encoding speedups
http://code.google.com/p/simplejson/issues/detail?id=86
+* Allow use_decimal to work with dump()
+ http://code.google.com/p/simplejson/issues/detail?id=87
Version 2.1.2 released 2010-11-01
diff --git a/docs/genindex.html b/docs/genindex.html
index 8e0d78d..f504cef 100644
--- a/docs/genindex.html
+++ b/docs/genindex.html
@@ -129,7 +129,7 @@
</div>
<div class="footer">
&copy; Copyright 2008, Bob Ippolito.
- Last updated on Nov 05, 2010.
+ Last updated on Jan 17, 2011.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
</div>
</body>
diff --git a/docs/index.html b/docs/index.html
index 4177b78..0788e06 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -557,7 +557,7 @@ available. For example:</p>
</div>
<div class="footer">
&copy; Copyright 2008, Bob Ippolito.
- Last updated on Nov 05, 2010.
+ Last updated on Jan 17, 2011.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
</div>
</body>
diff --git a/docs/search.html b/docs/search.html
index 9c993d5..5569d68 100644
--- a/docs/search.html
+++ b/docs/search.html
@@ -74,7 +74,7 @@
</div>
<div class="footer">
&copy; Copyright 2008, Bob Ippolito.
- Last updated on Nov 05, 2010.
+ Last updated on Jan 17, 2011.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
</div>
</body>
diff --git a/docs/searchindex.json b/docs/searchindex.json
index e2e44c0..da5047c 100644
--- a/docs/searchindex.json
+++ b/docs/searchindex.json
@@ -1 +1 @@
-[["index"],["<tt class=\"docutils literal\"><span class=\"pre\">simplejson</span></tt> &#8212; JSON encoder and decoder"],{"represent":[0],"all":[0],"code":[0],"skip":[0],"interchang":[0],"signific":[0],"follow":[0],"compact":[0],"typeerror":[0],"tt":[0],"decim":[0],"0":[0],"rstrip":[0],"sens":[0],"spec":[0],"isinst":[0],"liter":[0],"everi":[0],"string":[0],"raw_decod":[0],"fals":[0],"jsonencod":[0],"level":[0],"list":[0],"iter":[0],"try":[0],"item":[0],"prevent":[0],"pass":[0],"compat":[0],"index":[0],"compar":[0],"neg":[],"current":[0],"version":[0],"new":[0],"method":[0],"item_separ":[0],"elimin":[0],"full":[0],"abov":[0],"valu":[0],"num_str":[0],"convert":[0],"produc":[0],"precis":[0],"prior":[0],"implement":[0],"control":[0],"modul":[0],"api":[0],"coercion":[0],"select":[0],"highli":[0],"from":[0],"would":[0],"to":[0],"call":[0],"6":[0],"type":[0],"more":[0],"sort":[0],"unescap":[0],"conveni":[0],"it":[0],"must":[0],"none":[0],"join":[0],"bigobject":[0],"work":[0],"skipkei":[0],"wors":[0],"can":[0],"def":[0],"overrid":[0],"stream":[0],"lightweight":[0],"accept":[0],"serial":[0],"object_pairs_hook":[0],"alwai":[],"end":[0],"newlin":[0],"anoth":[0],"1":[0],"instead":[0],"simpl":[0],"circular":[0],"fp":[0],"recogn":[0],"after":[0],"mai":[0],"such":[0],"data":[0],"demonstr":[0],"a":[0],"attempt":[0],"correspond":[0],"marshal":[0],"caus":[0],"jsonencoderforhtml":[0],"maintain":[0],"so":[0],"allow":[0],"order":[0],"becaus":[0],"hierarchi":[0],"paramet":[0],"write":[0],"better":[0],"yaml":[0],"html":[0],"then":[0],"them":[0],"return":[0],"thei":[0],"python":[0],"safe":[0],"dai":[0],"not":[0],"jsondecod":[0],"superset":[0],"name":[0],"anyth":[0],"edit":[0],"l":[0],"separ":[0],"getvalu":[0],"each":[0],"unicod":[0],"2j":[0],"mean":[0],"subset":[0],"chunk":[0],"ensur":[0],"expect":[0],"special":[0],"out":[0],"3rd":[0],"space":[0],"content":[0],"7":[0],"reader":[0],"print":[0],"earlier":[0],"infin":[0],"standard":[0],"reason":[0],"base":[0],"dictionari":[0],"element":[0],"org":[0],"basi":[0],"indent":[0],"g":[0],"could":[0],"place":[0],"outsid":[0],"regress":[0],"first":[0],"rang":[0],"arrai":[0],"number":[0],"echo":[0],"unlik":[0],"prioriti":[0],"given":[0],"reli":[0],"their":[0],"2":[0],"1j":[0],"shell":[0],"option":[0],"that":[0],"tool":[0],"specifi":[0],"pars":[0],"than":[0],"b":[0],"keyword":[0],"whenev":[0],"provid":[0],"structur":[0],"charact":[0],"r":[],"str":[0],"pre":[0],"encode_complex":[0],"argument":[0],"have":[0],"null":[0],"equival":[0],"self":[0],"note":[0],"also":[0],"without":[0],"take":[0],"which":[0],"even":[0],"begin":[0],"unless":[0],"normal":[0],"object":[0],"most":[0],"getread":[0],"pair":[0],"class":[0],"m":[0],"doe":[0],"kw":[0],"determin":[0],"serializ":[0],"speedup":[0],"syntax":[0],"find":[0],"onli":[0],"explicitli":[0],"parse_float":[0],"pretti":[0],"with":[0],"solut":[0],"3":[0],"should":[0],"iterencod":[0],"dict":[0],"8":[0],"object_hook":[0],"get":[0],"familiar":[0],"stop":[0],"repr":[0],"nativ":[0],"fastest":[0],"key_separ":[0],"bar":[0],"baz":[0],"yield":[0],"contain":[0],"where":[0],"valid":[0],"set":[0],"dump":[0],"frame":[0],"datatyp":[0],"result":[0],"best":[0],"subject":[0],"infinit":[0],"extend":[0],"dict_separ":[0],"written":[0],"import":[0],"latin":[0],"kei":[0],"parse_const":[0],"javascript":[0],"extens":[0],"embed":[0],"addit":[0],"c":[0],"delimit":[0],"s":[0],"instanc":[0],"mani":[0],"ecma":[0],"load":[0],"and":[0],"simpli":[0],"cl":[0],"8212":[0],"rpc":[0],"getwrit":[0],"__complex__":[0],"json":[0],"much":[0],"interpret":[0],"basic":[0],"valueerror":[0],"imag":[0],"ani":[0],"understand":[0],"func":[],"input":[0],"sort_kei":[0],"those":[],"case":[],"x08ar":[0],"properti":[0],"n":[0],"will":[0],"defin":[0],"behavior":[0],"error":[0],"ordereddict":[0],"advantag":[0],"is":[0],"non":[],"kwarg":[0],"io":[0],"in":[0],"incom":[0],"ascii":[0],"if":[0],"u1234":[0],"perform":[0],"make":[0],"same":[0],"member":[0],"complex":[0],"decod":[0],"document":[0],"http":[0],"optim":[0],"nest":[0],"effect":[0],"rais":[0],"user":[0],"extern":[0],"chang":[0],"appropri":[0],"well":[0],"pickl":[0],"exampl":[0],"thi":[0],"the":[0],"protocol":[0],"mysocket":[0],"rest":[0],"allow_nan":[0],"as_complex":[0],"parse_int":[0],"expos":[0],"hint":[0],"except":[0],"other":[0],"4":[0],"els":[0],"real":[0],"msimplejson":[],"format":[0],"read":[0],"262":[0],"recurs":[0],"insert":[0],"like":[0],"specif":[0],"arbitrari":[0],"docutil":[0],"whitespac":[0],"integ":[0],"collect":[0],"t":[0],"output":[0],"encount":[0],"some":[0],"check_circular":[0],"pariti":[0],"superclass":[0],"guarante":[0],"5":[0],"librari":[0],"for":[0],"subclass":[0],"when":[0],"leav":[0],"foo":[0],"refer":[0],"be":[0],"usag":[0],"dct":[0],"by":[0],"on":[0],"obj":[0],"column":[0],"of":[0],"memori":[0],"o":[0],"splitlin":[0],"constructor":[0],"or":[0],"into":[0],"float":[0],"encod":[0],"wrap":[0],"your":[0],"span":[0],"complianc":[0],"support":[0],"there":[0],"transform":[0],"long":[0],"custom":[0],"avail":[0],"strict":[0],"compliant":[0],"overflowerror":[0],"function":[0],"simplejson":[0],"tupl":[0],"recommend":[0],"but":[0],"use_decim":[0],"translat":[0],"line":[0],"ha":[0],"true":[0],"notat":[0],"utf":[0],"consist":[0],"possibl":[0],"default":[0],"us":[0],"otherwis":[0],"ensure_ascii":[0],"uc":[0],"featur":[0],"ad":[0],"int":[0],"dure":[0],"parser":[0],"an":[0],"char":[0],"as":[0],"ar":[0],"at":[0],"file":[0],"inf":[0],"check":[0],"no":[0],"complexencod":[],"nan":[0],"invalid":[0],"codec":[0],"bool":[0],"rememb":[0],"test":[0],"you":[0],"deseri":[0],"repeat":[0],"stringio":[0],"e":[0],"extran":[0],"rule":[0],"u":[0],"escap":[0],"backward":[0]}] \ No newline at end of file
+[["index"],["<tt class=\"docutils literal\"><span class=\"pre\">simplejson</span></tt> &#8212; JSON encoder and decoder"],{"represent":[0],"all":[0],"code":[0],"skip":[0],"interchang":[0],"signific":[0],"follow":[0],"compact":[0],"typeerror":[0],"tt":[0],"decim":[0],"0":[0],"rstrip":[0],"sens":[0],"spec":[0],"isinst":[0],"liter":[0],"everi":[0],"string":[0],"raw_decod":[0],"fals":[0],"jsonencod":[0],"level":[0],"list":[0],"iter":[0],"try":[0],"item":[0],"prevent":[0],"pass":[0],"compat":[0],"index":[0],"compar":[0],"neg":[],"current":[0],"version":[0],"new":[0],"method":[0],"item_separ":[0],"elimin":[0],"full":[0],"behavior":[0],"valu":[0],"num_str":[0],"convert":[0],"precis":[0],"prior":[0],"implement":[0],"control":[0],"modul":[0],"api":[0],"coercion":[0],"select":[0],"highli":[0],"or":[0],"from":[0],"would":[0],"to":[0],"call":[0],"6":[0],"type":[0],"more":[0],"sort":[0],"unescap":[0],"it":[0],"must":[0],"none":[0],"join":[0],"bigobject":[0],"work":[0],"skipkei":[0],"wors":[0],"can":[0],"def":[0],"overrid":[0],"stream":[0],"lightweight":[0],"accept":[0],"serial":[0],"object_pairs_hook":[0],"alwai":[],"end":[0],"newlin":[0],"anoth":[0],"write":[0],"instead":[0],"simpl":[0],"circular":[0],"fp":[0],"recogn":[0],"earlier":[0],"mai":[0],"such":[0],"data":[0],"demonstr":[0],"a":[0],"attempt":[0],"correspond":[0],"element":[0],"caus":[0],"jsonencoderforhtml":[0],"maintain":[0],"so":[0],"allow":[0],"order":[0],"becaus":[0],"hierarchi":[0],"paramet":[0],"1":[0],"better":[0],"yaml":[0],"html":[0],"then":[0],"them":[0],"return":[0],"thei":[0],"python":[0],"safe":[0],"dai":[0],"not":[0],"jsondecod":[0],"superset":[0],"name":[0],"anyth":[0],"edit":[0],"l":[0],"separ":[0],"getvalu":[0],"each":[0],"unicod":[0],"2j":[0],"mean":[0],"subset":[0],"chunk":[0],"wrap":[0],"expect":[0],"special":[0],"out":[0],"3rd":[0],"space":[0],"content":[0],"7":[0],"reader":[0],"print":[0],"after":[0],"infin":[0],"standard":[0],"reason":[0],"base":[0],"dictionari":[0],"org":[0],"basi":[0],"indent":[0],"g":[0],"rule":[0],"could":[0],"place":[0],"outsid":[0],"regress":[0],"first":[0],"rang":[0],"arrai":[0],"number":[0],"echo":[0],"unlik":[0],"prioriti":[0],"given":[0],"compliant":[0],"their":[0],"2":[0],"conveni":[0],"shell":[0],"option":[0],"that":[0],"1j":[0],"tool":[0],"specifi":[0],"pars":[0],"than":[0],"b":[0],"keyword":[0],"whenev":[0],"provid":[0],"structur":[0],"charact":[0],"r":[],"str":[0],"pre":[0],"encode_complex":[0],"ani":[0],"have":[0],"null":[0],"equival":[0],"self":[0],"note":[0],"also":[0],"exampl":[0],"take":[0],"which":[0],"codec":[0],"even":[0],"begin":[0],"unless":[0],"normal":[0],"object":[0],"most":[0],"getread":[0],"pair":[0],"class":[0],"marshal":[0],"nan":[0],"m":[0],"doe":[0],"kw":[0],"determin":[0],"serializ":[0],"speedup":[0],"syntax":[0],"find":[0],"onli":[0],"explicitli":[0],"parse_float":[0],"pretti":[0],"true":[0],"solut":[0],"3":[0],"should":[0],"iterencod":[0],"dict":[0],"8":[0],"object_hook":[0],"get":[0],"familiar":[0],"stop":[0],"repr":[0],"nativ":[0],"fastest":[0],"key_separ":[0],"bar":[0],"baz":[0],"yield":[0],"contain":[0],"where":[0],"set":[0],"dump":[0],"frame":[0],"datatyp":[0],"result":[0],"best":[0],"subject":[0],"infinit":[0],"extend":[0],"dict_separ":[0],"written":[0],"import":[0],"latin":[0],"kei":[0],"parse_const":[0],"javascript":[0],"extens":[0],"ensure_ascii":[0],"addit":[0],"c":[0],"delimit":[0],"s":[0],"instanc":[0],"mani":[0],"ecma":[0],"load":[0],"and":[0],"simpli":[0],"cl":[0],"8212":[0],"rpc":[0],"getwrit":[0],"__complex__":[0],"json":[0],"much":[0],"interpret":[0],"basic":[0],"valueerror":[0],"imag":[0],"argument":[0],"understand":[0],"func":[],"input":[0],"sort_kei":[0],"those":[],"case":[],"x08ar":[0],"properti":[0],"n":[0],"will":[0],"defin":[0],"abov":[0],"error":[0],"ordereddict":[0],"advantag":[0],"is":[0],"non":[],"kwarg":[0],"io":[0],"in":[0],"incom":[0],"ascii":[0],"if":[0],"u1234":[0],"perform":[0],"make":[0],"same":[0],"member":[0],"complex":[0],"decod":[0],"document":[0],"http":[0],"optim":[0],"nest":[0],"effect":[0],"rais":[0],"user":[0],"extern":[0],"chang":[0],"appropri":[0],"well":[0],"pickl":[0],"without":[0],"thi":[0],"the":[0],"protocol":[0],"mysocket":[0],"rest":[0],"allow_nan":[0],"as_complex":[0],"parse_int":[0],"expos":[0],"hint":[0],"except":[0],"other":[0],"4":[0],"els":[0],"real":[0],"msimplejson":[],"format":[0],"read":[0],"262":[0],"recurs":[0],"insert":[0],"like":[0],"specif":[0],"arbitrari":[0],"docutil":[0],"whitespac":[0],"integ":[0],"collect":[0],"t":[0],"output":[0],"encount":[0],"some":[0],"check_circular":[0],"pariti":[0],"superclass":[0],"guarante":[0],"librari":[0],"for":[0],"subclass":[0],"leav":[0],"foo":[0],"refer":[0],"be":[0],"usag":[0],"dct":[0],"by":[0],"on":[0],"obj":[0],"column":[0],"of":[0],"memori":[0],"o":[0],"splitlin":[0],"constructor":[0],"produc":[0],"into":[0],"float":[0],"encod":[0],"ensur":[0],"bool":[0],"your":[0],"span":[0],"complianc":[0],"support":[0],"there":[0],"transform":[0],"long":[0],"custom":[0],"avail":[0],"strict":[0],"reli":[0],"overflowerror":[0],"function":[0],"simplejson":[0],"tupl":[0],"recommend":[0],"but":[0],"use_decim":[0],"translat":[0],"line":[0],"ha":[0],"with":[0],"notat":[0],"utf":[0],"consist":[0],"possibl":[0],"default":[0],"us":[0],"otherwis":[0],"embed":[0],"uc":[0],"featur":[0],"ad":[0],"int":[0],"dure":[0],"parser":[0],"an":[0],"char":[0],"as":[0],"ar":[0],"at":[0],"file":[0],"inf":[0],"check":[0],"no":[0],"complexencod":[],"when":[0],"invalid":[0],"valid":[0],"5":[0],"rememb":[0],"test":[0],"you":[0],"deseri":[0],"repeat":[0],"stringio":[0],"e":[0],"extran":[0],"u":[0],"escap":[0],"backward":[0]}] \ No newline at end of file
diff --git a/simplejson/__init__.py b/simplejson/__init__.py
index 81528a5..c36be23 100644
--- a/simplejson/__init__.py
+++ b/simplejson/__init__.py
@@ -191,7 +191,8 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
if (not skipkeys and ensure_ascii and
check_circular and allow_nan and
cls is None and indent is None and separators is None and
- encoding == 'utf-8' and default is None and not kw):
+ encoding == 'utf-8' and default is None and not use_decimal
+ and not kw):
iterable = _default_encoder.iterencode(obj)
else:
if cls is None:
diff --git a/simplejson/tests/test_decimal.py b/simplejson/tests/test_decimal.py
index a694c7e..6b4b8f3 100644
--- a/simplejson/tests/test_decimal.py
+++ b/simplejson/tests/test_decimal.py
@@ -1,33 +1,50 @@
from decimal import Decimal
from unittest import TestCase
+from StringIO import StringIO
import simplejson as json
class TestDecimal(TestCase):
NUMS = "1.0", "10.00", "1.1", "1234567890.1234567890", "500"
+ def dumps(self, obj, **kw):
+ sio = StringIO()
+ json.dump(obj, sio, **kw)
+ res = json.dumps(obj, **kw)
+ self.assertEquals(res, sio.getvalue())
+ return res
+
+ def loads(self, s, **kw):
+ sio = StringIO(s)
+ res = json.loads(s, **kw)
+ self.assertEquals(res, json.load(sio, **kw))
+ return res
+
def test_decimal_encode(self):
for d in map(Decimal, self.NUMS):
- self.assertEquals(json.dumps(d, use_decimal=True), str(d))
+ self.assertEquals(self.dumps(d, use_decimal=True), str(d))
def test_decimal_decode(self):
for s in self.NUMS:
- self.assertEquals(json.loads(s, parse_float=Decimal), Decimal(s))
+ self.assertEquals(self.loads(s, parse_float=Decimal), Decimal(s))
def test_decimal_roundtrip(self):
for d in map(Decimal, self.NUMS):
# The type might not be the same (int and Decimal) but they
# should still compare equal.
self.assertEquals(
- json.loads(
- json.dumps(d, use_decimal=True), parse_float=Decimal),
+ self.loads(
+ self.dumps(d, use_decimal=True), parse_float=Decimal),
d)
self.assertEquals(
- json.loads(
- json.dumps([d], use_decimal=True), parse_float=Decimal),
+ self.loads(
+ self.dumps([d], use_decimal=True), parse_float=Decimal),
[d])
def test_decimal_defaults(self):
d = Decimal(1)
+ sio = StringIO()
# use_decimal=False is the default
self.assertRaises(TypeError, json.dumps, d, use_decimal=False)
- self.assertRaises(TypeError, json.dumps, d) \ No newline at end of file
+ self.assertRaises(TypeError, json.dumps, d)
+ self.assertRaises(TypeError, json.dump, d, sio, use_decimal=False)
+ self.assertRaises(TypeError, json.dump, d, sio) \ No newline at end of file