a
    jCiš  ã                   @   sê   d dl Z d dlmZmZ g d¢Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	e
ƒ ZG dd„ dƒZG dd„ deƒZdZG dd„ deƒZG dd„ ded�ZG dd„ deeƒZdd„ ZG dd„ deƒZG dd„ deeƒZdd „ Zd!d"„ Zd#d$„ ZdS )%é    N)ÚMappingProxyTypeÚDynamicClassAttribute)ÚEnumMetaÚEnumÚIntEnumÚFlagÚIntFlagÚautoÚuniquec                 C   s   t | dƒpt | dƒpt | dƒS )z?
    Returns True if obj is a descriptor, False otherwise.
    Ú__get__Ú__set__Ú
__delete__)Úhasattr)Úobj© r   ú /usr/local/lib/python3.9/enum.pyÚ_is_descriptor   s
    
ÿýr   c                 C   sL   t | ƒdkoJ| dd… | dd…   ko.dkn  oJ| d dkoJ| d dkS )z=
    Returns True if a __dunder__ name, False otherwise.
    é   Né   éþÿÿÿÚ__Ú_éýÿÿÿ©Úlen©Únamer   r   r   Ú
_is_dunder   s    &ÿ
þ
ür   c                 C   sL   t | ƒdkoJ| d | d   ko&dkn  oJ| dd… dkoJ| dd… dkS )z;
    Returns True if a _sunder_ name, False otherwise.
    r   r   éÿÿÿÿr   é   r   r   r   r   r   r   Ú
_is_sunder!   s    ÿþür    c                 C   sT   d| f }t |ƒdkrL| |¡rL|t |ƒ dkrL|d dksH|d dkrLdS dS d S )Nz_%s__é   r   r   r   TF)r   Ú
startswith)Zcls_namer   Úpatternr   r   r   Ú_is_private,   s    

ÿþý
ü
ür$   c                 C   s   dd„ }|| _ d| _dS )z,
    Make the given class un-picklable.
    c                 S   s   t d|  ƒ‚d S )Nz%r cannot be pickled)Ú	TypeError©ÚselfZprotor   r   r   Ú_break_on_call_reduce=   s    z6_make_class_unpicklable.<locals>._break_on_call_reducez	<unknown>N)Ú__reduce_ex__Ú
__module__)Úclsr(   r   r   r   Ú_make_class_unpicklable9   s    r,   c                   @   s   e Zd ZdZeZdS )r	   zP
    Instances are replaced with an appropriate value in Enum class suites.
    N)Ú__name__r*   Ú__qualname__Ú__doc__Ú
_auto_nullÚvaluer   r   r   r   r	   C   s   r	   c                       s,   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡  ZS )Ú	_EnumDictz«
    Track enum member order and ensure member names are not reused.

    EnumMeta will use the names found in self._member_names as the
    enumeration member names.
    c                    s&   t ƒ  ¡  g | _g | _g | _d| _d S )NF)ÚsuperÚ__init__Ú_member_namesÚ_last_valuesÚ_ignoreÚ_auto_called©r'   ©Ú	__class__r   r   r4   Q   s
    
