o ö]Lbfã@s€dZddlmZddlmZzddlmZWn ey!dZYnwdZddlZdd „Z dd d „Z d d„Z ddd„Z dd„Z dS)ajClass advice. This module was adapted from 'protocols.advice', part of the Python Enterprise Application Kit (PEAK). Please notify the PEAK authors (pje@telecommunity.com and tsarna@sarna.org) if bugs are found or Zope-specific changes are required, so that the PEAK version of this module can be kept in sync. PEAK is a Python application framework that interoperates with (but does not require) Zope 3 and Twisted. It provides tools for manipulating UML models, object-relational persistence, aspect-oriented programming, and more. Visit the PEAK home page at http://peak.telecommunity.com for more information. é)Úabsolute_import)Ú FunctionType©Ú ClassTypeTFNc Cs¦|j}|j}||u}d|v}d|v}|o|}|o|d|dk}|r*tj |d¡p+d}|o2|j|u}|s8d} n|r?|s?d} n|rF|sFd} n|sKd} nd} | |||fS) z„Return (kind,module,locals,globals) for a frame 'kind' is one of "exec", "module", "class", "function call", or "unknown". Ú __module__Ú__name__NÚexecÚmoduleÚclassz function callÚunknown)Úf_localsÚ f_globalsÚsysÚmodulesÚgetÚ__dict__) Úframer r Ú sameNamespaceÚ hasModuleÚhasNameÚsameNamer ÚnamespaceIsModuleÚkind©rúL/usr/lib/python3/dist-packages/mercurial/thirdparty/zope/interface/advice.pyÚ getFrameInfo(s& récsvtrtdƒ‚t |¡}t|ƒ\}}}}| d¡‰tr!| dt¡‰n| dt¡‰‡‡‡fdd„}ˆ|_ˆ|_ ||d<dS)a2Set up 'callback' to be passed the containing class upon creation This function is designed to be called by an "advising" function executed in a class suite. The "advising" function supplies a callback that it wishes to have executed when the containing class is created. The callback will be given one argument: the newly created containing class. The return value of the callback will be used in place of the class, so the callback should return the input if it does not wish to replace the class. The optional 'depth' argument to this function determines the number of frames between this function and the targeted class suite. 'depth' defaults to 2, since this skips this function's frame and one calling function frame. If you use this function from a function called directly in the class suite, the default will be correct, otherwise you will need to determine the correct depth yourself. This function works by installing a special class factory function in place of the '__metaclass__' of the containing class. Therefore, only callbacks *after* the last '__metaclass__' assignment in the containing class will be executed. Be sure that classes using "advising" functions declare any '__metaclass__' *first*, to ensure all callbacks are run.z"Class advice impossible in Python3Ú __metaclass__csVd|vr|d=ˆdur|rt|ƒ}nˆ}n tˆƒrˆ}nt|ˆƒ}||||ƒ}ˆ|ƒS)Nr)ÚdetermineMetaclassÚisClassAdvisor)ÚnameÚbasesÚcdictÚmetaÚnewClass©ÚcallbackÚdefaultMetaclassÚpreviousMetaclassrrÚadvisezs   zaddClassAdvisor..adviseN) Ú __python3Ú TypeErrorrÚ _getframerrÚtyperr(r&)r&Údepthrrr Ú caller_localsÚcaller_globalsr)rr%rÚaddClassAdvisorLs    r1cCst|tƒo t|dƒS)z(True if 'ob' is a class advisor functionr()Ú isinstancerÚhasattr)ÚobrrrrœsrcCsjdd„|Dƒ}|dur| |¡t|ƒdkr|dSt|ƒ}|s&tr$J‚tSt|ƒdkr1td|ƒ‚|dS)zEDetermine metaclass from 1+ bases and optional explicit __metaclass__cSsg|] }t|dt|ƒƒ‘qS)Ú __class__)Úgetattrr-)Ú.0ÚbrrrÚ ¤sz&determineMetaclass..NérzIncompatible metatypes)ÚappendÚlenÚ minimalBasesr*rr+)r!Ú explicit_mcr#Ú candidatesrrrr¡s    rcCs`ts dd„|Dƒ}g}|D] }|D] }t||ƒr||urnq||vr(| |¡| |¡q |S)z?Reduce a list of base classes to its ordered minimum equivalentcSsg|]}|tur|‘qSrr)r7Úcrrrr9Âsz minimalBases..)r*Ú issubclassÚremover;)Úclassesr?ÚmÚnrrrr=¾s€  €r=)r)N)Ú__doc__Ú __future__rÚtypesrrÚ ImportErrorr*rrr1rrr=rrrrÚs   ÿ $P