mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #18023 -- Removed bundled simplejson.
And started the deprecation path for django.utils.simplejson. Thanks Alex Ogier, Clueless, and other contributors for their work on the patch.
This commit is contained in:
@@ -2,14 +2,17 @@
|
||||
Serialize data to/from JSON
|
||||
"""
|
||||
|
||||
# Avoid shadowing the standard library json module
|
||||
from __future__ import absolute_import
|
||||
|
||||
import datetime
|
||||
import decimal
|
||||
import json
|
||||
from StringIO import StringIO
|
||||
|
||||
from django.core.serializers.base import DeserializationError
|
||||
from django.core.serializers.python import Serializer as PythonSerializer
|
||||
from django.core.serializers.python import Deserializer as PythonDeserializer
|
||||
from django.utils import simplejson
|
||||
from django.utils.timezone import is_aware
|
||||
|
||||
class Serializer(PythonSerializer):
|
||||
@@ -19,10 +22,10 @@ class Serializer(PythonSerializer):
|
||||
internal_use_only = False
|
||||
|
||||
def end_serialization(self):
|
||||
if simplejson.__version__.split('.') >= ['2', '1', '3']:
|
||||
if json.__version__.split('.') >= ['2', '1', '3']:
|
||||
# Use JS strings to represent Python Decimal instances (ticket #16850)
|
||||
self.options.update({'use_decimal': False})
|
||||
simplejson.dump(self.objects, self.stream, cls=DjangoJSONEncoder, **self.options)
|
||||
json.dump(self.objects, self.stream, cls=DjangoJSONEncoder, **self.options)
|
||||
|
||||
def getvalue(self):
|
||||
if callable(getattr(self.stream, 'getvalue', None)):
|
||||
@@ -38,7 +41,7 @@ def Deserializer(stream_or_string, **options):
|
||||
else:
|
||||
stream = stream_or_string
|
||||
try:
|
||||
for obj in PythonDeserializer(simplejson.load(stream), **options):
|
||||
for obj in PythonDeserializer(json.load(stream), **options):
|
||||
yield obj
|
||||
except GeneratorExit:
|
||||
raise
|
||||
@@ -47,7 +50,7 @@ def Deserializer(stream_or_string, **options):
|
||||
raise DeserializationError(e)
|
||||
|
||||
|
||||
class DjangoJSONEncoder(simplejson.JSONEncoder):
|
||||
class DjangoJSONEncoder(json.JSONEncoder):
|
||||
"""
|
||||
JSONEncoder subclass that knows how to encode date/time and decimal types.
|
||||
"""
|
||||
|
||||
@@ -33,12 +33,13 @@ There are 65 url-safe characters: the 64 used by url-safe base64 and the ':'.
|
||||
These functions make use of all of them.
|
||||
"""
|
||||
import base64
|
||||
import json
|
||||
import time
|
||||
import zlib
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.utils import baseconv, simplejson
|
||||
from django.utils import baseconv
|
||||
from django.utils.crypto import constant_time_compare, salted_hmac
|
||||
from django.utils.encoding import force_unicode, smart_str
|
||||
from django.utils.importlib import import_module
|
||||
@@ -89,14 +90,14 @@ def get_cookie_signer(salt='django.core.signing.get_cookie_signer'):
|
||||
|
||||
class JSONSerializer(object):
|
||||
"""
|
||||
Simple wrapper around simplejson to be used in signing.dumps and
|
||||
Simple wrapper around json to be used in signing.dumps and
|
||||
signing.loads.
|
||||
"""
|
||||
def dumps(self, obj):
|
||||
return simplejson.dumps(obj, separators=(',', ':'))
|
||||
return json.dumps(obj, separators=(',', ':'))
|
||||
|
||||
def loads(self, data):
|
||||
return simplejson.loads(data)
|
||||
return json.loads(data)
|
||||
|
||||
|
||||
def dumps(obj, key=None, salt='django.core.signing', serializer=JSONSerializer, compress=False):
|
||||
|
||||
Reference in New Issue
Block a user