z_EnumDict.__init__c                    s�  t | j|ƒr*ddl}|jd|f tdd� t|ƒr¾|dvrBtdƒ‚|dkrf| jrXtd	ƒ‚t	| d
|ƒ nV|dkr¼t
|tƒrŠ| dd¡ ¡ }nt|ƒ}|| _t|ƒt| jƒ@ }|r¼td|f ƒ‚nÀt|ƒrÔ|dkrÒd}nª|| jv rìtd| ƒ‚n’|| jv røn†t|ƒ�s~|| v �r td|| | f ƒ‚t
|tƒ�rf|jtk�r`|  |dt| jƒ| jdd… ¡|_d| _|j}| j |¡ | j |¡ tƒ  ||¡ dS )zí
        Changes anything not dundered or not a descriptor.

        If an enum member name is used twice, an error is raised; duplicate
        values are not checked for.

        Single underscore (sunder) names are reserved.
        r   Nz@private variables, such as %r, will be normal attributes in 3.10r   )Ú
stacklevel)Ú_order_Ú_create_pseudo_member_Ú_generate_next_value_Ú	_missing_Ú_ignore_z(_names_ are reserved for future Enum user?   z4_generate_next_value_ must be defined before membersÚ_generate_next_valuerA   ú,ú z-_ignore_ cannot specify already set names: %rZ	__order__r=   zAttempted to reuse key: %rz%r already defined as: %rr   T)r$   Ú	_cls_nameÚwarningsÚwarnÚDeprecationWarningr    Ú
ValueErrorr8   r%   ÚsetattrÚ
isinstanceÚstrÚreplaceÚsplitÚlistr7   Úsetr5   r   r   r	   r1   r0   rB   r   r6   Úappendr3   Ú__setitem__)r'   Úkeyr1   rF   Zalreadyr:   r   r   rR   X   sf    	ÿü
ÿÿ



üz_EnumDict.__setitem__)r-   r*   r.   r/   r4   rR   Ú__classcell__r   r   r:   r   r2   J   s   r2   c                       sð   e Zd ZdZedd„ ƒZ‡ fdd„Zdd„ Zd-dddd	d
œdd„Zdd„ Z	‡ fdd„Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZdd„ Zdd „ Z‡ fd!d"„Zdddd	d
œd#d$„Zd.d%d&„Zed'd(„ ƒZed)d*„ ƒZed+d,„ ƒZ‡  ZS )/r   z
    Metaclass for Enum
    c                 K   sD   |   ||¡ tƒ }||_|  ||¡\}}|d ur@t|dd ƒ|d< |S )Nr?   )Ú_check_for_existing_membersr2   rE   Ú_get_mixins_Úgetattr)Úmetaclsr+   ÚbasesÚkwdsZ	enum_dictÚmember_typeÚ
first_enumr   r   r   Ú__prepare__¤   s    ÿzEnumMeta.__prepare__c              	      s¸  ˆ  dg ¡ d¡ ˆd }|D ]}ˆ |d ¡ q|  ||¡\‰}|  ˆˆ|¡\}}	}
‡fdd„ˆjD ƒ}ˆjD ]
}ˆ|= qnˆ dd ¡}t|ƒddh@ }|r®td d 	|¡¡ƒ‚d	ˆvr¾d
ˆd	< t
ƒ j| ||ˆfi |¤Ž}g |_i |_ˆ|_dd„ | ¡ D ƒ}i |_dˆv�rÌˆtu�rÌd}t‡fdd„|D ƒƒ�sÌdˆv �rFt|ƒ n†d }|D ]n}|jD ]P‰ ˆ tu �rl�qXn:t‡ fdd„|D ƒƒ�r�d} �qªndˆ jv �rXd} �qª�qX|d u�rN �q¾�qN|�rÌt|ƒ ˆjD �]*}|| }t|tƒ�sô|f}n|}ˆtu �r|f}|
�s*||ƒ}t|dƒ�sb||_n8||g|¢R Ž }t|dƒ�sbˆtu �rX||_n
ˆ|Ž |_|j}||_||_|j|Ž  |j ¡ D ]"\}}|j|jk�rˆ|} �q¸�qˆ|j |¡ ||v�rÎt|||ƒ ||j|< z||j|< W n t�yú   Y n0 �qÒdD ]V}|ˆv �r�qt ||ƒ}t ˆ|d ƒ}t ||d ƒ}|d u�r||u �rt|||ƒ �qt!d u�rz|	�rr||_"t!j|_|d u�r´t|t#ƒ�r | $dd¡ %¡ }||jk�r´tdƒ‚|S )NrA   c                    s   i | ]}|ˆ | “qS r   r   )Ú.0Úk)Ú	classdictr   r   Ú
<dictcomp>Å   ó    z$EnumMeta.__new__.<locals>.<dictcomp>r=   ÚmroÚ zInvalid enum member name: {0}rC   r/   zAn enumeration.c                 S   s.   h | ]&}|j  ¡ D ]\}}t|tƒr|’qqS r   )Ú__dict__ÚitemsrK   r   )r^   Úcr_   Úvr   r   r   Ú	<setcomp>Ý   s   
þz#EnumMeta.__new__.<locals>.<setcomp>r)   )Z__getnewargs_ex__Ú__getnewargs__r)   Ú
__reduce__c                 3   s   | ]}|ˆ j v V  qd S ©N©re   ©r^   Úm)r[   r   r   Ú	<genexpr>ô   rb   z#EnumMeta.__new__.<locals>.<genexpr>Ú__new__c                 3   s   | ]}|ˆ j v V  qd S rl   rm   rn   )Úbaser   r   rp     rb   FTÚ_value_)Ú__repr__Ú__str__Ú
__format__r)   rD   z#member order does not match _order_)&Ú
setdefaultrQ   ÚpoprV   Ú
_find_new_r5   rP   rI   ÚformatÚjoinr3   rq   Ú_member_names_Ú_member_map_Ú_member_type_rc   Ú_value2member_map_ÚobjectÚanyr,   Ú__mro__re   rK   Útupler   rs   Ú_name_Ú__objclass__r4   rf   rJ   r%   rW   r   Ú__new_member__rL   rM   rN   )rX   r+   rY   r`   rZ   ÚignorerS   r\   rq   Úsave_newÚuse_argsZenum_membersr   r=   Zinvalid_namesÚ
enum_classZdynamic_attributesÚmethodsZsabotageÚchainÚmember_namer1   ÚargsZenum_memberZcanonical_memberZclass_methodZ
obj_methodZenum_methodr:   )rr   r`   r[   r   rq   ³   sÄ    ÿ

ÿÿ




















zEnumMeta.__new__c                 C   s   dS )z6
        classes/types should always be True.
        Tr   r9   r   r   r   Ú__bool__`  s    zEnumMeta.__bool__Nr   ©ÚmoduleÚqualnameÚtypeÚstartc                C   s*   |du r|   | |¡S | j||||||d�S )a!  
        Either returns an existing member, or creates a new enum class.

        This method is used both when an enum class is given a value to match
        to an enumeration member (i.e. Color(3)) and for the functional API
        (i.e. Color = Enum('Color', names='RED GREEN BLUE')).

        When used for the functional API:

        `value` will be the name of the new class.

        `names` should be either a string of white-space/comma delimited names
        (values will start at `start`), or an iterator/mapping of name, value pairs.

        `module` should be set to the module this class is being created in;
        if it is not set, an attempt to find that module will be made, but if
        it fails the class will not be picklable.

        `qualname` should be set to the actual location this class can be found
        at in its module; by default it is set to the global scope.  If this is
        not correct, unpickling will fail in some circumstances.

        `type`, if set, will be mixed in as the first base class.
        Nr�   )rq   Ú_create_)r+   r1   Únamesr‘   r’   r“   r”   r   r   r   Ú__call__f  s    úzEnumMeta.__call__c                 C   s:   t |tƒs$tdt|ƒj| jjf ƒ‚t || ƒo8|j| jv S )Nú3unsupported operand type(s) for 'in': '%s' and '%s')rK   r   r%   r“   r.   r;   r„   r}   )r+   Úmemberr   r   r   Ú__contains__‹  s    
