home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / pyxmpp / interface_micro_impl.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  4.2 KB  |  144 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. __revision__ = '$Id: utils.py 647 2006-08-26 18:27:39Z jajcus $'
  5. __docformat__ = 'restructuredtext en'
  6. import sys
  7. from types import FunctionType
  8.  
  9. def classImplements(cls, *interfaces):
  10.     if not isinstance(cls, classobj):
  11.         raise TypeError, '%r is not a class'
  12.     isinstance(cls, classobj)
  13.     for interface in interfaces:
  14.         if not isinstance(interface, InterfaceClass):
  15.             raise TypeError, 'Only interfaces may be implemented'
  16.         isinstance(interface, InterfaceClass)
  17.     
  18.     cls.__implemented__ = tuple(interfaces)
  19.  
  20.  
  21. def implements(*interfaces):
  22.     for interface in interfaces:
  23.         if not isinstance(interface, InterfaceClass):
  24.             raise TypeError, 'Only interfaces may be implemented'
  25.         isinstance(interface, InterfaceClass)
  26.     
  27.     frame = sys._getframe(1)
  28.     locals = frame.f_locals
  29.     if locals is frame.f_globals or '__module__' not in locals:
  30.         raise TypeError, 'implements() may only be used in a class definition'
  31.     '__module__' not in locals
  32.     if '__implemented__' in locals:
  33.         raise TypeError, 'implements() may be used only once'
  34.     '__implemented__' in locals
  35.     locals['__implemented__'] = tuple(interfaces)
  36.  
  37.  
  38. def _whole_tree(cls):
  39.     yield cls
  40.     for base in cls.__bases__:
  41.         for b in _whole_tree(base):
  42.             yield b
  43.         
  44.     
  45.  
  46.  
  47. def implementedBy(cls):
  48.     
  49.     try:
  50.         for interface in cls.__implemented__:
  51.             for c in _whole_tree(interface):
  52.                 yield c
  53.             
  54.     except AttributeError:
  55.         pass
  56.  
  57.     for base in cls.__bases__:
  58.         for interface in implementedBy(base):
  59.             yield interface
  60.         
  61.     
  62.  
  63.  
  64. def providedBy(ob):
  65.     
  66.     try:
  67.         for interface in ob.__provides__:
  68.             yield interface
  69.     except AttributeError:
  70.         
  71.         try:
  72.             for interface in implementedBy(ob.__class__):
  73.                 yield interface
  74.         except AttributeError:
  75.             return None
  76.         
  77.  
  78.         None<EXCEPTION MATCH>AttributeError
  79.  
  80.  
  81.  
  82. class InterfaceClass(object):
  83.     
  84.     def __init__(self, name, bases = (), attrs = None, __doc__ = None, __module__ = None):
  85.         if __module__ is None:
  86.             if attrs is not None and '__module__' in attrs and isinstance(attrs['__module__'], str):
  87.                 __module__ = attrs['__module__']
  88.                 del attrs['__module__']
  89.             else:
  90.                 __module__ = sys._getframe(1).f_globals['__name__']
  91.         
  92.         if __doc__ is not None:
  93.             self.__doc__ = __doc__
  94.         
  95.         if attrs is not None and '__doc__' in attrs:
  96.             del attrs['__doc__']
  97.         
  98.         self.__module__ = __module__
  99.         for base in bases:
  100.             if not isinstance(base, InterfaceClass):
  101.                 raise TypeError, 'Interface bases must be Interfaces'
  102.             isinstance(base, InterfaceClass)
  103.         
  104.         if attrs is not None:
  105.             for aname, attr in attrs.items():
  106.                 if not isinstance(attr, Attribute) and type(attr) is not FunctionType:
  107.                     raise TypeError, 'Interface attributes must be Attributes o functions (%r found in %s)' % (attr, aname)
  108.                 type(attr) is not FunctionType
  109.             
  110.         
  111.         self.__bases__ = bases
  112.         self._InterfaceClass__attrs = attrs
  113.         self.__name__ = name
  114.         self.__identifier__ = '%s.%s' % (self.__module__, self.__name__)
  115.  
  116.     
  117.     def providedBy(self, ob):
  118.         if self in providedBy(ob):
  119.             return True
  120.         return False
  121.  
  122.     
  123.     def implementedBy(self, cls):
  124.         return self in implementedBy(cls)
  125.  
  126.     
  127.     def __repr__(self):
  128.         name = self.__name__
  129.         module = self.__module__
  130.         if module and module != '__main__':
  131.             name = '%s.%s' % (module, name)
  132.         
  133.         return '<%s %s>' % (self.__class__.__name__, name)
  134.  
  135.  
  136.  
  137. class Attribute(object):
  138.     
  139.     def __init__(self, doc):
  140.         self.__doc__ = doc
  141.  
  142.  
  143. Interface = InterfaceClass('Interface', __module__ = 'pyxmpp.inteface_micro_impl')
  144.