From d4971605cc0f82315805c44ea8346f609b1f07bb Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Sun, 30 Dec 2012 17:52:56 -0500 Subject: [PATCH] Use the built-in json module on python >= 2.6. `django.utils.simplejson` is pending deprecation as of django 1.5 and will be removed in 1.7. --- debug_toolbar/utils/tracking/db.py | 10 +++++++--- debug_toolbar/views.py | 14 +++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/debug_toolbar/utils/tracking/db.py b/debug_toolbar/utils/tracking/db.py index 0dc22a6e4..d898b31d0 100644 --- a/debug_toolbar/utils/tracking/db.py +++ b/debug_toolbar/utils/tracking/db.py @@ -5,16 +5,20 @@ from django.conf import settings from django.template import Node -from django.utils import simplejson from django.utils.encoding import force_unicode, smart_str from debug_toolbar.utils import ms_from_timedelta, tidy_stacktrace, \ get_template_info, get_stack from debug_toolbar.utils.compat.db import connections +try: + import json +except ImportError: # python < 2.6 + from django.utils import simplejson as json + try: from hashlib import sha1 -except ImportError: +except ImportError: # python < 2.5 from django.utils.hashcompat import sha_constructor as sha1 # TODO:This should be set in the toolbar loader as a default and panels should @@ -103,7 +107,7 @@ def execute(self, sql, params=()): stacktrace = [] _params = '' try: - _params = simplejson.dumps( + _params = json.dumps( [force_unicode(x, strings_only=True) for x in params] ) except TypeError: diff --git a/debug_toolbar/views.py b/debug_toolbar/views.py index a64254122..18b9460af 100644 --- a/debug_toolbar/views.py +++ b/debug_toolbar/views.py @@ -9,13 +9,17 @@ from django.conf import settings from django.http import HttpResponseBadRequest from django.shortcuts import render_to_response -from django.utils import simplejson from debug_toolbar.utils.compat.db import connections +try: + import json +except ImportError: # python < 2.6 + from django.utils import simplejson as json + try: from hashlib import sha1 -except ImportError: +except ImportError: # python < 2.5 from django.utils.hashcompat import sha_constructor as sha1 @@ -45,7 +49,7 @@ def sql_select(request): if hash != request.GET.get('hash', ''): return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert if sql.lower().strip().startswith('select'): - params = simplejson.loads(params) + params = json.loads(params) cursor = connections[alias].cursor() cursor.execute(sql, params) headers = [d[0] for d in cursor.description] @@ -80,7 +84,7 @@ def sql_explain(request): if hash != request.GET.get('hash', ''): return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert if sql.lower().strip().startswith('select'): - params = simplejson.loads(params) + params = json.loads(params) cursor = connections[alias].cursor() conn = connections[alias].connection @@ -126,7 +130,7 @@ def sql_profile(request): if hash != request.GET.get('hash', ''): return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert if sql.lower().strip().startswith('select'): - params = simplejson.loads(params) + params = json.loads(params) cursor = connections[alias].cursor() result = None headers = None