1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/OpenSecurity/install/web.py-0.37/build/lib/web/python23.py Mon Dec 02 14:02:05 2013 +0100
1.3 @@ -0,0 +1,46 @@
1.4 +"""Python 2.3 compatabilty"""
1.5 +import threading
1.6 +
1.7 +class threadlocal(object):
1.8 + """Implementation of threading.local for python2.3.
1.9 + """
1.10 + def __getattribute__(self, name):
1.11 + if name == "__dict__":
1.12 + return threadlocal._getd(self)
1.13 + else:
1.14 + try:
1.15 + return object.__getattribute__(self, name)
1.16 + except AttributeError:
1.17 + try:
1.18 + return self.__dict__[name]
1.19 + except KeyError:
1.20 + raise AttributeError, name
1.21 +
1.22 + def __setattr__(self, name, value):
1.23 + self.__dict__[name] = value
1.24 +
1.25 + def __delattr__(self, name):
1.26 + try:
1.27 + del self.__dict__[name]
1.28 + except KeyError:
1.29 + raise AttributeError, name
1.30 +
1.31 + def _getd(self):
1.32 + t = threading.currentThread()
1.33 + if not hasattr(t, '_d'):
1.34 + # using __dict__ of thread as thread local storage
1.35 + t._d = {}
1.36 +
1.37 + _id = id(self)
1.38 + # there could be multiple instances of threadlocal.
1.39 + # use id(self) as key
1.40 + if _id not in t._d:
1.41 + t._d[_id] = {}
1.42 + return t._d[_id]
1.43 +
1.44 +if __name__ == '__main__':
1.45 + d = threadlocal()
1.46 + d.x = 1
1.47 + print d.__dict__
1.48 + print d.x
1.49 +
1.50 \ No newline at end of file