aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Christie2011-04-25 04:50:28 +0100
committerTom Christie2011-04-25 04:50:28 +0100
commit762a52edde09297e87c640797219c9bb8255d50a (patch)
treec68aff4f73e988fd2ee2cec827bd3ec528fa6e22
parent84a4fd3ea11a55441cb5b8acd584c76fc325edcc (diff)
downloaddjango-rest-framework-762a52edde09297e87c640797219c9bb8255d50a.tar.bz2
Fix some compat issues with json/simplejson
-rw-r--r--djangorestframework/compat.py10
-rw-r--r--djangorestframework/emitters.py6
-rw-r--r--djangorestframework/parsers.py13
-rw-r--r--djangorestframework/tests/authentication.py12
-rw-r--r--djangorestframework/tests/reverse.py5
-rw-r--r--examples/blogpost/tests.py13
-rw-r--r--examples/pygments_api/tests.py8
7 files changed, 29 insertions, 38 deletions
diff --git a/djangorestframework/compat.py b/djangorestframework/compat.py
index 3e82bd98..22b57186 100644
--- a/djangorestframework/compat.py
+++ b/djangorestframework/compat.py
@@ -125,4 +125,12 @@ except:
# 'request': self.request
# }
#)
- return http.HttpResponseNotAllowed(allowed_methods) \ No newline at end of file
+ return http.HttpResponseNotAllowed(allowed_methods)
+
+# parse_qs
+try:
+ # python >= ?
+ from urlparse import parse_qs
+except ImportError:
+ # python <= ?
+ from cgi import parse_qs \ No newline at end of file
diff --git a/djangorestframework/emitters.py b/djangorestframework/emitters.py
index 2990d313..39046919 100644
--- a/djangorestframework/emitters.py
+++ b/djangorestframework/emitters.py
@@ -5,6 +5,7 @@ and providing forms and links depending on the allowed methods, emitters and par
"""
from django.conf import settings
from django.template import RequestContext, loader
+from django.utils import simplejson as json
from django import forms
from djangorestframework.response import ErrorResponse
@@ -18,11 +19,6 @@ from urllib import quote_plus
import string
import re
-try:
- import json
-except ImportError:
- import simplejson as json
-
# TODO: Rename verbose to something more appropriate
diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py
index 707b61d5..caa76277 100644
--- a/djangorestframework/parsers.py
+++ b/djangorestframework/parsers.py
@@ -9,20 +9,13 @@ We need a method to be able to:
and multipart/form-data. (eg also handle multipart/json)
"""
from django.http.multipartparser import MultiPartParser as DjangoMPParser
+from django.utils import simplejson as json
+
from djangorestframework.response import ErrorResponse
from djangorestframework import status
from djangorestframework.utils import as_tuple
from djangorestframework.mediatypes import MediaType
-
-try:
- import json
-except ImportError:
- import simplejson as json
-
-try:
- from urlparse import parse_qs
-except ImportError:
- from cgi import parse_qs
+from djangorestframework.compat import parse_qs
diff --git a/djangorestframework/tests/authentication.py b/djangorestframework/tests/authentication.py
index c825883d..72300506 100644
--- a/djangorestframework/tests/authentication.py
+++ b/djangorestframework/tests/authentication.py
@@ -1,16 +1,15 @@
from django.conf.urls.defaults import patterns
from django.test import TestCase
from django.test import Client
-from djangorestframework.compat import RequestFactory
-from djangorestframework.resource import Resource
from django.contrib.auth.models import User
from django.contrib.auth import login
+from django.utils import simplejson as json
+
+from djangorestframework.compat import RequestFactory
+from djangorestframework.resource import Resource
import base64
-try:
- import json
-except ImportError:
- import simplejson as json
+
class MockResource(Resource):
def post(self, request):
@@ -86,3 +85,4 @@ class SessionAuthTests(TestCase):
"""Ensure POSTing form over session authentication without logged in user fails."""
response = self.csrf_client.post('/', {'example': 'example'})
self.assertEqual(response.status_code, 403)
+
diff --git a/djangorestframework/tests/reverse.py b/djangorestframework/tests/reverse.py
index 1f9071b3..28fee63b 100644
--- a/djangorestframework/tests/reverse.py
+++ b/djangorestframework/tests/reverse.py
@@ -1,13 +1,10 @@
from django.conf.urls.defaults import patterns, url
from django.core.urlresolvers import reverse
from django.test import TestCase
+from django.utils import simplejson as json
from djangorestframework.resource import Resource
-try:
- import json
-except ImportError:
- import simplejson as json
class MockResource(Resource):
diff --git a/examples/blogpost/tests.py b/examples/blogpost/tests.py
index dfb4d5f5..14b0914d 100644
--- a/examples/blogpost/tests.py
+++ b/examples/blogpost/tests.py
@@ -1,13 +1,15 @@
"""Test a range of REST API usage of the example application.
"""
-from django.test import TestCase
from django.core.urlresolvers import reverse
+from django.test import TestCase
+from django.utils import simplejson as json
+
+from djangorestframework.compat import RequestFactory
+
from blogpost import views, models
import blogpost
-#import json
-#from rest.utils import xml2dict, dict2xml
class AcceptHeaderTests(TestCase):
"""Test correct behaviour of the Accept header as specified by RFC 2616:
@@ -164,11 +166,6 @@ class AllowedMethodsTests(TestCase):
#above testcases need to probably moved to the core
-from djangorestframework.compat import RequestFactory
-try:
- import json
-except ImportError:
- import simplejson as json
class TestRotation(TestCase):
"""For the example the maximum amount of Blogposts is capped off at views.MAX_POSTS.
diff --git a/examples/pygments_api/tests.py b/examples/pygments_api/tests.py
index 017823b9..a8f085cf 100644
--- a/examples/pygments_api/tests.py
+++ b/examples/pygments_api/tests.py
@@ -1,12 +1,12 @@
from django.test import TestCase
+from django.utils import simplejson as json
+
from djangorestframework.compat import RequestFactory
+
from pygments_api import views
import tempfile, shutil
-try:
- import json
-except ImportError:
- import simplejson as json
+
class TestPygmentsExample(TestCase):