diff options
Diffstat (limited to 'debug_toolbar/utils')
| -rw-r--r-- | debug_toolbar/utils/__init__.py | 12 | ||||
| -rw-r--r-- | debug_toolbar/utils/compat/db.py | 2 | ||||
| -rw-r--r-- | debug_toolbar/utils/sqlparse/engine/filter.py | 2 | ||||
| -rw-r--r-- | debug_toolbar/utils/sqlparse/filters.py | 5 | ||||
| -rw-r--r-- | debug_toolbar/utils/sqlparse/sql.py | 4 | ||||
| -rw-r--r-- | debug_toolbar/utils/tracking/__init__.py | 10 |
6 files changed, 24 insertions, 11 deletions
diff --git a/debug_toolbar/utils/__init__.py b/debug_toolbar/utils/__init__.py index 45dfc6f..01f817a 100644 --- a/debug_toolbar/utils/__init__.py +++ b/debug_toolbar/utils/__init__.py @@ -11,12 +11,14 @@ from django.views.debug import linebreak_iter django_path = os.path.realpath(os.path.dirname(django.__file__)) socketserver_path = os.path.realpath(os.path.dirname(SocketServer.__file__)) + def ms_from_timedelta(td): """ Given a timedelta object, returns a float representing milliseconds """ return (td.seconds * 1000) + (td.microseconds / 1000.0) + def tidy_stacktrace(stack): """ Clean up stacktrace and remove all entries that: @@ -45,6 +47,7 @@ def tidy_stacktrace(stack): trace.append((path, line_no, func_name, text)) return trace + def get_template_info(source, context_lines=3): line = 0 upto = 0 @@ -79,6 +82,7 @@ def get_template_info(source, context_lines=3): 'context': context, } + def get_name_from_obj(obj): if hasattr(obj, '__name__'): name = obj.__name__ @@ -93,6 +97,7 @@ def get_name_from_obj(obj): return name + def getframeinfo(frame, context=1): """ Get information about a frame or traceback object. @@ -116,7 +121,7 @@ def getframeinfo(frame, context=1): filename = inspect.getsourcefile(frame) or inspect.getfile(frame) if context > 0: - start = lineno - 1 - context//2 + start = lineno - 1 - context // 2 try: lines, lnum = inspect.findsource(frame) except (IOError, IndexError): @@ -124,7 +129,7 @@ def getframeinfo(frame, context=1): else: start = max(start, 1) start = max(0, min(start, len(lines) - context)) - lines = lines[start:start+context] + lines = lines[start:(start + context)] index = lineno - 1 - start else: lines = index = None @@ -134,6 +139,7 @@ def getframeinfo(frame, context=1): else: return (filename, lineno, frame.f_code.co_name, lines, index) + def get_stack(context=1): """ Get a list of records for a frame and all higher (calling) frames. @@ -148,4 +154,4 @@ def get_stack(context=1): while frame: framelist.append((frame,) + getframeinfo(frame, context)) frame = frame.f_back - return framelist
\ No newline at end of file + return framelist diff --git a/debug_toolbar/utils/compat/db.py b/debug_toolbar/utils/compat/db.py index 4273d9e..6ff09ec 100644 --- a/debug_toolbar/utils/compat/db.py +++ b/debug_toolbar/utils/compat/db.py @@ -10,4 +10,4 @@ except ImportError: 'default': { 'ENGINE': settings.DATABASE_ENGINE, } - }
\ No newline at end of file + } diff --git a/debug_toolbar/utils/sqlparse/engine/filter.py b/debug_toolbar/utils/sqlparse/engine/filter.py index c1c0d6a..a31c5de 100644 --- a/debug_toolbar/utils/sqlparse/engine/filter.py +++ b/debug_toolbar/utils/sqlparse/engine/filter.py @@ -61,7 +61,7 @@ class StatementFilter(TokenFilter): if unified == 'END': # Should this respect a preceeding BEGIN? # In CASE ... WHEN ... END this results in a split level -1. - self._begin_depth = max(0, self._begin_depth-1) + self._begin_depth = max(0, self._begin_depth - 1) return -1 if ttype is T.Keyword.DDL and unified.startswith('CREATE'): diff --git a/debug_toolbar/utils/sqlparse/filters.py b/debug_toolbar/utils/sqlparse/filters.py index 2d247e7..897cc90 100644 --- a/debug_toolbar/utils/sqlparse/filters.py +++ b/debug_toolbar/utils/sqlparse/filters.py @@ -146,13 +146,14 @@ class ReindentFilter(Filter): split_words = ('FROM', 'JOIN$', 'AND', 'OR', 'GROUP', 'ORDER', 'UNION', 'VALUES', 'SET', 'BETWEEN') + def _next_token(i): t = tlist.token_next_match(i, T.Keyword, split_words, regex=True) if t and t.value.upper() == 'BETWEEN': - t = _next_token(tlist.token_index(t)+1) + t = _next_token(tlist.token_index(t) + 1) if t and t.value.upper() == 'AND': - t = _next_token(tlist.token_index(t)+1) + t = _next_token(tlist.token_index(t) + 1) return t idx = 0 diff --git a/debug_toolbar/utils/sqlparse/sql.py b/debug_toolbar/utils/sqlparse/sql.py index 55bf804..2f9f538 100644 --- a/debug_toolbar/utils/sqlparse/sql.py +++ b/debug_toolbar/utils/sqlparse/sql.py @@ -146,7 +146,7 @@ class TokenList(Token): def _pprint_tree(self, max_depth=None, depth=0): """Pretty-print the object tree.""" - indent = ' '*(depth*2) + indent = ' ' * (depth * 2) for idx, token in enumerate(self.tokens): if token.is_group(): pre = ' +-' @@ -156,7 +156,7 @@ class TokenList(Token): token._get_repr_name(), token._get_repr_value()) if (token.is_group() and (max_depth is None or depth < max_depth)): - token._pprint_tree(max_depth, depth+1) + token._pprint_tree(max_depth, depth + 1) def flatten(self): """Generator yielding ungrouped tokens. diff --git a/debug_toolbar/utils/tracking/__init__.py b/debug_toolbar/utils/tracking/__init__.py index db8ff18..9c72803 100644 --- a/debug_toolbar/utils/tracking/__init__.py +++ b/debug_toolbar/utils/tracking/__init__.py @@ -2,18 +2,21 @@ import logging import time import types + def post_dispatch(func): def wrapped(callback): register_hook(func, 'after', callback) return callback return wrapped + def pre_dispatch(func): def wrapped(callback): register_hook(func, 'before', callback) return callback return wrapped + def replace_call(func): def inner(callback): def wrapped(*args, **kwargs): @@ -28,6 +31,7 @@ def replace_call(func): return wrapped return inner + def fire_hook(hook, sender, **kwargs): try: for callback in callbacks[hook].get(id(sender), []): @@ -36,6 +40,7 @@ def fire_hook(hook, sender, **kwargs): # Log the exception, dont mess w/ the underlying function logging.exception(e) + def _replace_function(func, wrapped): if isinstance(func, types.FunctionType): if func.__module__ == '__builtin__': @@ -58,6 +63,7 @@ callbacks = { 'after': {}, } + def register_hook(func, hook, callback): """ def myhook(sender, args, kwargs): @@ -81,10 +87,10 @@ def register_hook(func, hook, callback): wrapped.__wrapped__ = actual wrapped.__doc__ = getattr(actual, '__doc__', None) wrapped.__name__ = actual.__name__ - + id_ = id(actual) if id_ not in callbacks[hook]: callbacks[hook][id_] = [] callbacks[hook][id_].append(callback) - _replace_function(func, wrapped)
\ No newline at end of file + _replace_function(func, wrapped) |
