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.
This commit is contained in:
3
README
3
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.
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user