U
    j5{iN  ã                   @   sJ   d Z ddlmZ ddddgZddlZdd„ Zd	d„ Zdd
d„Zdd„ ZdS )aj  Class 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.
é    )ÚFunctionTypeÚdetermineMetaclassÚgetFrameInfoÚisClassAdvisorÚminimalBasesNc           
      C   s¦   | j }| j}||k}d|k}d|k}|o*|}|o>|d |d k}|rTtj |d ¡pVd}|od|j|k}|spd}	n*|r~|s~d}	n|rŒ|sŒd}	n|s–d}	nd}	|	|||fS )	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   ZsameNamespaceZ	hasModuleZhasNameZsameNamer
   ZnamespaceIsModuleÚkind© r   ú9/tmp/pip-unpacked-wheel-jkvlexts/zope/interface/advice.pyr   )   s&    c                 C   s   t | tƒot| dƒS )z(True if 'ob' is a class advisor functionZpreviousMetaclass)Ú
isinstancer   Úhasattr)Úobr   r   r   r   N   s    c                 C   sZ   dd„ | D ƒ}|dk	r |  |¡ t|ƒdkr4|d S t|ƒ}t|ƒdkrRtd| ƒ‚|d S )zEDetermine metaclass from 1+ bases and optional explicit __metaclass__c                 S   s   g | ]}t |d t|ƒƒ‘qS )Ú	__class__)ÚgetattrÚtype)Ú.0Úbr   r   r   Ú
<listcomp>V   s     z&determineMetaclass.<locals>.<listcomp>Né   r   zIncompatible metatypes)ÚappendÚlenr   Ú	TypeError)ÚbasesZexplicit_mcÚmetaÚ
candidatesr   r   r   r   S   s    

c                 C   sN   g }| D ]@}| D ]}t ||ƒr||k	r qq||kr>| |¡ | |¡ q|S )z?Reduce a list of base classes to its ordered minimum equivalent)Ú
issubclassÚremover!   )Úclassesr&   ÚmÚnr   r   r   r   k   s    
)N)	Ú__doc__Útypesr   Ú__all__r   r   r   r   r   r   r   r   r   Ú<module>   s   ü%
