Skip to content
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

First bunch of fixes to make debug-toolbar work with Python 3 #365

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion debug_toolbar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
try:
VERSION = __import__('pkg_resources') \
.get_distribution('django-debug-toolbar').version
except Exception, e:
except Exception as e:
VERSION = 'unknown'
15 changes: 11 additions & 4 deletions debug_toolbar/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
Debug Toolbar middleware
"""
import imp
import thread

try: # python 3 compat
import thread
except ImportError:
import threading as thread
import sys
from django.conf import settings
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.utils.encoding import smart_unicode
try: # python 3 compat
from django.utils.encoding import smart_unicode
except ImportError:
from django.utils.encoding import smart_text as smart_unicode
from django.utils.importlib import import_module

import debug_toolbar.urls
Expand Down Expand Up @@ -76,7 +82,8 @@ def process_request(self, request):
__traceback_hide__ = True
if self.show_toolbar(request):
urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF)
if isinstance(urlconf, basestring):
# the below condition is for python 3 compat
if isinstance(urlconf, basestring if sys.version_info[0] < 3 else str):
urlconf = import_module(getattr(request, 'urlconf', settings.ROOT_URLCONF))

if urlconf not in self._urlconfs:
Expand Down
1 change: 0 additions & 1 deletion debug_toolbar/panels/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def cursor(func, self):

return CursorWrapper(result, self, logger=logger)


def get_isolation_level_display(engine, level):
if engine == 'psycopg2':
import psycopg2.extensions
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/toolbar/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def load_panel_classes():
panel_module, panel_classname = panel_path[:dot], panel_path[dot + 1:]
try:
mod = import_module(panel_module)
except ImportError, e:
except ImportError as e:
raise ImproperlyConfigured(
'Error importing debug panel %s: "%s"' %
(panel_module, e))
Expand Down
5 changes: 4 additions & 1 deletion debug_toolbar/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import inspect
import os.path
import django
import SocketServer
try: # python 3 compat
import SocketServer
except ImportError:
import socketserver as SocketServer
import sys

from django.conf import settings
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/utils/sqlparse/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _process_state(cls, unprocessed, processed, state):

try:
rex = re.compile(tdef[0], rflags).match
except Exception, err:
except Exception as err:
raise ValueError(("uncompilable regex %r in state"
" %r of %r: %s"
% (tdef[0], state, cls, err)))
Expand Down
5 changes: 3 additions & 2 deletions debug_toolbar/utils/sqlparse/sql.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

"""This module contains classes representing syntactical elements of SQL."""
from __future__ import print_function

import re

Expand Down Expand Up @@ -152,9 +153,9 @@ def _pprint_tree(self, max_depth=None, depth=0):
pre = ' +-'
else:
pre = ' | '
print '%s%s%d %s \'%s\'' % (indent, pre, idx,
print('%s%s%d %s \'%s\'' % (indent, pre, idx,
token._get_repr_name(),
token._get_repr_value())
token._get_repr_value()))
if (token.is_group() and (max_depth is None or depth < max_depth)):
token._pprint_tree(max_depth, depth + 1)

Expand Down
5 changes: 4 additions & 1 deletion debug_toolbar/utils/tracking/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

from django.conf import settings
from django.template import Node
from django.utils.encoding import force_unicode, smart_str
try: # python 3 compat
from django.utils.encoding import force_unicode, smart_str
except ImportError:
from django.utils.encoding import force_text as force_unicode, smart_bytes as smart_str

from debug_toolbar.utils import ms_from_timedelta, tidy_stacktrace, \
get_template_info, get_stack
Expand Down
Loading