ÿÿzEnumMeta.__contains__c                    s(   || j v rtd| j ƒ‚tƒ  |¡ d S )Nz%s: cannot delete Enum member.)r}   ÚAttributeErrorr-   r3   Ú__delattr__)r+   Úattrr:   r   r   rœ   ’  s    
zEnumMeta.__delattr__c                 C   s   g d¢| j  S )N)r;   r/   Ú__members__r*   ©r|   r9   r   r   r   Ú__dir__™  s    ÿÿzEnumMeta.__dir__c                 C   s>   t |ƒrt|ƒ‚z| j| W S  ty8   t|ƒd‚Y n0 dS )a=  
        Return the enum member matching `name`

        We use __getattr__ instead of descriptors or inserting into the enum
        class' __dict__ in order to support `name` and `value` being both
        properties for enum members (which live in the class' __dict__) and
        enum members themselves.
        N)r   r›   r}   ÚKeyError©r+   r   r   r   r   Ú__getattr__Ÿ  s    	zEnumMeta.__getattr__c                 C   s
   | j | S rl   ©r}   r¢   r   r   r   Ú__getitem__¯  s    zEnumMeta.__getitem__c                    s   ‡ fdd„ˆ j D ƒS )z6
        Returns members in definition order.
        c                 3   s   | ]}ˆ j | V  qd S rl   r¤   ©r^   r   ©r+   r   r   rp   ¶  rb   z$EnumMeta.__iter__.<locals>.<genexpr>rŸ   r§   r   r§   r   Ú__iter__²  s    zEnumMeta.__iter__c                 C   s
   t | jƒS rl   )r   r|   r§   r   r   r   Ú__len__¸  s    zEnumMeta.__len__c                 C   s
   t | jƒS )z¿
        Returns a mapping of member name->value.

        This mapping lists all enum members, including aliases. Note that this
        is a read-only view of the internal mapping.
        )r   r}   r§   r   r   r   rž   »  s    zEnumMeta.__members__c                 C   s
   d| j  S )Nz	<enum %r>)r-   r§   r   r   r   rt   Å  s    zEnumMeta.__repr__c                    s   ‡ fdd„t ˆ jƒD ƒS )z>
        Returns members in reverse definition order.
        c                 3   s   | ]}ˆ j | V  qd S rl   r¤   r¦   r§   r   r   rp   Ì  rb   z(EnumMeta.__reversed__.<locals>.<genexpr>)Úreversedr|   r§   r   r§   r   Ú__reversed__È  s    zEnumMeta.__reversed__c                    s0   | j  di ¡}||v rtdƒ‚tƒ  ||¡ dS )a  
        Block attempts to reassign Enum members.

        A simple assignment to the class namespace only changes one of the
        several possible ways to get an Enum member from the Enum class,
        resulting in an inconsistent Enumeration.
        r}   zCannot reassign members.N)re   Úgetr›   r3   Ú__setattr__)r+   r   r1   Z
