home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / protocols / zope_support.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  3.8 KB  |  110 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. __all__ = []
  5. from types import ClassType
  6. from adapters import *
  7. from api import declareImplementation, advise, adapt
  8. from interfaces import IOpenProtocol, Protocol
  9. from advice import metamethod, supermeta
  10.  
  11. try:
  12.     import zope.interface as zi
  13. except ImportError:
  14.     ZopeInterfaceTypes = []
  15.     zi = None
  16.  
  17.  
  18. def __adapt__(self, obj):
  19.     return adapt(self, IOpenProtocol).__adapt__(obj)
  20.  
  21.  
  22. try:
  23.     from zope.interface import adapter_hooks
  24. except ImportError:
  25.     
  26.     try:
  27.         from zope.interface.interface import adapter_hooks
  28.     except ImportError:
  29.         zi.Interface.__class__.__adapt__ = __adapt__
  30.         adapter_hooks = []
  31.     except:
  32.         None<EXCEPTION MATCH>ImportError
  33.     
  34.  
  35.     None<EXCEPTION MATCH>ImportError
  36.  
  37. adapter_hooks.append(__adapt__)
  38. ZopeInterfaceTypes = [
  39.     zi.Interface.__class__]
  40. del __adapt__
  41. del adapter_hooks
  42.  
  43. class ZopeInterfaceAsProtocol(StickyAdapter, Protocol):
  44.     advise(instancesProvide = [
  45.         IOpenProtocol], asAdapterForTypes = ZopeInterfaceTypes)
  46.     attachForProtocols = (IOpenProtocol,)
  47.     
  48.     def __init__(self, ob):
  49.         StickyAdapter.__init__(self, ob)
  50.         Protocol.__init__(self)
  51.  
  52.     if ZopeInterfaceTypes and hasattr(ZopeInterfaceTypes[0], 'providedBy'):
  53.         
  54.         def __adapt__(self, obj):
  55.             if self.subject.providedBy(obj):
  56.                 return obj
  57.             
  58.             return supermeta(ZopeInterfaceAsProtocol, self).__adapt__(obj)
  59.  
  60.     else:
  61.         
  62.         def __adapt__(self, obj):
  63.             if self.subject.isImplementedBy(obj):
  64.                 return obj
  65.             
  66.             return supermeta(ZopeInterfaceAsProtocol, self).__adapt__(obj)
  67.  
  68.     
  69.     def registerImplementation(self, klass, adapter = NO_ADAPTER_NEEDED, depth = 1):
  70.         if adapter is NO_ADAPTER_NEEDED:
  71.             zi.classImplements(klass, self.subject)
  72.         elif adapter is DOES_NOT_SUPPORT:
  73.             ifaces = []([ i.__iro__ for i in zi.implementedBy(klass) ]) - self.subject
  74.             zi.classImplementsOnly(klass, ifaces)
  75.         
  76.         return supermeta(ZopeInterfaceAsProtocol, self).registerImplementation(klass, adapter, depth)
  77.  
  78.     registerImplementation = metamethod(registerImplementation)
  79.     
  80.     def registerObject(self, ob, adapter = NO_ADAPTER_NEEDED, depth = 1):
  81.         if adapter is NO_ADAPTER_NEEDED:
  82.             zi.directlyProvides(ob, self.subject)
  83.         elif adapter is DOES_NOT_SUPPORT:
  84.             zi.directlyProvides(ob, zi.directlyProvidedBy(ob) - self.subject)
  85.         
  86.         return supermeta(ZopeInterfaceAsProtocol, self).registerObject(ob, adapter, depth)
  87.  
  88.     registerObject = metamethod(registerObject)
  89.     
  90.     def getImpliedProtocols(self):
  91.         protos = super(ZopeInterfaceAsProtocol, self).getImpliedProtocols()
  92.         return [] + _[1]
  93.  
  94.     
  95.     def __getstate__(self):
  96.         state = self.__dict__.copy()
  97.         del state['_Protocol__lock']
  98.         del state['_Protocol__listeners']
  99.         return state
  100.  
  101.     
  102.     def __hash__(self):
  103.         return hash(self.subject)
  104.  
  105.     
  106.     def __cmp__(self, other):
  107.         return cmp(self.subject, other)
  108.  
  109.  
  110.