mirror of
https://github.com/django/django.git
synced 2025-07-24 05:36:15 +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:
parent
ee0a7c741e
commit
cec6bd5a59
26 changed files with 105 additions and 1321 deletions
|
@ -1,20 +1,11 @@
|
|||
"""
|
||||
Sphinx plugins for Django documentation.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
|
||||
from docutils import nodes, transforms
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
try:
|
||||
import simplejson as json
|
||||
except ImportError:
|
||||
try:
|
||||
from django.utils import simplejson as json
|
||||
except ImportError:
|
||||
json = None
|
||||
|
||||
from sphinx import addnodes, roles, __version__ as sphinx_ver
|
||||
from sphinx.builders.html import StandaloneHTMLBuilder
|
||||
|
@ -210,9 +201,6 @@ class DjangoStandaloneHTMLBuilder(StandaloneHTMLBuilder):
|
|||
|
||||
def finish(self):
|
||||
super(DjangoStandaloneHTMLBuilder, self).finish()
|
||||
if json is None:
|
||||
self.warn("cannot create templatebuiltins.js due to missing simplejson dependency")
|
||||
return
|
||||
self.info(bold("writing templatebuiltins.js..."))
|
||||
xrefs = self.env.domaindata["std"]["objects"]
|
||||
templatebuiltins = {
|
||||
|
|
|
@ -268,6 +268,9 @@ these changes.
|
|||
See the :doc:`Django 1.5 release notes</releases/1.5>` for more details on
|
||||
these changes.
|
||||
|
||||
* The module ``django.utils.simplejson`` will be removed. The standard library
|
||||
provides :mod:`json` which should be used instead.
|
||||
|
||||
* The function ``django.utils.itercompat.product`` will be removed. The Python
|
||||
builtin version should be used instead.
|
||||
|
||||
|
|
|
@ -58,8 +58,17 @@ Backwards incompatible changes in 1.5
|
|||
Features deprecated in 1.5
|
||||
==========================
|
||||
|
||||
itercompat.product
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
``django.utils.simplejson``
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Since Django 1.5 drops support for Python 2.5, all supported versions of
|
||||
Python provide the :mod:`json` module in their standard library. This module
|
||||
is actually a version of ``simplejson`` distributed by Python, so Django no
|
||||
longer needs to provide a copy. Any use of :mod:`django.utils.simplejson` can
|
||||
be safely changed to :mod:`json`.
|
||||
|
||||
``itercompat.product``
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The :func:`~django.utils.itercompat.product` function has been deprecated. Use
|
||||
the builtin `itertools.product` instead.
|
||||
|
|
|
@ -501,8 +501,8 @@ different rendering behavior.
|
|||
|
||||
For example, a simple JSON mixin might look something like this::
|
||||
|
||||
import json
|
||||
from django import http
|
||||
from django.utils import simplejson as json
|
||||
|
||||
class JSONResponseMixin(object):
|
||||
def render_to_response(self, context):
|
||||
|
|
|
@ -143,15 +143,13 @@ Identifier Information
|
|||
========== ==============================================================
|
||||
``xml`` Serializes to and from a simple XML dialect.
|
||||
|
||||
``json`` Serializes to and from JSON_ (using a version of simplejson_
|
||||
bundled with Django).
|
||||
``json`` Serializes to and from JSON_.
|
||||
|
||||
``yaml`` Serializes to YAML (YAML Ain't a Markup Language). This
|
||||
serializer is only available if PyYAML_ is installed.
|
||||
========== ==============================================================
|
||||
|
||||
.. _json: http://json.org/
|
||||
.. _simplejson: http://undefined.org/python/#simplejson
|
||||
.. _PyYAML: http://www.pyyaml.org/
|
||||
|
||||
Notes for specific serialization formats
|
||||
|
@ -169,28 +167,21 @@ For example::
|
|||
json_serializer = serializers.get_serializer("json")()
|
||||
json_serializer.serialize(queryset, ensure_ascii=False, stream=response)
|
||||
|
||||
The Django source code includes the simplejson_ module. However, if you're
|
||||
using Python 2.6 or later (which includes a builtin version of the module), Django will
|
||||
use the builtin ``json`` module automatically. If you have a system installed
|
||||
version that includes the C-based speedup extension, or your system version is
|
||||
more recent than the version shipped with Django (currently, 2.0.7), the
|
||||
system version will be used instead of the version included with Django.
|
||||
|
||||
Be aware that if you're serializing using that module directly, not all Django
|
||||
output can be passed unmodified to simplejson. In particular, :ref:`lazy
|
||||
translation objects <lazy-translations>` need a `special encoder`_ written for
|
||||
them. Something like this will work::
|
||||
Be aware that not all Django output can be passed unmodified to :mod:`json`.
|
||||
In particular, :ref:`lazy translation objects <lazy-translations>` need a
|
||||
`special encoder`_ written for them. Something like this will work::
|
||||
|
||||
import json
|
||||
from django.utils.functional import Promise
|
||||
from django.utils.encoding import force_unicode
|
||||
|
||||
class LazyEncoder(simplejson.JSONEncoder):
|
||||
class LazyEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if isinstance(obj, Promise):
|
||||
return force_unicode(obj)
|
||||
return super(LazyEncoder, self).default(obj)
|
||||
|
||||
.. _special encoder: http://svn.red-bean.com/bob/simplejson/tags/simplejson-1.7/docs/index.html
|
||||
.. _special encoder: http://docs.python.org/library/json.html#encoders-and-decoders
|
||||
|
||||
.. _topics-serialization-natural-keys:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue