diff options
| author | Jannis Leidel | 2012-04-06 12:59:56 +0200 | 
|---|---|---|
| committer | Jannis Leidel | 2013-12-08 23:33:39 +0100 | 
| commit | 184992f2d5773016e2c8315c91acbf8f601775bf (patch) | |
| tree | 17753ea901f2db95e93f5897606fe0cbbda5e860 /debug_toolbar/utils.py | |
| parent | e334bf6e4b4975fd87957c473a62c0d889e38cb0 (diff) | |
| download | django-debug-toolbar-184992f2d5773016e2c8315c91acbf8f601775bf.tar.bz2 | |
Added staticfiles panel class.
Diffstat (limited to 'debug_toolbar/utils.py')
| -rw-r--r-- | debug_toolbar/utils.py | 33 | 
1 files changed, 33 insertions, 0 deletions
| diff --git a/debug_toolbar/utils.py b/debug_toolbar/utils.py index d84c79c..0aedb54 100644 --- a/debug_toolbar/utils.py +++ b/debug_toolbar/utils.py @@ -4,6 +4,10 @@ import inspect  import os.path  import re  import sys +try: +    import threading +except ImportError: +    threading = None  import django  from django.core.exceptions import ImproperlyConfigured @@ -199,3 +203,32 @@ def get_stack(context=1):          framelist.append((frame,) + getframeinfo(frame, context))          frame = frame.f_back      return framelist + + +class ThreadCollector(object): +    def __init__(self): +        if threading is None: +            raise NotImplementedError( +                "threading module is not available, " +                "this panel cannot be used without it") +        self.collections = {}  # a dictionary that maps threads to collections + +    def get_collection(self, thread=None): +        """ +        Returns a list of collected items for the provided thread, of if none +        is provided, returns a list for the current thread. +        """ +        if thread is None: +            thread = threading.currentThread() +        if thread not in self.collections: +            self.collections[thread] = [] +        return self.collections[thread] + +    def clear_collection(self, thread=None): +        if thread is None: +            thread = threading.currentThread() +        if thread in self.collections: +            del self.collections[thread] + +    def collect(self, item, thread=None): +        self.get_collection(thread).append(item) | 
