Skip to content

fix hashcompat deprecation warnings with django 1.5 #336

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
Nov 26, 2012
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
fix hashcompat deprecation warnings with django 1.5
  • Loading branch information
craigds committed Nov 20, 2012
commit dc62f8175f5b63285628694f67185b51afe626e8
9 changes: 7 additions & 2 deletions debug_toolbar/utils/tracking/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
from django.template import Node
from django.utils import simplejson
from django.utils.encoding import force_unicode, smart_str
from django.utils.hashcompat import sha_constructor

from debug_toolbar.utils import ms_from_timedelta, tidy_stacktrace, \
get_template_info, get_stack
from debug_toolbar.utils.compat.db import connections

try:
from hashlib import sha1
except ImportError:
from django.utils.hashcompat import sha_constructor as sha1

# TODO:This should be set in the toolbar loader as a default and panels should
# get a copy of the toolbar object with access to its config dictionary
SQL_WARNING_THRESHOLD = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}) \
Expand Down Expand Up @@ -134,7 +139,7 @@ def execute(self, sql, params=()):
'duration': duration,
'raw_sql': sql,
'params': _params,
'hash': sha_constructor(settings.SECRET_KEY \
'hash': sha1(settings.SECRET_KEY \
+ smart_str(sql) \
+ _params).hexdigest(),
'stacktrace': stacktrace,
Expand Down
12 changes: 8 additions & 4 deletions debug_toolbar/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
from django.http import HttpResponseBadRequest
from django.shortcuts import render_to_response
from django.utils import simplejson
from django.utils.hashcompat import sha_constructor

from debug_toolbar.utils.compat.db import connections

try:
from hashlib import sha1
except ImportError:
from django.utils.hashcompat import sha_constructor as sha1


class InvalidSQLError(Exception):
def __init__(self, value):
Expand All @@ -37,7 +41,7 @@ def sql_select(request):
sql = request.GET.get('sql', '')
params = request.GET.get('params', '')
alias = request.GET.get('alias', 'default')
hash = sha_constructor(settings.SECRET_KEY + sql + params).hexdigest()
hash = sha1(settings.SECRET_KEY + sql + params).hexdigest()
if hash != request.GET.get('hash', ''):
return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert
if sql.lower().strip().startswith('select'):
Expand Down Expand Up @@ -72,7 +76,7 @@ def sql_explain(request):
sql = request.GET.get('sql', '')
params = request.GET.get('params', '')
alias = request.GET.get('alias', 'default')
hash = sha_constructor(settings.SECRET_KEY + sql + params).hexdigest()
hash = sha1(settings.SECRET_KEY + sql + params).hexdigest()
if hash != request.GET.get('hash', ''):
return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert
if sql.lower().strip().startswith('select'):
Expand Down Expand Up @@ -118,7 +122,7 @@ def sql_profile(request):
sql = request.GET.get('sql', '')
params = request.GET.get('params', '')
alias = request.GET.get('alias', 'default')
hash = sha_constructor(settings.SECRET_KEY + sql + params).hexdigest()
hash = sha1(settings.SECRET_KEY + sql + params).hexdigest()
if hash != request.GET.get('hash', ''):
return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert
if sql.lower().strip().startswith('select'):
Expand Down