Ticket #18023: use_json_over_simplejson.diff

File use_json_over_simplejson.diff, 16.2 KB (added by Alex Ogier, 13 years ago)
  • django/contrib/formtools/wizard/storage/cookie.py

    diff --git a/django/contrib/formtools/wizard/storage/cookie.py b/django/contrib/formtools/wizard/storage/cookie.py
    index d1776de..e803610 100644
    a b  
     1import json
     2
    13from django.core.exceptions import SuspiciousOperation
    24from django.core.signing import BadSignature
    3 from django.utils import simplejson as json
    45
    56from django.contrib.formtools.wizard import storage
    67
  • django/contrib/gis/geometry/test_data.py

    diff --git a/django/contrib/gis/geometry/test_data.py b/django/contrib/gis/geometry/test_data.py
    index 4e07348..f927402 100644
    a b This module has the mock object definitions used to hold reference geometry  
    33for the GEOS and GDAL tests.
    44"""
    55import gzip
     6import json
    67import os
    78
    89from django.contrib import gis
    9 from django.utils import simplejson
    1010
    1111
    1212# This global used to store reference geometry data.
    class TestDataMixin(object):  
    100100        if GEOMETRIES is None:
    101101            # Load up the test geometry data from fixture into global.
    102102            gzf = gzip.GzipFile(os.path.join(TEST_DATA, 'geometries.json.gz'))
    103             geometries = simplejson.loads(gzf.read())
     103            geometries = json.loads(gzf.read())
    104104            GEOMETRIES = TestGeomSet(**strconvert(geometries))
    105105        return GEOMETRIES
  • django/contrib/messages/storage/cookie.py

    diff --git a/django/contrib/messages/storage/cookie.py b/django/contrib/messages/storage/cookie.py
    index c45dff4..0762005 100644
    a b  
     1import json
     2
    13from django.conf import settings
    24from django.contrib.messages.storage.base import BaseStorage, Message
    35from django.http import SimpleCookie
    4 from django.utils import simplejson as json
    56from django.utils.crypto import salted_hmac, constant_time_compare
    67
    78
  • django/contrib/messages/tests/cookie.py

    diff --git a/django/contrib/messages/tests/cookie.py b/django/contrib/messages/tests/cookie.py
    index 30aa6b5..2aef1db 100644
    a b  
     1import json
     2
    13from django.contrib.messages import constants
    24from django.contrib.messages.tests.base import BaseTest
    35from django.contrib.messages.storage.cookie import (CookieStorage,
    46    MessageEncoder, MessageDecoder)
    57from django.contrib.messages.storage.base import Message
    68from django.test.utils import override_settings
    7 from django.utils import simplejson as json
    89
    910
    1011def set_cookie_data(storage, messages, invalid=False, encode_empty=False):
  • django/core/serializers/json.py

    diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
    index 91af84e..5d71797 100644
    a b  
    11"""
    22Serialize data to/from JSON
    33"""
     4# We shadow the standard library json module
     5from __future__ import absolute_import
    46
    57import datetime
    68import decimal
     9import json
    710from StringIO import StringIO
    811
    912from django.core.serializers.base import DeserializationError
    1013from django.core.serializers.python import Serializer as PythonSerializer
    1114from django.core.serializers.python import Deserializer as PythonDeserializer
    12 from django.utils import simplejson
    1315from django.utils.timezone import is_aware
    1416
    1517class Serializer(PythonSerializer):
    class Serializer(PythonSerializer):  
    1921    internal_use_only = False
    2022
    2123    def end_serialization(self):
    22         if simplejson.__version__.split('.') >= ['2', '1', '3']:
     24        if json.__version__.split('.') >= ['2', '1', '3']:
    2325            # Use JS strings to represent Python Decimal instances (ticket #16850)
    2426            self.options.update({'use_decimal': False})
    25         simplejson.dump(self.objects, self.stream, cls=DjangoJSONEncoder, **self.options)
     27        json.dump(self.objects, self.stream, cls=DjangoJSONEncoder, **self.options)
    2628
    2729    def getvalue(self):
    2830        if callable(getattr(self.stream, 'getvalue', None)):
    def Deserializer(stream_or_string, **options):  
    3840    else:
    3941        stream = stream_or_string
    4042    try:
    41         for obj in PythonDeserializer(simplejson.load(stream), **options):
     43        for obj in PythonDeserializer(json.load(stream), **options):
    4244            yield obj
    4345    except GeneratorExit:
    4446        raise
    def Deserializer(stream_or_string, **options):  
    4749        raise DeserializationError(e)
    4850
    4951
    50 class DjangoJSONEncoder(simplejson.JSONEncoder):
     52class DjangoJSONEncoder(json.JSONEncoder):
    5153    """
    5254    JSONEncoder subclass that knows how to encode date/time and decimal types.
    5355    """
  • django/core/signing.py

    diff --git a/django/core/signing.py b/django/core/signing.py
    index 7f92d61..f2c79de 100644
    a b There are 65 url-safe characters: the 64 used by url-safe base64 and the ':'.  
    3333These functions make use of all of them.
    3434"""
    3535import base64
     36import json
    3637import time
    3738import zlib
    3839
    3940from django.conf import settings
    4041from django.core.exceptions import ImproperlyConfigured
    41 from django.utils import baseconv, simplejson
     42from django.utils import baseconv
    4243from django.utils.crypto import constant_time_compare, salted_hmac
    4344from django.utils.encoding import force_unicode, smart_str
    4445from django.utils.importlib import import_module
    def get_cookie_signer(salt='django.core.signing.get_cookie_signer'):  
    8990
    9091class JSONSerializer(object):
    9192    """
    92     Simple wrapper around simplejson to be used in signing.dumps and
     93    Simple wrapper around json to be used in signing.dumps and
    9394    signing.loads.
    9495    """
    9596    def dumps(self, obj):
    96         return simplejson.dumps(obj, separators=(',', ':'))
     97        return json.dumps(obj, separators=(',', ':'))
    9798
    9899    def loads(self, data):
    99         return simplejson.loads(data)
     100        return json.loads(data)
    100101
    101102
    102103def dumps(obj, key=None, salt='django.core.signing', serializer=JSONSerializer, compress=False):
  • django/test/testcases.py

    diff --git a/django/test/testcases.py b/django/test/testcases.py
    index b5e1dc0..8f1068f 100644
    a b  
    11from __future__ import with_statement
    22
    33import difflib
     4import json
    45import os
    56import re
    67import sys
    from django.test.signals import template_rendered  
    3536from django.test.utils import (get_warnings_state, restore_warnings_state,
    3637    override_settings)
    3738from django.test.utils import ContextList
    38 from django.utils import simplejson, unittest as ut2
     39from django.utils import unittest as ut2
    3940from django.utils.encoding import smart_str, force_unicode
    4041from django.utils.unittest.util import safe_repr
    4142from django.views.static import serve
    class OutputChecker(doctest.OutputChecker):  
    191192        """
    192193        want, got = self._strip_quotes(want, got)
    193194        try:
    194             want_json = simplejson.loads(want)
    195             got_json = simplejson.loads(got)
     195            want_json = json.loads(want)
     196            got_json = json.loads(got)
    196197        except Exception:
    197198            return False
    198199        return want_json == got_json
  • docs/_ext/djangodocs.py

    diff --git a/docs/_ext/djangodocs.py b/docs/_ext/djangodocs.py
    index 3cf00a3..a2e916b 100644
    a b except ImportError:  
    1111    try:
    1212        import simplejson as json
    1313    except ImportError:
    14         try:
    15             from django.utils import simplejson as json
    16         except ImportError:
    17             json = None
     14        json = None
    1815
    1916from sphinx import addnodes, roles, __version__ as sphinx_ver
    2017from sphinx.builders.html import StandaloneHTMLBuilder
  • tests/modeltests/field_subclassing/fields.py

    diff --git a/tests/modeltests/field_subclassing/fields.py b/tests/modeltests/field_subclassing/fields.py
    index f744706..4d809ba 100644
    a b  
     1import json
     2
    13from django.db import models
    2 from django.utils import simplejson as json
    34from django.utils.encoding import force_unicode
    45
    56
  • tests/modeltests/serializers/tests.py

    diff --git a/tests/modeltests/serializers/tests.py b/tests/modeltests/serializers/tests.py
    index 309a83e..c92ee61 100644
    a b  
    33from __future__ import with_statement, absolute_import
    44
    55# -*- coding: utf-8 -*-
     6import json
    67from datetime import datetime
    78from xml.dom import minidom
    89from StringIO import StringIO
    from django.conf import settings  
    1112from django.core import serializers
    1213from django.db import transaction, connection
    1314from django.test import TestCase, TransactionTestCase, Approximate
    14 from django.utils import simplejson, unittest
     15from django.utils import unittest
    1516
    1617from .models import (Category, Author, Article, AuthorProfile, Actor, Movie,
    1718    Score, Player, Team)
    class JsonSerializerTestCase(SerializersTestBase, TestCase):  
    356357    @staticmethod
    357358    def _validate_output(serial_str):
    358359        try:
    359             simplejson.loads(serial_str)
     360            json.loads(serial_str)
    360361        except Exception:
    361362            return False
    362363        else:
    class JsonSerializerTestCase(SerializersTestBase, TestCase):  
    365366    @staticmethod
    366367    def _get_pk_values(serial_str):
    367368        ret_list = []
    368         serial_list = simplejson.loads(serial_str)
     369        serial_list = json.loads(serial_str)
    369370        for obj_dict in serial_list:
    370371            ret_list.append(obj_dict["pk"])
    371372        return ret_list
    class JsonSerializerTestCase(SerializersTestBase, TestCase):  
    373374    @staticmethod
    374375    def _get_field_values(serial_str, field_name):
    375376        ret_list = []
    376         serial_list = simplejson.loads(serial_str)
     377        serial_list = json.loads(serial_str)
    377378        for obj_dict in serial_list:
    378379            if field_name in obj_dict["fields"]:
    379380                ret_list.append(obj_dict["fields"][field_name])
  • tests/regressiontests/file_uploads/tests.py

    diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py
    index ffa2017..b6191ba 100644
    a b from __future__ import absolute_import  
    55import base64
    66import errno
    77import hashlib
     8import json
    89import os
    910import shutil
    1011from StringIO import StringIO
    from django.core.files import temp as tempfile  
    1314from django.core.files.uploadedfile import SimpleUploadedFile
    1415from django.http.multipartparser import MultiPartParser
    1516from django.test import TestCase, client
    16 from django.utils import simplejson, unittest
     17from django.utils import unittest
    1718
    1819from . import uploadhandler
    1920from .models import FileModel, temp_storage, UPLOAD_TO
    class FileUploadTests(TestCase):  
    7879            'wsgi.input':     client.FakePayload(payload),
    7980        }
    8081        response = self.client.request(**r)
    81         received = simplejson.loads(response.content)
     82        received = json.loads(response.content)
    8283
    8384        self.assertEqual(received['file'], test_string)
    8485
    class FileUploadTests(TestCase):  
    150151        response = self.client.request(**r)
    151152
    152153        # The filenames should have been sanitized by the time it got to the view.
    153         recieved = simplejson.loads(response.content)
     154        recieved = json.loads(response.content)
    154155        for i, name in enumerate(scary_file_names):
    155156            got = recieved["file%s" % i]
    156157            self.assertEqual(got, "hax0rd.txt")
    class FileUploadTests(TestCase):  
    174175            'REQUEST_METHOD': 'POST',
    175176            'wsgi.input':     client.FakePayload(payload),
    176177        }
    177         got = simplejson.loads(self.client.request(**r).content)
     178        got = json.loads(self.client.request(**r).content)
    178179        self.assertTrue(len(got['file']) < 256, "Got a long file name (%s characters)." % len(got['file']))
    179180
    180181    def test_truncated_multipart_handled_gracefully(self):
    class FileUploadTests(TestCase):  
    200201            'REQUEST_METHOD': 'POST',
    201202            'wsgi.input': client.FakePayload(payload),
    202203        }
    203         got = simplejson.loads(self.client.request(**r).content)
     204        got = json.loads(self.client.request(**r).content)
    204205        self.assertEquals(got, {})
    205206
    206207    def test_empty_multipart_handled_gracefully(self):
    class FileUploadTests(TestCase):  
    215216            'REQUEST_METHOD': 'POST',
    216217            'wsgi.input': client.FakePayload(''),
    217218        }
    218         got = simplejson.loads(self.client.request(**r).content)
     219        got = json.loads(self.client.request(**r).content)
    219220        self.assertEquals(got, {})
    220221
    221222    def test_custom_upload_handler(self):
    class FileUploadTests(TestCase):  
    231232
    232233        # Small file posting should work.
    233234        response = self.client.post('/file_uploads/quota/', {'f': smallfile})
    234         got = simplejson.loads(response.content)
     235        got = json.loads(response.content)
    235236        self.assertTrue('f' in got)
    236237
    237238        # Large files don't go through.
    238239        response = self.client.post("/file_uploads/quota/", {'f': bigfile})
    239         got = simplejson.loads(response.content)
     240        got = json.loads(response.content)
    240241        self.assertTrue('f' not in got)
    241242
    242243    def test_broken_custom_upload_handler(self):
    class FileUploadTests(TestCase):  
    274275            'field5': u'test7',
    275276            'file2': (file2, file2a)
    276277        })
    277         got = simplejson.loads(response.content)
     278        got = json.loads(response.content)
    278279
    279280        self.assertEqual(got.get('file1'), 1)
    280281        self.assertEqual(got.get('file2'), 2)
  • tests/regressiontests/file_uploads/views.py

    diff --git a/tests/regressiontests/file_uploads/views.py b/tests/regressiontests/file_uploads/views.py
    index 9fd1a8d..ae6842d 100644
    a b  
    11from __future__ import absolute_import
    22
    33import hashlib
     4import json
    45import os
    56
    67from django.core.files.uploadedfile import UploadedFile
    78from django.http import HttpResponse, HttpResponseServerError
    8 from django.utils import simplejson
    99
    1010from .models import FileModel, UPLOAD_TO
    1111from .tests import UNICODE_FILENAME
    def file_upload_echo(request):  
    8888    Simple view to echo back info about uploaded files for tests.
    8989    """
    9090    r = dict([(k, f.name) for k, f in request.FILES.items()])
    91     return HttpResponse(simplejson.dumps(r))
     91    return HttpResponse(json.dumps(r))
    9292
    9393def file_upload_echo_content(request):
    9494    """
    9595    Simple view to echo back the content of uploaded files for tests.
    9696    """
    9797    r = dict([(k, f.read()) for k, f in request.FILES.items()])
    98     return HttpResponse(simplejson.dumps(r))
     98    return HttpResponse(json.dumps(r))
    9999
    100100def file_upload_quota(request):
    101101    """
    def file_upload_getlist_count(request):  
    120120
    121121    for key in request.FILES.keys():
    122122        file_counts[key] = len(request.FILES.getlist(key))
    123     return HttpResponse(simplejson.dumps(file_counts))
     123    return HttpResponse(json.dumps(file_counts))
    124124
    125125def file_upload_errors(request):
    126126    request.upload_handlers.insert(0, ErroringUploadHandler())
  • tests/regressiontests/test_client_regress/views.py

    diff --git a/tests/regressiontests/test_client_regress/views.py b/tests/regressiontests/test_client_regress/views.py
    index ebb68c4..ffd4166 100644
    a b  
     1import json
    12import warnings
    23
    34from django.conf import settings
    from django.contrib.auth.decorators import login_required  
    56from django.http import HttpResponse, HttpResponseRedirect
    67from django.core.exceptions import SuspiciousOperation
    78from django.shortcuts import render_to_response
    8 from django.utils import simplejson
    99from django.utils.encoding import smart_str
    1010from django.core.serializers.json import DjangoJSONEncoder
    1111from django.test.client import CONTENT_TYPE_RE
    def return_json_file(request):  
    8181        charset = settings.DEFAULT_CHARSET
    8282
    8383    # This just checks that the uploaded data is JSON
    84     obj_dict = simplejson.loads(request.body.decode(charset))
    85     obj_json = simplejson.dumps(obj_dict, encoding=charset,
     84    obj_dict = json.loads(request.body.decode(charset))
     85    obj_json = json.dumps(obj_dict, encoding=charset,
    8686                                cls=DjangoJSONEncoder,
    8787                                ensure_ascii=False)
    8888    response = HttpResponse(smart_str(obj_json, encoding=charset), status=200,
Back to Top