member_mapr:   r   r   r­   Î  s    zEnumMeta.__setattr__c             
   C   sn  | j }|du r| fn|| f}|  | |¡\}	}
| ||¡}t|tƒrR| dd¡ ¡ }t|ttfƒrÂ|rÂt|d tƒrÂ|g  }}g }t	|ƒD ]8\}}|
 
||||dd… ¡}| |¡ | ||f¡ qˆ|D ].}t|tƒrä|||  }}n|\}}|||< qÆ| ||||¡}|du �r@zt d¡jd }W n tttf�y>   Y n0 |du �rTt|ƒ n||_|du�rj||_|S )a�  
        Convenience method to create a new Enum class.

        `names` can be:

        * A string containing member names, separated either with spaces or
          commas.  Values are incremented by 1 from `start`.
        * An iterable of member names.  Values are incremented by 1 from `start`.
        * An iterable of (member name, value) pairs.
        * A mapping of member name -> value pairs.
        NrC   rD   r   r   r-   )r;   rV   r]   rK   rL   rM   rN   rƒ   rO   Ú	enumerater?   rQ   rq   ÚsysÚ	_getframeÚ	f_globalsr›   rI   r¡   r,   r*   r.   )r+   Ú
class_namer–   r‘   r’   r“   r”   rX   rY   r   r\   r`   Zoriginal_namesÚlast_valuesÚcountr   r1   Úitemr�   Úmember_valuerŠ   r   r   r   r•   Û  s<    
 







zEnumMeta._create_c                    sš   t tj| ƒ}|rt |ƒ}n|}‡ fdd„| ¡ D ƒ}z|jdd„ d� W n" tyl   |jdd„ d� Y n0 | |||d�} t| _| | j	¡ | ||< | S )z[
        Create a new Enum subclass that replaces a collection of global constants
        c                    s    g | ]\}}ˆ |ƒr||f‘qS r   r   )r^   r   r1   ©Úfilterr   r   Ú
<listcomp>!  s   þz&EnumMeta._convert_.<locals>.<listcomp>c                 S   s   | d | d fS )Nr   r   r   ©Útr   r   r   Ú<lambda>'  rb   z$EnumMeta._convert_.<locals>.<lambda>)rS   c                 S   s   | d S ©Nr   r   rº   r   r   r   r¼   *  rb   )r‘   )
Úvarsr¯   Úmodulesrf   Úsortr%   Ú_reduce_ex_by_namer)   Úupdaterž   )r+   r   r‘   r¸   ÚsourceZmodule_globalsÚmembersr   r·   r   Ú	_convert_  s     	

þzEnumMeta._convert_c                 C   s<   |D ]2}|j D ]&}t|tƒr|jrtd| |jf ƒ‚qqd S )Nz %s: cannot extend enumeration %r)r‚   Ú
issubclassr   r|   r%   r-   )r²   rY   rŒ   rr   r   r   r   rU   1  s    
ÿÿz$EnumMeta._check_for_existing_membersc                    sT   |st tfS ‡ fdd„}|d }t|tƒs2tdƒ‚||ƒp<t }|jrLtdƒ‚||fS )z¦
        Returns the type for creating enum members, and the first inherited
        enum class.

        bases: the tuple of bases that was given to __new__
        c                    s¶   t ƒ }| D ]x}d }|jD ]h}|tu r(qqt|tƒrN|jtur€| |j¡  q
qd|jv rxt|tƒrdq| |pn|¡  q
q|p~|}qq
t|ƒdkr¢t	dˆ |f ƒ‚n|r®| 
¡ S d S d S )Nrq   r   z%r: too many data types: %r)rP   r‚   r€   rÆ   r   r~   Úaddre   r   r%   rx   )rY   Z
data_typesrŒ   Ú	candidaterr   ©r²   r   r   Ú_find_data_typeF  s*    




z.EnumMeta._get_mixins_.<locals>._find_data_typer   zZnew enumerations should be created as `EnumName([mixin_type, ...] [data_type,] enum_type)`zCannot extend enumerations)r€   r   rÆ   r%   r|   )r²   rY   rÊ   r\   r[   r   rÉ   r   rV   ;  s    
zEnumMeta._get_mixins_c           	      C   sŽ   |   dd¡}|du}|du rpdD ]H}||fD ].}t||dƒ}|ddjtjtjhvr,|} q\q,|dur  qpq tj}|tju r€d}nd}|||fS )a  
        Returns the __new__ to be used for creating the enum members.

        classdict: the class dictionary given to __new__
        member_type: the data type whose __new__ will be used by default
        first_enum: enumeration to check for an overriding __new__
        rq   N)r†   rq   FT)r¬   rW   rq   r€   r   )	r`   r[   r\   rq   rˆ   ÚmethodZpossibleÚtargetr‰   r   r   r   ry   j  s*    ü
zEnumMeta._find_new_)N)N)r-   r*   r.   r/   Úclassmethodr]   rq   r�   r—   rš   rœ   r    r£   r¥   r¨   r©   Úpropertyrž   rt   r«   r­   r•   rÅ   ÚstaticmethodrU   rV   ry   rT   r   r   r:   r   r       s6   
 .%
	5
