diff options
| author | David Cramer | 2012-01-12 19:13:47 -0800 |
|---|---|---|
| committer | David Cramer | 2012-01-12 19:13:47 -0800 |
| commit | 01cd08518ded622d3308dd539b00ebbf7012894e (patch) | |
| tree | a9cca14ff92d4602a51d4999430574587a733d1d /debug_toolbar/utils/__init__.py | |
| parent | c4eeef24faa81e7bc64ebfbd72c046f25c7b3381 (diff) | |
| download | django-debug-toolbar-01cd08518ded622d3308dd539b00ebbf7012894e.tar.bz2 | |
pep8
Diffstat (limited to 'debug_toolbar/utils/__init__.py')
| -rw-r--r-- | debug_toolbar/utils/__init__.py | 12 |
1 files changed, 9 insertions, 3 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 |
