simplejson correctly serializes Decimal() objects now (see
http://code.google.com/p/simplejson/issues/detail?id=34)
TurboJson should also.
Unfortunately, it is not the default behavior (an option
use_decimal=True) must be passed. (The author of simplejson seems to
contend that it was never broken, but regardless: clearly representing
Decimal('2.2') as 2.2 is correct and as 2.20000000001 is incorrect).
I'm requesting someone fix up TurboJson to use_decimal. (I don't know
if a ticket need to be opened and assigned, etc, but this would be nice
for TurboGears).
My changes to TurboJson include removing "jsonify_decimal()":
========================================
diff -u -r TurboJson-1.2.1/turbojson/jsonify.py
TurboJson-1.2.1.1kb/turbojson/jsonify.py
--- TurboJson-1.2.1/turbojson/jsonify.py 2008-08-24
14:58:55.000000000 -0400
+++ TurboJson-1.2.1.1kb/turbojson/jsonify.py 2010-06-21
07:09:59.000000000 -0400
@@ -37,11 +37,6 @@
"""JSONify datetime and date objects."""
return str(obj)
[email protected]("isinstance(obj, decimal.Decimal)", prio=-1)
-def jsonify_decimal(obj):
- """JSONify decimal objects."""
- return float(obj)
-
@jsonify.when("hasattr(obj, '__json__')", prio=-1)
def jsonify_explicit(obj):
"""JSONify objects with explicit JSONification method."""
========================================
And updating setup.py:
========================================
diff -u -r TurboJson-1.2.1/setup.py TurboJson-1.2.1.1kb/setup.py
--- TurboJson-1.2.1/setup.py 2008-08-24 14:58:55.000000000 -0400
+++ TurboJson-1.2.1.1kb/setup.py 2010-06-21 07:08:28.000000000 -0400
@@ -4,7 +4,7 @@
setup(
name = 'TurboJson',
- version = '1.2.1',
+ version = '1.2.1.1',
description = 'Python template plugin that supports JSON',
author = 'Elvelind Grandin',
author_email = '[email protected]',
@@ -19,7 +19,7 @@
],
install_requires = [
'PEAK-Rules >= 0.5a1.dev-r2555',
- 'simplejson >= 1.9.1',
+ 'simplejson >= 2.1.1',
'prioritized_methods >= 0.2'
],
zip_safe = True,
========================================
Additionally, I've put the required parameter in the app_cfg.py for the
Turbogears project, but there is probably a better place for it (like
inside TurboJson):
Line added to app_cfg.py:
base_config['buffet.template_options'] = {'json.use_decimal':True}
Thanks to whoever may pick this up and make these few changes.
Kent
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en.