!
	
.r   c                   @   st   e Zd ZdZdd„ Zdd„ Zedd„ ƒZdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zedd„ ƒZedd„ ƒZdS )r   zV
    Generic enumeration.

    Derive from this class to define new enumerations.
    c              
   C   s(  t |ƒ| u r|S z| j| W S  ty.   Y n8 tyd   | j ¡ D ]}|j|krD|   Y S qDY n0 zd }|  |¡}W n, ty¤ } z|}d }W Y d }~n
d }~0 0 zrt	|| ƒrÀ|W d }d }S t
d|| jf ƒ}|d u rè|d u rè|‚n|d u �rtd| j|f ƒ}||_|‚W d }d }n
d }d }0 d S )Nú%r is not a valid %szDerror in %s._missing_: returned %r instead of None or a valid member)r“   r   r¡   r%   r}   Úvaluesrs   r@   Ú	ExceptionrK   rI   r.   r-   Ú__context__)r+   r1   r™   ÚexcÚresultÚeZve_excr   r   r   rq   ž  sJ    

ñ
ÿÿÿzEnum.__new__c              	   C   s4   t |ƒD ]&}z|d W   S  ty,   Y q0 q|S )úð
        Generate the next value when not given.

        name: the name of the member
        start: the initial start value or None
        count: the number of existing members
        last_value: the last value assigned or None
        r   N)rª   r%   )r   r”   r´   r³   Ú
