formencode.util.threadinglocal
Covered: 5 lines
Missed: 24 lines
Skipped 11 lines
Percent: 17 %
 4
try:
 5
    import threading
 6
except ImportError:
 8
    class local(object):
 9
        pass
10
else:
11
    try:
12
        local = threading.local
13
    except AttributeError:
15
        import thread
16
        class local(object):
18
            def __init__(self):
19
                self.__dict__['__objs'] = {}
21
            def __getattr__(self, attr, g=thread.get_ident):
22
                try:
23
                    return self.__dict__['__objs'][g()][attr]
24
                except KeyError:
25
                    raise AttributeError(
26
                        "No variable %s defined for the thread %s"
27
                        % (attr, g()))
29
            def __setattr__(self, attr, value, g=thread.get_ident):
30
                self.__dict__['__objs'].setdefault(g(), {})[attr] = value
32
            def __delattr__(self, attr, g=thread.get_ident):
33
                try:
34
                    del self.__dict__['__objs'][g()][attr]
35
                except KeyError:
36
                    raise AttributeError(
37
                        "No variable %s defined for thread %s"
38
                        % (attr, g()))