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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from __future__ import generators
  5. from new import instancemethod
  6. from types import ClassType, FunctionType, InstanceType
  7. import sys
  8. __all__ = [
  9.     'metamethod',
  10.     'supermeta',
  11.     'getMRO',
  12.     'classicMRO',
  13.     'mkRef',
  14.     'StrongRef',
  15.     'addClassAdvisor',
  16.     'isClassAdvisor',
  17.     'add_assignment_advisor',
  18.     'determineMetaclass',
  19.     'getFrameInfo',
  20.     'minimalBases']
  21. from peak.util import decorators
  22.  
  23. def addClassAdvisor(callback, depth = 2, frame = None):
  24.     warn = warn
  25.     import warnings
  26.     warn(addClassAdvisor.__doc__, DeprecationWarning, 2)
  27.     if not depth:
  28.         pass
  29.     return decorators.decorate_class(callback, 0 + 1, frame)
  30.  
  31.  
  32. def add_assignment_advisor(callback, depth = 2, frame = None):
  33.     warn = warn
  34.     import warnings
  35.     warn(add_assignment_advisor.__doc__, DeprecationWarning, 2)
  36.     if not depth:
  37.         pass
  38.     return decorators.decorate_assignment(callback, 0 + 1, frame)
  39.  
  40.  
  41. def getFrameInfo(frame):
  42.     warn = warn
  43.     import warnings
  44.     warn(getFrameInfo.__doc__, DeprecationWarning, 2)
  45.     return decorators.frameinfo(frame)
  46.  
  47.  
  48. def determineMetaclass(bases, explicit_mc = None):
  49.     warn = warn
  50.     import warnings
  51.     warn(determineMetaclass.__doc__, DeprecationWarning, 2)
  52.     return decorators.metaclass_for_bases(bases, explicit_mc)
  53.  
  54.  
  55. def isClassAdvisor(ob):
  56.     warn = warn
  57.     import warnings
  58.     warn(isClassAdvisor.__doc__, DeprecationWarning, 2)
  59.     return decorators.metaclass_is_decorator(ob)
  60.  
  61.  
  62. def metamethod(func):
  63.     return (property,)((lambda ob: func.__get__(ob, ob.__class__)))
  64.  
  65.  
  66. try:
  67.     from ExtensionClass import ExtensionClass
  68. except ImportError:
  69.     ClassicTypes = ClassType
  70.  
  71. ClassicTypes = (ClassType, ExtensionClass)
  72.  
  73. def classicMRO(ob, extendedClassic = False):
  74.     stack = []
  75.     push = stack.insert
  76.     pop = stack.pop
  77.     push(0, ob)
  78.     while stack:
  79.         cls = pop()
  80.         yield cls
  81.         p = len(stack)
  82.         for b in cls.__bases__:
  83.             push(p, b)
  84.         
  85.     if extendedClassic:
  86.         yield InstanceType
  87.         yield object
  88.     
  89.  
  90.  
  91. def getMRO(ob, extendedClassic = False):
  92.     if isinstance(ob, ClassicTypes):
  93.         return classicMRO(ob, extendedClassic)
  94.     if isinstance(ob, type):
  95.         return ob.__mro__
  96.     return (ob,)
  97.  
  98.  
  99. try:
  100.     from _speedups import metamethod, getMRO, classicMRO
  101. except ImportError:
  102.     pass
  103.  
  104.  
  105. def supermeta(typ, ob):
  106.     starttype = type(ob)
  107.     mro = starttype.__mro__
  108.     if typ not in mro:
  109.         starttype = ob
  110.         mro = starttype.__mro__
  111.     
  112.     mro = iter(mro)
  113.     for cls in mro:
  114.         if cls is typ:
  115.             mro = [ cls.__dict__ for cls in mro ]
  116.             break
  117.             continue
  118.         []
  119.     else:
  120.         raise TypeError('Not sub/supertypes:', starttype, typ)
  121.     typ = [](ob)
  122.     
  123.     class theSuper(None, 'theSuper', (object,)):
  124.         
  125.         def __getattribute__(self, name):
  126.             for d in mro:
  127.                 if name in d:
  128.                     descr = d[name]
  129.                     
  130.                     try:
  131.                         descr = descr.__get__
  132.                     except AttributeError:
  133.                         return descr
  134.  
  135.                     return descr(ob, typ)
  136.                 name in d
  137.             
  138.             return object.__getattribute__(self, name)
  139.  
  140.  
  141.     return theSuper()
  142.  
  143.  
  144. def minimalBases(classes):
  145.     warn = warn
  146.     import warnings
  147.     warn('protocols.advice.minimalBases is deprecated; please do not use it', DeprecationWarning, 2)
  148.     classes = _[1]
  149.     candidates = []
  150.     for m in classes:
  151.         for n in classes:
  152.             if issubclass(n, m) and m is not n:
  153.                 break
  154.                 continue
  155.             []
  156.         elif m in candidates:
  157.             candidates.remove(m)
  158.         
  159.         candidates.append(m)
  160.     
  161.     return candidates
  162.  
  163. from weakref import ref
  164.  
  165. class StrongRef(object):
  166.     __slots__ = 'referent'
  167.     
  168.     def __init__(self, referent):
  169.         self.referent = referent
  170.  
  171.     
  172.     def __call__(self):
  173.         return self.referent
  174.  
  175.     
  176.     def __hash__(self):
  177.         return hash(self.referent)
  178.  
  179.     
  180.     def __eq__(self, other):
  181.         return self.referent == other
  182.  
  183.     
  184.     def __repr__(self):
  185.         return 'StrongRef(%r)' % self.referent
  186.  
  187.  
  188.  
  189. def mkRef(ob, *args):
  190.     
  191.     try:
  192.         return ref(ob, *args)
  193.     except TypeError:
  194.         return StrongRef(ob)
  195.  
  196.  
  197.