last_valuer   r   r   r?   Ë  s    	zEnum._generate_next_value_c                 C   s   d S rl   r   )r+   r1   r   r   r   r@   Ü  s    zEnum._missing_c                 C   s   d| j j| j| jf S )Nú<%s.%s: %r>)r;   r-   r„   rs   r9   r   r   r   rt   à  s    ÿzEnum.__repr__c                 C   s   d| j j| jf S )Nú%s.%s)r;   r-   r„   r9   r   r   r   ru   ä  s    zEnum.__str__c                    s4   ‡ fdd„ˆ j  ¡ D ƒdd„ ˆ jD ƒ }g d¢| S )z<
        Returns all members and all public methods
        c                    s2   g | ]*}|j D ]}|d  dkr|ˆ jvr|‘qqS ©r   r   )re   r}   )r^   r+   ro   r9   r   r   r¹   ë  s   
ýz Enum.__dir__.<locals>.<listcomp>c                 S   s   g | ]}|d  dkr|‘qS rÛ   r   rn   r   r   r   r¹   ð  rb   )r;   r/   r*   )r;   rc   re   )r'   Zadded_behaviorr   r9   r   r    ç  s    
þûzEnum.__dir__c                 C   sJ   t | ƒjtjtjfv}| jtu s$|r2t}t| ƒ}n| j}| j}| ||¡S )z\
        Returns format using actual value type unless __str__ has been overridden.
        )	r“   ru   r   r   r~   r€   rL   rs   rv   )r'   Úformat_specZstr_overriddenr+   Úvalr   r   r   rv   ó  s    	
zEnum.__format__c                 C   s
   t | jƒS rl   )Úhashr„   r9   r   r   r   Ú__hash__  s    zEnum.__hash__c                 C   s   | j | jffS rl   ©r;   rs   r&   r   r   r   r)   	  s    zEnum.__reduce_ex__c                 C   s   | j S )zThe name of the Enum member.)r„   r9   r   r   r   r     s    z	Enum.namec                 C   s   | j S )zThe value of the Enum member.©rs   r9   r   r   r   r1     s    z
Enum.valueN)r-   r*   r.   r/   rq   r?   rÍ   r@   rt   ru   r    rv   rß   r)   r   r   r1   r   r   r   r   r   ˜  s   -


