diff --git a/django/contrib/formtools/wizard/storage/cookie.py b/django/contrib/formtools/wizard/storage/cookie.py
index d1776de..e803610 100644
|
a
|
b
|
|
| | 1 | import json |
| | 2 | |
| 1 | 3 | from django.core.exceptions import SuspiciousOperation |
| 2 | 4 | from django.core.signing import BadSignature |
| 3 | | from django.utils import simplejson as json |
| 4 | 5 | |
| 5 | 6 | from django.contrib.formtools.wizard import storage |
| 6 | 7 | |
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
|
| 3 | 3 | for the GEOS and GDAL tests. |
| 4 | 4 | """ |
| 5 | 5 | import gzip |
| | 6 | import json |
| 6 | 7 | import os |
| 7 | 8 | |
| 8 | 9 | from django.contrib import gis |
| 9 | | from django.utils import simplejson |
| 10 | 10 | |
| 11 | 11 | |
| 12 | 12 | # This global used to store reference geometry data. |
| … |
… |
class TestDataMixin(object):
|
| 100 | 100 | if GEOMETRIES is None: |
| 101 | 101 | # Load up the test geometry data from fixture into global. |
| 102 | 102 | gzf = gzip.GzipFile(os.path.join(TEST_DATA, 'geometries.json.gz')) |
| 103 | | geometries = simplejson.loads(gzf.read()) |
| | 103 | geometries = json.loads(gzf.read()) |
| 104 | 104 | GEOMETRIES = TestGeomSet(**strconvert(geometries)) |
| 105 | 105 | return GEOMETRIES |
diff --git a/django/contrib/messages/storage/cookie.py b/django/contrib/messages/storage/cookie.py
index c45dff4..0762005 100644
|
a
|
b
|
|
| | 1 | import json |
| | 2 | |
| 1 | 3 | from django.conf import settings |
| 2 | 4 | from django.contrib.messages.storage.base import BaseStorage, Message |
| 3 | 5 | from django.http import SimpleCookie |
| 4 | | from django.utils import simplejson as json |
| 5 | 6 | from django.utils.crypto import salted_hmac, constant_time_compare |
| 6 | 7 | |
| 7 | 8 | |
diff --git a/django/contrib/messages/tests/cookie.py b/django/contrib/messages/tests/cookie.py
index 30aa6b5..2aef1db 100644
|
a
|
b
|
|
| | 1 | import json |
| | 2 | |
| 1 | 3 | from django.contrib.messages import constants |
| 2 | 4 | from django.contrib.messages.tests.base import BaseTest |
| 3 | 5 | from django.contrib.messages.storage.cookie import (CookieStorage, |
| 4 | 6 | MessageEncoder, MessageDecoder) |
| 5 | 7 | from django.contrib.messages.storage.base import Message |
| 6 | 8 | from django.test.utils import override_settings |
| 7 | | from django.utils import simplejson as json |
| 8 | 9 | |
| 9 | 10 | |
| 10 | 11 | def set_cookie_data(storage, messages, invalid=False, encode_empty=False): |
diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
index 91af84e..5d71797 100644
|
a
|
b
|
|
| 1 | 1 | """ |
| 2 | 2 | Serialize data to/from JSON |
| 3 | 3 | """ |
| | 4 | # We shadow the standard library json module |
| | 5 | from __future__ import absolute_import |
| 4 | 6 | |
| 5 | 7 | import datetime |
| 6 | 8 | import decimal |
| | 9 | import json |
| 7 | 10 | from StringIO import StringIO |
| 8 | 11 | |
| 9 | 12 | from django.core.serializers.base import DeserializationError |
| 10 | 13 | from django.core.serializers.python import Serializer as PythonSerializer |
| 11 | 14 | from django.core.serializers.python import Deserializer as PythonDeserializer |
| 12 | | from django.utils import simplejson |
| 13 | 15 | from django.utils.timezone import is_aware |
| 14 | 16 | |
| 15 | 17 | class Serializer(PythonSerializer): |
| … |
… |
class Serializer(PythonSerializer):
|
| 19 | 21 | internal_use_only = False |
| 20 | 22 | |
| 21 | 23 | def end_serialization(self): |
| 22 | | if simplejson.__version__.split('.') >= ['2', '1', '3']: |
| | 24 | if json.__version__.split('.') >= ['2', '1', '3']: |
| 23 | 25 | # Use JS strings to represent Python Decimal instances (ticket #16850) |
| 24 | 26 | 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) |
| 26 | 28 | |
| 27 | 29 | def getvalue(self): |
| 28 | 30 | if callable(getattr(self.stream, 'getvalue', None)): |
| … |
… |
def Deserializer(stream_or_string, **options):
|
| 38 | 40 | else: |
| 39 | 41 | stream = stream_or_string |
| 40 | 42 | try: |
| 41 | | for obj in PythonDeserializer(simplejson.load(stream), **options): |
| | 43 | for obj in PythonDeserializer(json.load(stream), **options): |
| 42 | 44 | yield obj |
| 43 | 45 | except GeneratorExit: |
| 44 | 46 | raise |
| … |
… |
def Deserializer(stream_or_string, **options):
|
| 47 | 49 | raise DeserializationError(e) |
| 48 | 50 | |
| 49 | 51 | |
| 50 | | class DjangoJSONEncoder(simplejson.JSONEncoder): |
| | 52 | class DjangoJSONEncoder(json.JSONEncoder): |
| 51 | 53 | """ |
| 52 | 54 | JSONEncoder subclass that knows how to encode date/time and decimal types. |
| 53 | 55 | """ |
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 ':'.
|
| 33 | 33 | These functions make use of all of them. |
| 34 | 34 | """ |
| 35 | 35 | import base64 |
| | 36 | import json |
| 36 | 37 | import time |
| 37 | 38 | import zlib |
| 38 | 39 | |
| 39 | 40 | from django.conf import settings |
| 40 | 41 | from django.core.exceptions import ImproperlyConfigured |
| 41 | | from django.utils import baseconv, simplejson |
| | 42 | from django.utils import baseconv |
| 42 | 43 | from django.utils.crypto import constant_time_compare, salted_hmac |
| 43 | 44 | from django.utils.encoding import force_unicode, smart_str |
| 44 | 45 | from django.utils.importlib import import_module |
| … |
… |
def get_cookie_signer(salt='django.core.signing.get_cookie_signer'):
|
| 89 | 90 | |
| 90 | 91 | class JSONSerializer(object): |
| 91 | 92 | """ |
| 92 | | Simple wrapper around simplejson to be used in signing.dumps and |
| | 93 | Simple wrapper around json to be used in signing.dumps and |
| 93 | 94 | signing.loads. |
| 94 | 95 | """ |
| 95 | 96 | def dumps(self, obj): |
| 96 | | return simplejson.dumps(obj, separators=(',', ':')) |
| | 97 | return json.dumps(obj, separators=(',', ':')) |
| 97 | 98 | |
| 98 | 99 | def loads(self, data): |
| 99 | | return simplejson.loads(data) |
| | 100 | return json.loads(data) |
| 100 | 101 | |
| 101 | 102 | |
| 102 | 103 | def dumps(obj, key=None, salt='django.core.signing', serializer=JSONSerializer, compress=False): |
diff --git a/django/test/testcases.py b/django/test/testcases.py
index b5e1dc0..8f1068f 100644
|
a
|
b
|
|
| 1 | 1 | from __future__ import with_statement |
| 2 | 2 | |
| 3 | 3 | import difflib |
| | 4 | import json |
| 4 | 5 | import os |
| 5 | 6 | import re |
| 6 | 7 | import sys |
| … |
… |
from django.test.signals import template_rendered
|
| 35 | 36 | from django.test.utils import (get_warnings_state, restore_warnings_state, |
| 36 | 37 | override_settings) |
| 37 | 38 | from django.test.utils import ContextList |
| 38 | | from django.utils import simplejson, unittest as ut2 |
| | 39 | from django.utils import unittest as ut2 |
| 39 | 40 | from django.utils.encoding import smart_str, force_unicode |
| 40 | 41 | from django.utils.unittest.util import safe_repr |
| 41 | 42 | from django.views.static import serve |
| … |
… |
class OutputChecker(doctest.OutputChecker):
|
| 191 | 192 | """ |
| 192 | 193 | want, got = self._strip_quotes(want, got) |
| 193 | 194 | 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) |
| 196 | 197 | except Exception: |
| 197 | 198 | return False |
| 198 | 199 | return want_json == got_json |
diff --git a/docs/_ext/djangodocs.py b/docs/_ext/djangodocs.py
index 3cf00a3..a2e916b 100644
|
a
|
b
|
except ImportError:
|
| 11 | 11 | try: |
| 12 | 12 | import simplejson as json |
| 13 | 13 | except ImportError: |
| 14 | | try: |
| 15 | | from django.utils import simplejson as json |
| 16 | | except ImportError: |
| 17 | | json = None |
| | 14 | json = None |
| 18 | 15 | |
| 19 | 16 | from sphinx import addnodes, roles, __version__ as sphinx_ver |
| 20 | 17 | from sphinx.builders.html import StandaloneHTMLBuilder |
diff --git a/tests/modeltests/field_subclassing/fields.py b/tests/modeltests/field_subclassing/fields.py
index f744706..4d809ba 100644
|
a
|
b
|
|
| | 1 | import json |
| | 2 | |
| 1 | 3 | from django.db import models |
| 2 | | from django.utils import simplejson as json |
| 3 | 4 | from django.utils.encoding import force_unicode |
| 4 | 5 | |
| 5 | 6 | |
diff --git a/tests/modeltests/serializers/tests.py b/tests/modeltests/serializers/tests.py
index 309a83e..c92ee61 100644
|
a
|
b
|
|
| 3 | 3 | from __future__ import with_statement, absolute_import |
| 4 | 4 | |
| 5 | 5 | # -*- coding: utf-8 -*- |
| | 6 | import json |
| 6 | 7 | from datetime import datetime |
| 7 | 8 | from xml.dom import minidom |
| 8 | 9 | from StringIO import StringIO |
| … |
… |
from django.conf import settings
|
| 11 | 12 | from django.core import serializers |
| 12 | 13 | from django.db import transaction, connection |
| 13 | 14 | from django.test import TestCase, TransactionTestCase, Approximate |
| 14 | | from django.utils import simplejson, unittest |
| | 15 | from django.utils import unittest |
| 15 | 16 | |
| 16 | 17 | from .models import (Category, Author, Article, AuthorProfile, Actor, Movie, |
| 17 | 18 | Score, Player, Team) |
| … |
… |
class JsonSerializerTestCase(SerializersTestBase, TestCase):
|
| 356 | 357 | @staticmethod |
| 357 | 358 | def _validate_output(serial_str): |
| 358 | 359 | try: |
| 359 | | simplejson.loads(serial_str) |
| | 360 | json.loads(serial_str) |
| 360 | 361 | except Exception: |
| 361 | 362 | return False |
| 362 | 363 | else: |
| … |
… |
class JsonSerializerTestCase(SerializersTestBase, TestCase):
|
| 365 | 366 | @staticmethod |
| 366 | 367 | def _get_pk_values(serial_str): |
| 367 | 368 | ret_list = [] |
| 368 | | serial_list = simplejson.loads(serial_str) |
| | 369 | serial_list = json.loads(serial_str) |
| 369 | 370 | for obj_dict in serial_list: |
| 370 | 371 | ret_list.append(obj_dict["pk"]) |
| 371 | 372 | return ret_list |
| … |
… |
class JsonSerializerTestCase(SerializersTestBase, TestCase):
|
| 373 | 374 | @staticmethod |
| 374 | 375 | def _get_field_values(serial_str, field_name): |
| 375 | 376 | ret_list = [] |
| 376 | | serial_list = simplejson.loads(serial_str) |
| | 377 | serial_list = json.loads(serial_str) |
| 377 | 378 | for obj_dict in serial_list: |
| 378 | 379 | if field_name in obj_dict["fields"]: |
| 379 | 380 | ret_list.append(obj_dict["fields"][field_name]) |
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
|
| 5 | 5 | import base64 |
| 6 | 6 | import errno |
| 7 | 7 | import hashlib |
| | 8 | import json |
| 8 | 9 | import os |
| 9 | 10 | import shutil |
| 10 | 11 | from StringIO import StringIO |
| … |
… |
from django.core.files import temp as tempfile
|
| 13 | 14 | from django.core.files.uploadedfile import SimpleUploadedFile |
| 14 | 15 | from django.http.multipartparser import MultiPartParser |
| 15 | 16 | from django.test import TestCase, client |
| 16 | | from django.utils import simplejson, unittest |
| | 17 | from django.utils import unittest |
| 17 | 18 | |
| 18 | 19 | from . import uploadhandler |
| 19 | 20 | from .models import FileModel, temp_storage, UPLOAD_TO |
| … |
… |
class FileUploadTests(TestCase):
|
| 78 | 79 | 'wsgi.input': client.FakePayload(payload), |
| 79 | 80 | } |
| 80 | 81 | response = self.client.request(**r) |
| 81 | | received = simplejson.loads(response.content) |
| | 82 | received = json.loads(response.content) |
| 82 | 83 | |
| 83 | 84 | self.assertEqual(received['file'], test_string) |
| 84 | 85 | |
| … |
… |
class FileUploadTests(TestCase):
|
| 150 | 151 | response = self.client.request(**r) |
| 151 | 152 | |
| 152 | 153 | # 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) |
| 154 | 155 | for i, name in enumerate(scary_file_names): |
| 155 | 156 | got = recieved["file%s" % i] |
| 156 | 157 | self.assertEqual(got, "hax0rd.txt") |
| … |
… |
class FileUploadTests(TestCase):
|
| 174 | 175 | 'REQUEST_METHOD': 'POST', |
| 175 | 176 | 'wsgi.input': client.FakePayload(payload), |
| 176 | 177 | } |
| 177 | | got = simplejson.loads(self.client.request(**r).content) |
| | 178 | got = json.loads(self.client.request(**r).content) |
| 178 | 179 | self.assertTrue(len(got['file']) < 256, "Got a long file name (%s characters)." % len(got['file'])) |
| 179 | 180 | |
| 180 | 181 | def test_truncated_multipart_handled_gracefully(self): |
| … |
… |
class FileUploadTests(TestCase):
|
| 200 | 201 | 'REQUEST_METHOD': 'POST', |
| 201 | 202 | 'wsgi.input': client.FakePayload(payload), |
| 202 | 203 | } |
| 203 | | got = simplejson.loads(self.client.request(**r).content) |
| | 204 | got = json.loads(self.client.request(**r).content) |
| 204 | 205 | self.assertEquals(got, {}) |
| 205 | 206 | |
| 206 | 207 | def test_empty_multipart_handled_gracefully(self): |
| … |
… |
class FileUploadTests(TestCase):
|
| 215 | 216 | 'REQUEST_METHOD': 'POST', |
| 216 | 217 | 'wsgi.input': client.FakePayload(''), |
| 217 | 218 | } |
| 218 | | got = simplejson.loads(self.client.request(**r).content) |
| | 219 | got = json.loads(self.client.request(**r).content) |
| 219 | 220 | self.assertEquals(got, {}) |
| 220 | 221 | |
| 221 | 222 | def test_custom_upload_handler(self): |
| … |
… |
class FileUploadTests(TestCase):
|
| 231 | 232 | |
| 232 | 233 | # Small file posting should work. |
| 233 | 234 | response = self.client.post('/file_uploads/quota/', {'f': smallfile}) |
| 234 | | got = simplejson.loads(response.content) |
| | 235 | got = json.loads(response.content) |
| 235 | 236 | self.assertTrue('f' in got) |
| 236 | 237 | |
| 237 | 238 | # Large files don't go through. |
| 238 | 239 | response = self.client.post("/file_uploads/quota/", {'f': bigfile}) |
| 239 | | got = simplejson.loads(response.content) |
| | 240 | got = json.loads(response.content) |
| 240 | 241 | self.assertTrue('f' not in got) |
| 241 | 242 | |
| 242 | 243 | def test_broken_custom_upload_handler(self): |
| … |
… |
class FileUploadTests(TestCase):
|
| 274 | 275 | 'field5': u'test7', |
| 275 | 276 | 'file2': (file2, file2a) |
| 276 | 277 | }) |
| 277 | | got = simplejson.loads(response.content) |
| | 278 | got = json.loads(response.content) |
| 278 | 279 | |
| 279 | 280 | self.assertEqual(got.get('file1'), 1) |
| 280 | 281 | self.assertEqual(got.get('file2'), 2) |
diff --git a/tests/regressiontests/file_uploads/views.py b/tests/regressiontests/file_uploads/views.py
index 9fd1a8d..ae6842d 100644
|
a
|
b
|
|
| 1 | 1 | from __future__ import absolute_import |
| 2 | 2 | |
| 3 | 3 | import hashlib |
| | 4 | import json |
| 4 | 5 | import os |
| 5 | 6 | |
| 6 | 7 | from django.core.files.uploadedfile import UploadedFile |
| 7 | 8 | from django.http import HttpResponse, HttpResponseServerError |
| 8 | | from django.utils import simplejson |
| 9 | 9 | |
| 10 | 10 | from .models import FileModel, UPLOAD_TO |
| 11 | 11 | from .tests import UNICODE_FILENAME |
| … |
… |
def file_upload_echo(request):
|
| 88 | 88 | Simple view to echo back info about uploaded files for tests. |
| 89 | 89 | """ |
| 90 | 90 | r = dict([(k, f.name) for k, f in request.FILES.items()]) |
| 91 | | return HttpResponse(simplejson.dumps(r)) |
| | 91 | return HttpResponse(json.dumps(r)) |
| 92 | 92 | |
| 93 | 93 | def file_upload_echo_content(request): |
| 94 | 94 | """ |
| 95 | 95 | Simple view to echo back the content of uploaded files for tests. |
| 96 | 96 | """ |
| 97 | 97 | r = dict([(k, f.read()) for k, f in request.FILES.items()]) |
| 98 | | return HttpResponse(simplejson.dumps(r)) |
| | 98 | return HttpResponse(json.dumps(r)) |
| 99 | 99 | |
| 100 | 100 | def file_upload_quota(request): |
| 101 | 101 | """ |
| … |
… |
def file_upload_getlist_count(request):
|
| 120 | 120 | |
| 121 | 121 | for key in request.FILES.keys(): |
| 122 | 122 | file_counts[key] = len(request.FILES.getlist(key)) |
| 123 | | return HttpResponse(simplejson.dumps(file_counts)) |
| | 123 | return HttpResponse(json.dumps(file_counts)) |
| 124 | 124 | |
| 125 | 125 | def file_upload_errors(request): |
| 126 | 126 | request.upload_handlers.insert(0, ErroringUploadHandler()) |
diff --git a/tests/regressiontests/test_client_regress/views.py b/tests/regressiontests/test_client_regress/views.py
index ebb68c4..ffd4166 100644
|
a
|
b
|
|
| | 1 | import json |
| 1 | 2 | import warnings |
| 2 | 3 | |
| 3 | 4 | from django.conf import settings |
| … |
… |
from django.contrib.auth.decorators import login_required
|
| 5 | 6 | from django.http import HttpResponse, HttpResponseRedirect |
| 6 | 7 | from django.core.exceptions import SuspiciousOperation |
| 7 | 8 | from django.shortcuts import render_to_response |
| 8 | | from django.utils import simplejson |
| 9 | 9 | from django.utils.encoding import smart_str |
| 10 | 10 | from django.core.serializers.json import DjangoJSONEncoder |
| 11 | 11 | from django.test.client import CONTENT_TYPE_RE |
| … |
… |
def return_json_file(request):
|
| 81 | 81 | charset = settings.DEFAULT_CHARSET |
| 82 | 82 | |
| 83 | 83 | # 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, |
| 86 | 86 | cls=DjangoJSONEncoder, |
| 87 | 87 | ensure_ascii=False) |
| 88 | 88 | response = HttpResponse(smart_str(obj_json, encoding=charset), status=200, |