home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_1567 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  3.2 KB  |  114 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4.  
  5. class _localbase(object):
  6.     __slots__ = ('_local__key', '_local__args', '_local__lock')
  7.     
  8.     def __new__(cls, *args, **kw):
  9.         self = object.__new__(cls)
  10.         key = 'thread.local.' + str(id(self))
  11.         object.__setattr__(self, '_local__key', key)
  12.         object.__setattr__(self, '_local__args', (args, kw))
  13.         object.__setattr__(self, '_local__lock', RLock())
  14.         if (args or kw) and cls.__init__ is object.__init__:
  15.             raise TypeError('Initialization arguments are not supported')
  16.         cls.__init__ is object.__init__
  17.         dict = object.__getattribute__(self, '__dict__')
  18.         currentThread().__dict__[key] = dict
  19.         return self
  20.  
  21.  
  22.  
  23. def _patch(self):
  24.     key = object.__getattribute__(self, '_local__key')
  25.     d = currentThread().__dict__.get(key)
  26.     if d is None:
  27.         d = { }
  28.         currentThread().__dict__[key] = d
  29.         object.__setattr__(self, '__dict__', d)
  30.         cls = type(self)
  31.         if cls.__init__ is not object.__init__:
  32.             (args, kw) = object.__getattribute__(self, '_local__args')
  33.             cls.__init__(self, *args, **kw)
  34.         
  35.     else:
  36.         object.__setattr__(self, '__dict__', d)
  37.  
  38.  
  39. class local(_localbase):
  40.     
  41.     def __getattribute__(self, name):
  42.         lock = object.__getattribute__(self, '_local__lock')
  43.         lock.acquire()
  44.         
  45.         try:
  46.             _patch(self)
  47.             return object.__getattribute__(self, name)
  48.         finally:
  49.             lock.release()
  50.  
  51.  
  52.     
  53.     def __setattr__(self, name, value):
  54.         lock = object.__getattribute__(self, '_local__lock')
  55.         lock.acquire()
  56.         
  57.         try:
  58.             _patch(self)
  59.             return object.__setattr__(self, name, value)
  60.         finally:
  61.             lock.release()
  62.  
  63.  
  64.     
  65.     def __delattr__(self, name):
  66.         lock = object.__getattribute__(self, '_local__lock')
  67.         lock.acquire()
  68.         
  69.         try:
  70.             _patch(self)
  71.             return object.__delattr__(self, name)
  72.         finally:
  73.             lock.release()
  74.  
  75.  
  76.     
  77.     def __del__():
  78.         threading_enumerate = enumerate
  79.         __getattribute__ = object.__getattribute__
  80.         
  81.         def __del__(self):
  82.             key = __getattribute__(self, '_local__key')
  83.             
  84.             try:
  85.                 threads = list(threading_enumerate())
  86.             except:
  87.                 return None
  88.  
  89.             for thread in threads:
  90.                 
  91.                 try:
  92.                     __dict__ = thread.__dict__
  93.                 except AttributeError:
  94.                     continue
  95.  
  96.                 if key in __dict__:
  97.                     
  98.                     try:
  99.                         del __dict__[key]
  100.                     except KeyError:
  101.                         pass
  102.                     except:
  103.                         None<EXCEPTION MATCH>KeyError
  104.                     
  105.  
  106.                 None<EXCEPTION MATCH>KeyError
  107.             
  108.  
  109.         return __del__
  110.  
  111.     __del__ = __del__()
  112.  
  113. from threading import currentThread, enumerate, RLock
  114.