r   )Ú	metaclassc                   @   s   e Zd ZdZdS )r   z.Enum where members are also (and must be) intsN)r-   r*   r.   r/   r   r   r   r   r     s   r   c                 C   s   | j S rl   r   r&   r   r   r   rÁ   "  s    rÁ   c                   @   sp   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )r   z
    Support for flags
    c              	   C   sb   |s|dur|S dS t |ƒD ]8}zt|ƒ}W  qVW q tyR   td| ƒd‚Y q0 qd|d  S )r×   Nr   zInvalid Flag value: %rr   )rª   Ú	_high_bitrÒ   r%   )r   r”   r´   r³   rØ   Zhigh_bitr   r   r   r?   *  s    	
zFlag._generate_next_value_c                 C   s.   |}|dk r| }|   |¡}|dk r*| }|S )úV
        Returns member (possibly creating it) if one can be found for value.
        r   )r>   )r+   r1   Zoriginal_valueZpossible_memberr   r   r   r@   =  s    
zFlag._missing_c                 C   sb   | j  |d¡}|du r^t| |ƒ\}}|r:td|| jf ƒ‚t | ¡}d|_||_| j  	||¡}|S )úL
        Create a composite member iff value contains only members.
        NrÐ   )
r   r¬   Ú
_decomposerI   r.   r€   rq   r„   rs   rw   )r+   r1   Úpseudo_memberr   Úextra_flagsr   r   r   r>   J  s    
zFlag._create_pseudo_member_c                 C   s8   t || jƒs&tdt|ƒj| jjf ƒ‚|j| j@ |jkS )zP
        Returns True if self has at least the same flags set as other.
        r˜   )rK   r;   r%   r“   r.   rs   ©r'   Úotherr   r   r   rš   ^  s    ÿÿzFlag.__contains__c                 C   sV   | j }| jd ur$d|j| j| jf S t|| jƒ\}}d|jd dd„ |D ƒ¡| jf S )NrÙ   ú|c                 S   s   g | ]}t |jp|jƒ‘qS r   ©rL   r„   rs   rn   r   r   r   r¹   o  rb   z!Flag.__repr__.<locals>.<listcomp>)r;   r„   r-   rs   ræ   r{   ©r'   r+   rÄ   Ú	uncoveredr   r   r   rt   h  s    
ýzFlag.__repr__c                 C   s€   | j }| jd ur d|j| jf S t|| jƒ\}}t|ƒdkr^|d jd u r^d|j|d jf S d|jd dd„ |D ƒ¡f S d S )NrÚ   r   r   z%s.%rrë   c                 S   s   g | ]}t |jp|jƒ‘qS r   rì   rn   r   r   r   r¹   }  rb   z Flag.__str__.<locals>.<listcomp>)r;   r„   r-   ræ   rs   r   r{   rí   r   r   r   ru   s  s    
þzFlag.__str__c                 C   s
   t | jƒS rl   )Úboolrs   r9   r   r   r   r�   €  s    zFlag.__bool__c                 C   s"   t || jƒstS |  | j|jB ¡S rl   ©rK   r;   ÚNotImplementedrs   ré   r   r   r   Ú__or__ƒ  s    zFlag.__or__c                 C   s"   t || jƒstS |  | j|j@ ¡S rl   rð   ré   r   r   r   Ú__and__ˆ  s    zFlag.__and__c                 C   s"   t || jƒstS |  | j|jA ¡S rl   rð   ré   r   r   r   Ú__xor__�  s    zFlag.__xor__c                 C   sN   t | j| jƒ\}}|  d¡}| jD ] }||vr"|j| j@ s"||B }q"|  |¡S r½   )ræ   r;   rs   )r'   rÄ   rî   Zinvertedro   r   r   r   Ú
__invert__’  s    


zFlag.__invert__N)r-   r*   r.   r/   r?   rÍ   r@   r>   rš   rt   ru   r�   rò   ró   rô   rõ   r   r   r   r   r   %  s   


