diff options
Diffstat (limited to 'debug_toolbar')
| -rw-r--r-- | debug_toolbar/management/commands/debugsqlshell.py | 2 | ||||
| -rw-r--r-- | debug_toolbar/middleware.py | 18 | ||||
| -rw-r--r-- | debug_toolbar/panels/cache.py | 11 | ||||
| -rw-r--r-- | debug_toolbar/panels/logger.py | 3 | ||||
| -rw-r--r-- | debug_toolbar/panels/profiling.py | 23 | ||||
| -rw-r--r-- | debug_toolbar/panels/request_vars.py | 12 | ||||
| -rw-r--r-- | debug_toolbar/panels/signals.py | 17 | ||||
| -rw-r--r-- | debug_toolbar/panels/sql.py | 9 | ||||
| -rw-r--r-- | debug_toolbar/panels/template.py | 6 | ||||
| -rw-r--r-- | debug_toolbar/panels/timer.py | 4 | ||||
| -rw-r--r-- | debug_toolbar/templatetags/debug_toolbar_utils.py | 1 | ||||
| -rw-r--r-- | debug_toolbar/urls.py | 2 | ||||
| -rw-r--r-- | debug_toolbar/utils/__init__.py | 2 | ||||
| -rw-r--r-- | debug_toolbar/utils/tracking/db.py | 10 | ||||
| -rw-r--r-- | debug_toolbar/views.py | 14 |
15 files changed, 77 insertions, 57 deletions
diff --git a/debug_toolbar/management/commands/debugsqlshell.py b/debug_toolbar/management/commands/debugsqlshell.py index 120f0a2..a11af98 100644 --- a/debug_toolbar/management/commands/debugsqlshell.py +++ b/debug_toolbar/management/commands/debugsqlshell.py @@ -3,7 +3,7 @@ from __future__ import print_function, unicode_literals from time import time # 'debugsqlshell' is the same as the 'shell'. -from django.core.management.commands.shell import Command +from django.core.management.commands.shell import Command # noqa from django.db.backends import util import sqlparse diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index f58d78c..2c47227 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -18,13 +18,15 @@ import debug_toolbar.urls from debug_toolbar.toolbar.loader import DebugToolbar _HTML_TYPES = ('text/html', 'application/xhtml+xml') -threading._DummyThread._Thread__stop = lambda x: 1 # Handles python threading module bug - http://bugs.python.org/issue14308 +# Handles python threading module bug - http://bugs.python.org/issue14308 +threading._DummyThread._Thread__stop = lambda x: 1 def replace_insensitive(string, target, replacement): """ - Similar to string.replace() but is case insensitive - Code borrowed from: http://forums.devshed.com/python-programming-11/case-insensitive-string-replace-490921.html + Similar to string.replace() but is case insensitive. + Code borrowed from: + http://forums.devshed.com/python-programming-11/case-insensitive-string-replace-490921.html """ no_case = string.lower() index = no_case.rfind(target.lower()) @@ -75,7 +77,7 @@ class DebugToolbarMiddleware(object): self.tag = '</' + tag + '>' def process_request(self, request): - __traceback_hide__ = True + __traceback_hide__ = True # noqa if self.show_toolbar(request): urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF) if isinstance(urlconf, six.string_types): @@ -83,8 +85,8 @@ class DebugToolbarMiddleware(object): if urlconf not in self._urlconfs: new_urlconf = imp.new_module('urlconf') - new_urlconf.urlpatterns = debug_toolbar.urls.urlpatterns + \ - list(urlconf.urlpatterns) + new_urlconf.urlpatterns = (debug_toolbar.urls.urlpatterns + + list(urlconf.urlpatterns)) if hasattr(urlconf, 'handler403'): new_urlconf.handler403 = urlconf.handler403 @@ -103,7 +105,7 @@ class DebugToolbarMiddleware(object): self.__class__.debug_toolbars[threading.current_thread().ident] = toolbar def process_view(self, request, view_func, view_args, view_kwargs): - __traceback_hide__ = True + __traceback_hide__ = True # noqa toolbar = self.__class__.debug_toolbars.get(threading.current_thread().ident) if not toolbar: return @@ -115,7 +117,7 @@ class DebugToolbarMiddleware(object): return result def process_response(self, request, response): - __traceback_hide__ = True + __traceback_hide__ = True # noqa ident = threading.current_thread().ident toolbar = self.__class__.debug_toolbars.get(ident) if not toolbar or request.is_ajax() or getattr(response, 'streaming', False): diff --git a/debug_toolbar/panels/cache.py b/debug_toolbar/panels/cache.py index 1272dfc..b3cb540 100644 --- a/debug_toolbar/panels/cache.py +++ b/debug_toolbar/panels/cache.py @@ -18,7 +18,8 @@ from debug_toolbar.utils import (tidy_stacktrace, render_stacktrace, get_template_info, get_stack) -cache_called = Signal(providing_args=["time_taken", "name", "return_value", "args", "kwargs", "trace"]) +cache_called = Signal(providing_args=[ + "time_taken", "name", "return_value", "args", "kwargs", "trace"]) def send_signal(method): @@ -27,8 +28,8 @@ def send_signal(method): value = method(self, *args, **kwargs) t = time.time() - t - enable_stacktraces = getattr(settings, - 'DEBUG_TOOLBAR_CONFIG', {}).get('ENABLE_STACKTRACES', True) + debug_toolbar_config = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}) + enable_stacktraces = debug_toolbar_config.get('ENABLE_STACKTRACES', True) if enable_stacktraces: stacktrace = tidy_stacktrace(reversed(get_stack())) else: @@ -160,8 +161,8 @@ class CacheDebugPanel(DebugPanel): cache_called.connect(self._store_call_info) def _store_call_info(self, sender, name=None, time_taken=0, - return_value=None, args=None, kwargs=None, trace=None, - template_info=None, backend=None, **kw): + return_value=None, args=None, kwargs=None, + trace=None, template_info=None, backend=None, **kw): if name == 'get': if return_value is None: self.misses += 1 diff --git a/debug_toolbar/panels/logger.py b/debug_toolbar/panels/logger.py index 2c749ce..0617976 100644 --- a/debug_toolbar/panels/logger.py +++ b/debug_toolbar/panels/logger.py @@ -15,7 +15,8 @@ MESSAGE_IF_STRING_REPRESENTATION_INVALID = '[Could not get log message]' class LogCollector(object): def __init__(self): if threading is None: - raise NotImplementedError("threading module is not available, " + raise NotImplementedError( + "threading module is not available, " "the logging panel cannot be used without it") self.records = {} # a dictionary that maps threads to log records diff --git a/debug_toolbar/panels/profiling.py b/debug_toolbar/panels/profiling.py index 995cccb..0555f23 100644 --- a/debug_toolbar/panels/profiling.py +++ b/debug_toolbar/panels/profiling.py @@ -69,12 +69,15 @@ class FunctionCall(object): file_path, file_name = file_name.rsplit(os.sep, 1) - return mark_safe('<span class="path">{0}/</span><span class="file">{1}</span> in <span class="func">{3}</span>(<span class="lineno">{2}</span>)'.format( - file_path, - file_name, - line_num, - method, - )) + return mark_safe( + '<span class="path">{0}/</span>' + '<span class="file">{1}</span>' + ' in <span class="func">{3}</span>' + '(<span class="lineno">{2}</span>)'.format( + file_path, + file_name, + line_num, + method)) def subfuncs(self): i = 0 @@ -164,7 +167,7 @@ class ProfilingDebugPanel(DebugPanel): self._unwrap_closure_and_profile(cell.cell_contents) def process_view(self, request, view_func, view_args, view_kwargs): - __traceback_hide__ = True + __traceback_hide__ = True # noqa self.profiler = cProfile.Profile() args = (request,) + view_args if DJ_PROFILE_USE_LINE_PROFILER: @@ -184,13 +187,13 @@ class ProfilingDebugPanel(DebugPanel): if func.depth < max_depth: for subfunc in func.subfuncs(): if (subfunc.stats[3] >= cum_time or - (hasattr(self.stats, 'line_stats') and - (subfunc.func in self.stats.line_stats.timings))): + (hasattr(self.stats, 'line_stats') and + (subfunc.func in self.stats.line_stats.timings))): func.has_subfuncs = True self.add_node(func_list, subfunc, max_depth, cum_time=cum_time) def process_response(self, request, response): - __traceback_hide__ = True + __traceback_hide__ = True # noqa if not hasattr(self, 'profiler'): return None self.profiler.create_stats() diff --git a/debug_toolbar/panels/request_vars.py b/debug_toolbar/panels/request_vars.py index 5bf3e7f..326d014 100644 --- a/debug_toolbar/panels/request_vars.py +++ b/debug_toolbar/panels/request_vars.py @@ -35,11 +35,11 @@ class RequestVarsDebugPanel(DebugPanel): 'cookies': [(k, self.request.COOKIES.get(k)) for k in self.request.COOKIES], }) view_info = { - 'view_func': _('<no view>'), - 'view_args': 'None', - 'view_kwargs': 'None', - 'view_urlname': 'None', - } + 'view_func': _('<no view>'), + 'view_args': 'None', + 'view_kwargs': 'None', + 'view_urlname': 'None', + } try: match = resolve(self.request.path) func, args, kwargs = match @@ -56,4 +56,4 @@ class RequestVarsDebugPanel(DebugPanel): self.record_stats({ 'session': [(k, self.request.session.get(k)) for k in self.request.session.keys()] - }) + }) diff --git a/debug_toolbar/panels/signals.py b/debug_toolbar/panels/signals.py index d3d9cfc..f7d4239 100644 --- a/debug_toolbar/panels/signals.py +++ b/debug_toolbar/panels/signals.py @@ -1,10 +1,11 @@ from __future__ import unicode_literals from django.conf import settings -from django.core.signals import (request_started, request_finished, - got_request_exception) -from django.db.models.signals import (class_prepared, pre_init, post_init, - pre_save, post_save, pre_delete, post_delete, post_syncdb) +from django.core.signals import ( + request_started, request_finished, got_request_exception) +from django.db.models.signals import ( + class_prepared, pre_init, post_init, pre_save, post_save, + pre_delete, post_delete, post_syncdb) from django.dispatch.dispatcher import WEAKREF_TYPES from django.utils.translation import ugettext_lazy as _, ungettext from django.utils.importlib import import_module @@ -13,7 +14,7 @@ from django.utils.importlib import import_module try: from django.db.backends.signals import connection_created except ImportError: - connection_created = None # noqa + connection_created = None from debug_toolbar.panels import DebugPanel @@ -90,9 +91,11 @@ class SignalDebugPanel(DebugPanel): receiver = getattr(receiver, '__wraps__', receiver) receiver_name = getattr(receiver, '__name__', str(receiver)) if getattr(receiver, '__self__', None) is not None: - text = "%s.%s" % (getattr(receiver.__self__, '__class__', type).__name__, receiver_name) + receiver_class_name = getattr(receiver.__self__, '__class__', type).__name__ + text = "%s.%s" % (receiver_class_name, receiver_name) elif getattr(receiver, 'im_class', None) is not None: # Python 2 only - text = "%s.%s" % (receiver.im_class.__name__, receiver_name) + receiver_class_name = receiver.im_class.__name__ + text = "%s.%s" % (receiver_class_name, receiver_name) else: text = "%s" % receiver_name receivers.append(text) diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py index 709a5f5..660a794 100644 --- a/debug_toolbar/panels/sql.py +++ b/debug_toolbar/panels/sql.py @@ -171,9 +171,11 @@ class SQLDebugPanel(DebugPanel): query['alias'] = alias if 'iso_level' in query: - query['iso_level'] = get_isolation_level_display(query['engine'], query['iso_level']) + query['iso_level'] = get_isolation_level_display(query['engine'], + query['iso_level']) if 'trans_status' in query: - query['trans_status'] = get_transaction_status_display(query['engine'], query['trans_status']) + query['trans_status'] = get_transaction_status_display(query['engine'], + query['trans_status']) query['form'] = SQLSelectForm(auto_id=None, initial=copy(query)) @@ -182,7 +184,8 @@ class SQLDebugPanel(DebugPanel): query['rgb_color'] = self._databases[alias]['rgb_color'] try: query['width_ratio'] = (query['duration'] / self._sql_time) * 100 - query['width_ratio_relative'] = 100.0 * query['width_ratio'] / (100.0 - width_ratio_tally) + query['width_ratio_relative'] = ( + 100.0 * query['width_ratio'] / (100.0 - width_ratio_tally)) except ZeroDivisionError: query['width_ratio'] = 0 query['width_ratio_relative'] = 0 diff --git a/debug_toolbar/panels/template.py b/debug_toolbar/panels/template.py index b3b6707..d8f96f2 100644 --- a/debug_toolbar/panels/template.py +++ b/debug_toolbar/panels/template.py @@ -75,8 +75,10 @@ class TemplateDebugPanel(DebugPanel): temp_layer[key] = '<<languages>>' # QuerySet would trigger the database: user can run the query from SQL Panel elif isinstance(value, (QuerySet, RawQuerySet)): - model_name = "%s.%s" % (value.model._meta.app_label, value.model.__name__) - temp_layer[key] = '<<%s of %s>>' % (value.__class__.__name__.lower(), model_name) + model_name = "%s.%s" % ( + value.model._meta.app_label, value.model.__name__) + temp_layer[key] = '<<%s of %s>>' % ( + value.__class__.__name__.lower(), model_name) else: try: recording(False) diff --git a/debug_toolbar/panels/timer.py b/debug_toolbar/panels/timer.py index 9b420cb..379f6ae 100644 --- a/debug_toolbar/panels/timer.py +++ b/debug_toolbar/panels/timer.py @@ -89,10 +89,6 @@ class TimerDebugPanel(DebugPanel): (_('Total CPU time'), _('%(total)0.3f msec') % stats), (_('Elapsed time'), _('%(total_time)0.3f msec') % stats), (_('Context switches'), _('%(vcsw)d voluntary, %(ivcsw)d involuntary') % stats), -# ('Memory use', '%d max RSS, %d shared, %d unshared' % (stats['rss'], stats.['srss'], -# stats['urss'] + stats['usrss'])), -# ('Page faults', '%d no i/o, %d requiring i/o' % (stats['minflt'], stats['majflt'])), -# ('Disk operations', '%d in, %d out, %d swapout' % (stats['blkin'], stats['blkout'], stats['swap'])), ) context = self.context.copy() context.update({'rows': rows}) diff --git a/debug_toolbar/templatetags/debug_toolbar_utils.py b/debug_toolbar/templatetags/debug_toolbar_utils.py index 7917a67..c96f868 100644 --- a/debug_toolbar/templatetags/debug_toolbar_utils.py +++ b/debug_toolbar/templatetags/debug_toolbar_utils.py @@ -10,4 +10,3 @@ register = template.Library() def dotted_number(number): number = float(number) return format(number, '.', 6) - diff --git a/debug_toolbar/urls.py b/debug_toolbar/urls.py index 524710d..1a6daf8 100644 --- a/debug_toolbar/urls.py +++ b/debug_toolbar/urls.py @@ -11,7 +11,7 @@ from django.conf.urls import patterns, url _PREFIX = '__debug__' -urlpatterns = patterns('debug_toolbar.views', +urlpatterns = patterns('debug_toolbar.views', # noqa url(r'^%s/sql_select/$' % _PREFIX, 'sql_select', name='sql_select'), url(r'^%s/sql_explain/$' % _PREFIX, 'sql_explain', name='sql_explain'), url(r'^%s/sql_profile/$' % _PREFIX, 'sql_profile', name='sql_profile'), diff --git a/debug_toolbar/utils/__init__.py b/debug_toolbar/utils/__init__.py index da2e3c3..73e38e2 100644 --- a/debug_toolbar/utils/__init__.py +++ b/debug_toolbar/utils/__init__.py @@ -68,7 +68,7 @@ def tidy_stacktrace(stack): # inspection. if '__traceback_hide__' in frame.f_locals: continue - if hide_django_sql and django_path in s_path and not 'django/contrib' in s_path: + if hide_django_sql and django_path in s_path and not 'django/contrib' in s_path: continue if omit_path(s_path): continue diff --git a/debug_toolbar/utils/tracking/db.py b/debug_toolbar/utils/tracking/db.py index b4ceff0..5822270 100644 --- a/debug_toolbar/utils/tracking/db.py +++ b/debug_toolbar/utils/tracking/db.py @@ -16,8 +16,8 @@ from debug_toolbar.utils import tidy_stacktrace, get_template_info, get_stack # 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', {}) \ - .get('SQL_WARNING_THRESHOLD', 500) +DEBUG_TOOLBAR_CONFIG = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}) +SQL_WARNING_THRESHOLD = DEBUG_TOOLBAR_CONFIG.get('SQL_WARNING_THRESHOLD', 500) class SQLQueryTriggered(Exception): @@ -82,7 +82,7 @@ class NormalCursorWrapper(object): return params if isinstance(params, dict): return dict((key, self._quote_expr(value)) - for key, value in params.items()) + for key, value in params.items()) return list(map(self._quote_expr, params)) def _decode(self, param): @@ -98,8 +98,8 @@ class NormalCursorWrapper(object): finally: stop_time = time() duration = (stop_time - start_time) * 1000 - enable_stacktraces = getattr(settings, - 'DEBUG_TOOLBAR_CONFIG', {}).get('ENABLE_STACKTRACES', True) + debug_toolbar_config = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}) + enable_stacktraces = debug_toolbar_config.get('ENABLE_STACKTRACES', True) if enable_stacktraces: stacktrace = tidy_stacktrace(reversed(get_stack())) else: diff --git a/debug_toolbar/views.py b/debug_toolbar/views.py index 53ad3c9..436cb07 100644 --- a/debug_toolbar/views.py +++ b/debug_toolbar/views.py @@ -90,8 +90,18 @@ def sql_profile(request): cursor.execute("SET PROFILING=1") # Enable profiling cursor.execute(sql, params) # Execute SELECT cursor.execute("SET PROFILING=0") # Disable profiling - # The Query ID should always be 1 here but I'll subselect to get the last one just in case... - cursor.execute("SELECT * FROM information_schema.profiling WHERE query_id=(SELECT query_id FROM information_schema.profiling ORDER BY query_id DESC LIMIT 1)") + # The Query ID should always be 1 here but I'll subselect to get + # the last one just in case... + cursor.execute(""" + SELECT * + FROM information_schema.profiling + WHERE query_id = ( + SELECT query_id + FROM information_schema.profiling + ORDER BY query_id DESC + LIMIT 1 + ) +""") headers = [d[0] for d in cursor.description] result = cursor.fetchall() except Exception: |
