From 21ad8ea6f2cc927bd1eddf0a2014a3fde6b1d0a1 Mon Sep 17 00:00:00 2001 From: Jonathan LaCour Date: Wed, 29 Sep 2010 00:05:04 -0400 Subject: [PATCH] Removing requirement for simplejson and using Python 2.6 built-in JSON if available, otherwise we fallback to simplejson. Improved the default jsonification rule for datetime and date objects. --- README | 3 --- pecan/jsonify.py | 8 ++++++-- setup.py | 1 - 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README b/README index e1f578c..ecc1074 100644 --- a/README +++ b/README @@ -6,7 +6,4 @@ TODO * Switch "hooks" over to Context Managers. - * Remove requirement for simplejson, since we should be using - Python's built-in JSON. - * JSONify dates as isoformat strings by default. \ No newline at end of file diff --git a/pecan/jsonify.py b/pecan/jsonify.py index 128e3bb..1b6077c 100644 --- a/pecan/jsonify.py +++ b/pecan/jsonify.py @@ -1,4 +1,8 @@ -from simplejson import JSONEncoder, dumps +try: + from json import JSONEncoder, dumps +except ImportError: + from simplejson import JSONEncoder, dumps + from datetime import datetime, date from decimal import Decimal from webob.multidict import MultiDict @@ -28,7 +32,7 @@ class BaseEncoder(JSONEncoder): if hasattr(obj, '__json__') and callable(obj.__json__): return obj.__json__() elif isinstance(obj, (date, datetime)): - return str(obj) + return obj.isoformat() elif isinstance(obj, Decimal): return float(obj) elif self.is_saobject(obj): diff --git a/setup.py b/setup.py index 3f738e3..a6330f7 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,6 @@ setup( zip_safe = True, install_requires=[ "WebOb >= 0.9.8", - "simplejson >= 2.0.9", "simplegeneric >= 0.7", "Genshi >= 0.6", "Kajiki >= 0.2.2",