r   c                   @   sT   e Zd ZdZedd„ ƒZedd„ ƒZdd„ Zdd	„ Zd
d„ Z	eZ
eZe	Zdd„ ZdS )r   z)
    Support for integer-based Flags
    c                 C   s*   t |tƒstd|| jf ƒ‚|  |¡}|S )rä   rÐ   )rK   ÚintrI   r.   r>   )r+   r1   Z
new_memberr   r   r   r@      s    

zIntFlag._missing_c                 C   s¬   | j  |d¡}|du r¨|g}t| |ƒ\}}|rtt|ƒ}d| }|| j vrZ||vrZ| |¡ || krjd}q*||N }q*t|ƒD ]*}t | |¡}d|_||_	| j  
||¡}q||S )rå   Nr   r   )r   r¬   ræ   rã   rQ   rª   rö   rq   r„   rs   rw   )r+   r1   rç   Zneed_to_creater   rè   ZbitÚ
flag_valuer   r   r   r>   ª  s(    
ÿ


zIntFlag._create_pseudo_member_c                 C   s0   t || jtfƒstS |  | j|  |¡jB ¡}|S rl   ©rK   r;   rö   rñ   rs   )r'   rê   rÕ   r   r   r   rò   Ë  s    zIntFlag.__or__c                 C   s,   t || jtfƒstS |  | j|  |¡j@ ¡S rl   rø   ré   r   r   r   ró   Ñ  s    zIntFlag.__and__c                 C   s,   t || jtfƒstS |  | j|  |¡jA ¡S rl   rø   ré   r   r   r   rô   Ö  s    zIntFlag.__xor__c                 C   s   |   | j ¡}|S rl   rà   )r'   rÕ   r   r   r   rõ   ß  s    zIntFlag.__invert__N)r-   r*   r.   r/   rÍ   r@   r>   rò   ró   rô   Ú__ror__Ú__rand__Ú__rxor__rõ   r   r   r   r   r   ›  s   
	
 r   c                 C   s   |   ¡ d S )zJ
    returns index of highest bit, or -1 if value is zero or negative
    r   )Ú
bit_length)r1   r   r   r   rã   ä  s    rã   c                 C   s^   g }| j  ¡ D ]"\}}||jkr| ||jf¡ q|rZd dd„ |D ƒ¡}td| |f ƒ‚| S )zI
    Class decorator for enumerations ensuring unique member values.
    z, c                 S   s   g | ]\}}d ||f ‘qS )z%s -> %sr   )r^   Úaliasr   r   r   r   r¹   ô  rb   zunique.<locals>.<listcomp>z duplicate values found in %r: %s)rž   rf   r   rQ   r{   rI   )ZenumerationZ
duplicatesr   r™   Zalias_detailsr   r   r   r
   ê  s    
ÿÿr
   c           	      C   sè   |}|dk }g }| D ].}|j }|r||@ |kr| |¡ || M }q|sŒ|}|rŒdt|ƒ }|| jv r€| | j| ¡ || M }|| M }qL|sª|| jv rª| | j| ¡ |jdd„ dd� t|ƒdkrà|d j |krà| d¡ ||fS )z-
    Extract all members from the value.
    r   r   c                 S   s   | j S rl   rá   )ro   r   r   r   r¼     rb   z_decompose.<locals>.<lambda>T)rS   Úreverser   )r1   rQ   rã   r   rÀ   r   rx   )	Zflagr1   Znot_coveredÚnegativerÄ   r™   r¶   Ztmpr÷   r   r   r   ræ   ù  s,    



ræ   )r¯   Útypesr   r   Ú__all__r   r   r    r$   r,   r€   r0   r	   Údictr2   r   r“   r   rö   r   rÁ   r   r   rã   r
   ræ   r   r   r   r   Ú<module>   s0   
	T   { vI