home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / protocols / interfaces.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  11.2 KB  |  358 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from __future__ import generators
  5. __all__ = [
  6.     'Protocol',
  7.     'InterfaceClass',
  8.     'Interface',
  9.     'AbstractBase',
  10.     'AbstractBaseMeta',
  11.     'IAdapterFactory',
  12.     'IProtocol',
  13.     'IAdaptingProtocol',
  14.     'IOpenProtocol',
  15.     'IOpenProvider',
  16.     'IOpenImplementor',
  17.     'IImplicationListener',
  18.     'Attribute',
  19.     'Variation']
  20. import api
  21. from advice import metamethod, classicMRO, mkRef
  22. from adapters import composeAdapters, updateWithSimplestAdapter
  23. from adapters import NO_ADAPTER_NEEDED, DOES_NOT_SUPPORT
  24. from types import InstanceType
  25.  
  26. try:
  27.     from thread import allocate_lock
  28. except ImportError:
  29.     
  30.     try:
  31.         from dummy_thread import allocate_lock
  32.     except ImportError:
  33.         
  34.         class allocate_lock(object):
  35.             __slots__ = ()
  36.             
  37.             def acquire(*args):
  38.                 pass
  39.  
  40.             
  41.             def release(*args):
  42.                 pass
  43.  
  44.  
  45.     except:
  46.         None<EXCEPTION MATCH>ImportError
  47.     
  48.  
  49.     None<EXCEPTION MATCH>ImportError
  50.  
  51.  
  52. class Protocol:
  53.     
  54.     def __init__(self):
  55.         self._Protocol__adapters = { }
  56.         self._Protocol__implies = { }
  57.         self._Protocol__listeners = None
  58.         self._Protocol__lock = allocate_lock()
  59.  
  60.     
  61.     def getImpliedProtocols(self):
  62.         out = []
  63.         add = out.append
  64.         self._Protocol__lock.acquire()
  65.         
  66.         try:
  67.             for k, v in self._Protocol__implies.items():
  68.                 proto = k()
  69.                 if proto is None:
  70.                     del self._Protocol__implies[k]
  71.                     continue
  72.                 add((proto, v))
  73.             
  74.             return out
  75.         finally:
  76.             self._Protocol__lock.release()
  77.  
  78.  
  79.     
  80.     def addImpliedProtocol(self, proto, adapter = NO_ADAPTER_NEEDED, depth = 1):
  81.         self._Protocol__lock.acquire()
  82.         
  83.         try:
  84.             key = mkRef(proto)
  85.             if not updateWithSimplestAdapter(self._Protocol__implies, key, adapter, depth):
  86.                 return self._Protocol__implies[key][0]
  87.         finally:
  88.             self._Protocol__lock.release()
  89.  
  90.         for baseAdapter, d in self._Protocol__adapters.items():
  91.             api.declareAdapterForType(proto, composeAdapters(baseAdapter, self, adapter), klass, depth + d)
  92.         
  93.         if self._Protocol__listeners:
  94.             for listener in self._Protocol__listeners.keys():
  95.                 listener.newProtocolImplied(self, proto, adapter, depth)
  96.             
  97.         
  98.         return adapter
  99.  
  100.     addImpliedProtocol = metamethod(addImpliedProtocol)
  101.     
  102.     def registerImplementation(self, klass, adapter = NO_ADAPTER_NEEDED, depth = 1):
  103.         self._Protocol__lock.acquire()
  104.         
  105.         try:
  106.             if not updateWithSimplestAdapter(self._Protocol__adapters, klass, adapter, depth):
  107.                 return self._Protocol__adapters[klass][0]
  108.         finally:
  109.             self._Protocol__lock.release()
  110.  
  111.         if adapter is DOES_NOT_SUPPORT:
  112.             return adapter
  113.         for extender, d in self.getImpliedProtocols():
  114.             api.declareAdapterForType(proto, composeAdapters(adapter, self, extender), klass, depth + d)
  115.         
  116.         return adapter
  117.  
  118.     registerImplementation = metamethod(registerImplementation)
  119.     
  120.     def registerObject(self, ob, adapter = NO_ADAPTER_NEEDED, depth = 1):
  121.         pass
  122.  
  123.     registerObject = metamethod(registerObject)
  124.     
  125.     def __adapt__(self, obj):
  126.         get = self._Protocol__adapters.get
  127.         
  128.         try:
  129.             typ = obj.__class__
  130.         except AttributeError:
  131.             typ = type(obj)
  132.  
  133.         
  134.         try:
  135.             mro = typ.__mro__
  136.         except AttributeError:
  137.             mro = classicMRO(typ, extendedClassic = True)
  138.  
  139.         for klass in mro:
  140.             factory = get(klass)
  141.             if factory is not None:
  142.                 return factory[0](obj)
  143.         
  144.  
  145.     
  146.     try:
  147.         from _speedups import Protocol__adapt__ as __adapt__
  148.     except ImportError:
  149.         pass
  150.  
  151.     __adapt__ = metamethod(__adapt__)
  152.     
  153.     def addImplicationListener(self, listener):
  154.         self._Protocol__lock.acquire()
  155.         
  156.         try:
  157.             if self._Protocol__listeners is None:
  158.                 WeakKeyDictionary = WeakKeyDictionary
  159.                 import weakref
  160.                 self._Protocol__listeners = WeakKeyDictionary()
  161.             
  162.             self._Protocol__listeners[listener] = 1
  163.         finally:
  164.             self._Protocol__lock.release()
  165.  
  166.  
  167.     addImplicationListener = metamethod(addImplicationListener)
  168.     
  169.     def __call__(self, ob, default = api._marker):
  170.         return api.adapt(ob, self, default)
  171.  
  172.  
  173.  
  174. try:
  175.     from _speedups import Protocol__call__
  176. except ImportError:
  177.     pass
  178.  
  179. from new import instancemethod
  180. Protocol.__call__ = instancemethod(Protocol__call__, None, Protocol)
  181.  
  182. class AbstractBaseMeta(Protocol, type):
  183.     
  184.     def __init__(self, __name__, __bases__, __dict__):
  185.         type.__init__(self, __name__, __bases__, __dict__)
  186.         Protocol.__init__(self)
  187.         for b in __bases__:
  188.             if isinstance(b, AbstractBaseMeta) and b.__bases__ != (object,):
  189.                 self.addImpliedProtocol(b)
  190.                 continue
  191.         
  192.  
  193.     
  194.     def __setattr__(self, attr, val):
  195.         if attr == '__bases__':
  196.             raise TypeError("Can't change interface __bases__", self)
  197.         attr == '__bases__'
  198.         type.__setattr__(self, attr, val)
  199.  
  200.     __call__ = type.__call__
  201.  
  202.  
  203. class AbstractBase(object):
  204.     __metaclass__ = AbstractBaseMeta
  205.  
  206.  
  207. class InterfaceClass(AbstractBaseMeta):
  208.     
  209.     def __call__(self, *_InterfaceClass__args, **_InterfaceClass__kw):
  210.         if self.__init__ is Interface.__init__:
  211.             return Protocol.__call__(self, *_InterfaceClass__args, **_InterfaceClass__kw)
  212.         return type.__call__(self, *_InterfaceClass__args, **_InterfaceClass__kw)
  213.  
  214.     
  215.     def getBases(self):
  216.         return _[1]
  217.  
  218.  
  219.  
  220. class Interface(object):
  221.     __metaclass__ = InterfaceClass
  222.  
  223.  
  224. class Variation(Protocol):
  225.     
  226.     def __init__(self, baseProtocol, context = None):
  227.         self.baseProtocol = baseProtocol
  228.         self.context = context
  229.         Protocol.__init__(self)
  230.         api.declareAdapterForProtocol(self, NO_ADAPTER_NEEDED, baseProtocol)
  231.  
  232.     
  233.     def __repr__(self):
  234.         if self.context is None:
  235.             return 'Variation(%r)' % self.baseProtocol
  236.         return 'Variation(%r,%r)' % (self.baseProtocol, self.context)
  237.  
  238.  
  239.  
  240. class Attribute(object):
  241.     
  242.     def __init__(self, doc, name = None, value = None):
  243.         self.__doc__ = doc
  244.         self.name = name
  245.         self.value = value
  246.  
  247.     
  248.     def __get__(self, ob, typ = None):
  249.         if ob is None:
  250.             return self
  251.         if not self.name:
  252.             raise NotImplementedError('Abstract attribute')
  253.         self.name
  254.         
  255.         try:
  256.             return ob.__dict__[self.name]
  257.         except KeyError:
  258.             ob is None
  259.             ob is None
  260.             return self.value
  261.  
  262.  
  263.     
  264.     def __set__(self, ob, val):
  265.         if not self.name:
  266.             raise NotImplementedError('Abstract attribute')
  267.         self.name
  268.         ob.__dict__[self.name] = val
  269.  
  270.     
  271.     def __delete__(self, ob):
  272.         if not self.name:
  273.             raise NotImplementedError('Abstract attribute')
  274.         self.name
  275.         del ob.__dict__[self.name]
  276.  
  277.     
  278.     def __repr__(self):
  279.         return 'Attribute: %s' % self.__doc__
  280.  
  281.  
  282.  
  283. class IAdapterFactory(Interface):
  284.     
  285.     def __call__(ob):
  286.         pass
  287.  
  288.  
  289.  
  290. class IProtocol(Interface):
  291.     
  292.     def __hash__():
  293.         pass
  294.  
  295.     
  296.     def __eq__(other):
  297.         pass
  298.  
  299.     
  300.     def __ne__(other):
  301.         pass
  302.  
  303.  
  304.  
  305. class IAdaptingProtocol(IProtocol):
  306.     
  307.     def __adapt__(ob):
  308.         pass
  309.  
  310.  
  311.  
  312. class IConformingObject(Interface):
  313.     
  314.     def __conform__(protocol):
  315.         pass
  316.  
  317.  
  318.  
  319. class IOpenProvider(Interface):
  320.     
  321.     def declareProvides(protocol, adapter = NO_ADAPTER_NEEDED, depth = 1):
  322.         pass
  323.  
  324.  
  325.  
  326. class IOpenImplementor(Interface):
  327.     
  328.     def declareClassImplements(protocol, adapter = NO_ADAPTER_NEEDED, depth = 1):
  329.         pass
  330.  
  331.  
  332.  
  333. class IOpenProtocol(IAdaptingProtocol):
  334.     
  335.     def addImpliedProtocol(proto, adapter = NO_ADAPTER_NEEDED, depth = 1):
  336.         pass
  337.  
  338.     
  339.     def registerImplementation(klass, adapter = NO_ADAPTER_NEEDED, depth = 1):
  340.         pass
  341.  
  342.     
  343.     def registerObject(ob, adapter = NO_ADAPTER_NEEDED, depth = 1):
  344.         pass
  345.  
  346.     
  347.     def addImplicationListener(listener):
  348.         pass
  349.  
  350.  
  351.  
  352. class IImplicationListener(Interface):
  353.     
  354.     def newProtocolImplied(srcProto, destProto, adapter, depth):
  355.         pass
  356.  
  357.  
  358.