Skip to content

Use the built-in json module on python >= 2.6. #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions debug_toolbar/utils/tracking/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 9 additions & 5 deletions debug_toolbar/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down