o
    X|Äj—›  ã                   @   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.10/enum.pyÚ_is_descriptor   s
   
ÿýr   c                 C   sL   t | ƒdko%| dd… | dd…   kodkn  o%| d dko%| d dkS )z=
    Returns True if a __dunder__ name, False otherwise.
    é   Né   éþÿÿÿZ__Ú_éýÿÿÿ©Úlen©Únamer   r   r   Ú
_is_dunder   s   &ÿ
þ
ür   c                 C   sL   t | ƒdko%| d | d   kodkn  o%| dd… dko%| 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   s^   d| f }t |ƒ}t |ƒ|kr-| |¡r-|||d … dgkr-|d dks+|d dkr-dS dS )Nz_%s__r   r   r   r   TF)r   Ú
startswith)Zcls_namer   ÚpatternZpat_lenr   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|  ƒ‚)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_unpicklable:   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	   D   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   r2   R   s
   

z_EnumDict.__init__c                    s†  t | j|ƒrddl}|jd|f tdd� t|ƒr_|dvr!tdƒ‚|dkr3| jr,td	ƒ‚t	| d
|ƒ n‡|dkr^t
|tƒrE| dd¡ ¡ }nt|ƒ}|| _t|ƒt| jƒ@ }|r^td|f ƒ‚n[t|ƒrj|dkrid}nP|| jv rutd| ƒ‚|| jv r{n?t|ƒsº|| v r�td|| | f ƒ‚t
|tƒr®|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.11r   ©Ú
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_valuer@   ú,ú 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   Ú
ValueErrorr6   r#   ÚsetattrÚ
isinstanceÚstrÚreplaceÚsplitÚlistr5   Úsetr3   r   r   r	   r/   r.   rA   r   r4   Úappendr1   Ú__setitem__)r%   Úkeyr/   rE   Zalreadyr8   r   r   rQ   Y   sj   	ÿü
ÿÿ€€



üz_EnumDict.__setitem__)r+   r(   r,   r-   r2   rQ   Ú__classcell__r   r   r8   r   r0   K   s    r0   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_membersr0   rD   Ú_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 ]}ˆ|= q7ˆ dd ¡}t|ƒddh@ }|rWt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 rŸt|ƒ n6d }|D ]+}|jD ]‰ ˆ tu r¯q¨t‡ fdd„|D ƒƒr¾d} n
dˆ jv rÇd} nq¨|d urÎ nq£|rÕt|ƒ ˆjD ]Ž}|| }t|tƒsç|f}n|}ˆtu rð|f}|
sÿ||ƒ}t|dƒsþ||_n||g|¢R Ž }t|dƒ�sˆtu �r||_nˆ|Ž |_|j}||_||_|j|Ž  |j ¡ D ]\}}|j|jk�r=|} n�q.|j |¡ ||v�rPt|||ƒ ||j|< z||j|< W qØ t�yf   Y qØw dD ]+}|ˆv �rr�qit ||ƒ}t ˆ|d ƒ}t ||d ƒ}|d u�r“||u �r“t|||ƒ �qit!d u�r¤|	�r ||_"t!j|_|d u�rÁt|t#ƒ�r·| $dd¡ %¡ }||jk�rÁtdƒ‚|S )Nr@   c                    s   i | ]}|ˆ | “qS r   r   )Ú.0Úk)Ú	classdictr   r   Ú
<dictcomp>Æ   s    z$EnumMeta.__new__.<locals>.<dictcomp>r<   ÚmroÚ zInvalid enum member name: {0}rB   r-   zAn enumeration.c                 S   s.   h | ]}|j  ¡ D ]\}}t|tƒr	|’q	qS r   )Ú__dict__ÚitemsrJ   r   )r]   Úcr^   Úvr   r   r   Ú	<setcomp>Þ   s    þýÿz#EnumMeta.__new__.<locals>.<setcomp>r'   )Z__getnewargs_ex__Ú__getnewargs__r'   Ú
__reduce__c                 3   ó   � | ]}|ˆ j v V  qd S ©N©rc   ©r]   Úm)rZ   r   r   Ú	<genexpr>õ   ó   € z#EnumMeta.__new__.<locals>.<genexpr>Ú__new__c                 3   rj   rk   rl   rm   )Úbaser   r   ro     rp   FTÚ_value_)Ú__repr__Ú__str__Ú
__format__r'   rC   z#member order does not match _order_)&Ú
setdefaultrP   ÚpoprU   Ú
_find_new_r3   rO   rH   ÚformatÚjoinr1   rq   Ú_member_names_Ú_member_map_Ú_member_type_ra   Ú_value2member_map_ÚobjectÚanyr*   Ú__mro__rc   rJ   Útupler   rs   Ú_name_Ú__objclass__r2   rd   rI   r#   rV   r   Ú__new_member__rK   rL   rM   )rW   r)   rX   r_   rY   ÚignorerR   r[   rq   Úsave_newÚuse_argsZenum_membersr   r<   Zinvalid_namesÚ
enum_classZdynamic_attributesÚmethodsZsabotageÚchainÚmember_namer/   ÚargsZenum_memberZcanonical_memberZclass_methodZ
obj_methodZenum_methodr8   )rr   r_   rZ   r   rq   ´   sÐ   
ÿ
ÿÿ


ýÿ


€


þ

ÿ

€

zEnumMeta.__new__c                 C   s   dS )z6
        classes/types should always be True.
        Tr   r7   r   r   r   Ú__bool__a  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)   r/   Únamesr‘   r’   r“   r”   r   r   r   Ú__call__g  s   úzEnumMeta.__call__c                 C   sR   t |tƒsdd l}|jdtdd� tdt|ƒj| jjf ƒ‚t || ƒo(|j	| j
v S )Nr   zpin 3.12 __contains__ will no longer raise TypeError, but will return True if
obj is a member or a member's valuer   r:   ú3unsupported operand type(s) for 'in': '%s' and '%s')rJ   r   rE   rF   rG   r#   r“   r,   r9   r„   r}   )r)   r   rE   r   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+   r1   Ú__delattr__)r)   Úattrr8   r   r   r›   š  s   
zEnumMeta.__delattr__c                 C   s   g d¢| j  S )N)r9   r-   Ú__members__r(   ©r|   r7   r   r   r   Ú__dir__¡  s   ÿÿzEnumMeta.__dir__c                 C   s6   t |ƒrt|ƒ‚z| j| W S  ty   t|ƒd‚w )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 rk   ©r}   r¡   r   r   r   Ú__getitem__·  ó   
zEnumMeta.__getitem__c                    s   ‡ fdd„ˆ j D ƒS )z6
        Returns members in definition order.
        c                 3   ó   � | ]}ˆ j | V  qd S rk   r£   ©r]   r   ©r)   r   r   ro   ¾  rp   z$EnumMeta.__iter__.<locals>.<genexpr>rž   r¨   r   r¨   r   Ú__iter__º  s   zEnumMeta.__iter__c                 C   ó
   t | jƒS rk   )r   r|   r¨   r   r   r   Ú__len__À  r¥   zEnumMeta.__len__c                 C   rª   )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   Í  r¥   zEnumMeta.__repr__c                    s   ‡ fdd„t ˆ jƒD ƒS )z>
        Returns members in reverse definition order.
        c                 3   r¦   rk   r£   r§   r¨   r   r   ro   Ô  rp   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)rc   Úgetrš   r1   Ú__setattr__)r)   r   r/   Z
member_mapr8   r   r   r¯   Ö  s   zEnumMeta.__setattr__c             
   C   sf  | j }|du r
| fn|| f}|  | |¡\}	}
| ||¡}t|tƒr)| dd¡ ¡ }t|ttfƒra|rat|d tƒra|g }}g }t	|ƒD ]\}}|
 
||||dd… ¡}| |¡ | ||f¡ qD|D ]}t|tƒrr||| }}n|\}}|||< qc| ||||¡}|du ržz
t d¡jd }W n tttfy�   Y nw |du r§t|ƒ n||_|dur±||_|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.
        NrB   rC   r   r   r+   )r9   rU   r\   rJ   rK   rL   rM   rƒ   rN   Ú	enumerater>   rP   rq   ÚsysÚ	_getframeÚ	f_globalsrš   rH   r    r*   r(   r,   )r)   Ú
class_namer–   r‘   r’   r“   r”   rW   rX   r   r[   r_   Zoriginal_namesÚlast_valuesÚcountr   r/   Ú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y6   |jdd„ d� Y nw | |||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   r/   ©Úfilterr   r   Ú
<listcomp>)  s    ýÿz&EnumMeta._convert_.<locals>.<listcomp>c                 S   s   | d | d fS )Nr   r   r   ©Útr   r   r   Ú<lambda>/  s    z$EnumMeta._convert_.<locals>.<lambda>)rR   c                 S   s   | d S ©Nr   r   r¼   r   r   r   r¾   2  s    )r‘   )
Úvarsr±   Úmodulesrd   Ú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 ]}|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´   rX   rŒ   rr   r   r   r   rT   9  s   
ÿÿ€þÿz$EnumMeta._check_for_existing_membersc                    sT   |st tfS ‡ fdd„}|d }t|tƒstdƒ‚||ƒpt }|jr&t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 ]:}d }|jD ]2}|tu rqt|tƒr&|jtur%| |j¡  nqd|jv r:t|tƒr1q| |p6|¡  n|p=|}qqt|ƒdkrNt	dˆ |f ƒ‚|rT| 
¡ S d S )Nrq   r   z%r: too many data types: %r)rO   r‚   r€   rÈ   r   r~   Úaddrc   r   r#   rx   )rX   Z
data_typesrŒ   Ú	candidaterr   ©r´   r   r   Ú_find_data_typeN  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´   rX   rÌ   r[   rZ   r   rË   r   rU   C  s   
zEnumMeta._get_mixins_c           	      C   sŽ   |   dd¡}|du}|du r8dD ]$}||fD ]}t||dƒ}|ddjtjtjhvr-|} nq|dur4 nq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®   rV   rq   r€   r   )	r_   rZ   r[   rq   rˆ   ÚmethodZpossibleÚtargetr‰   r   r   r   ry   r  s.   üùÿ

zEnumMeta._find_new_rk   )r+   r(   r,   r-   Úclassmethodr\   rq   r�   r—   r™   r›   rŸ   r¢   r¤   r©   r«   Úpropertyr�   rt   r­   r¯   r•   rÇ   ÚstaticmethodrT   rU   ry   rS   r   r   r8   r   r   ¡   s8    
 .%
	
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 n ty2   | j ¡ D ]}|j|kr/|   Y S q"Y nw z	d }|  |¡}W n tyR } z
|}d }W Y d }~nd }~ww z6t	|| ƒr`|W d }d }S t
d|| jf ƒ}|d u rs|d u rs|‚|d u r€td| j|f ƒ}t	|t
ƒsˆ||_|‚d }d }w )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?   Ú	ExceptionrJ   rH   r,   r+   Ú__context__)r)   r/   ÚmemberÚexcÚresultÚeZve_excr   r   r   rq   ¦  sP   
ÿÿþ€þ
òÿÿ
zEnum.__new__c              	   C   s2   t |ƒD ]}z|d W   S  ty   Y qw |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   )r¬   r#   )r   r”   r¶   rµ   Ú
last_valuer   r   r   r>   Ô  s   	ÿzEnum._generate_next_value_c                 C   s   d S rk   r   )r)   r/   r   r   r   r?   å  s   zEnum._missing_c                 C   s   d| j j| j| jf S )Nú<%s.%s: %r>)r9   r+   r„   rs   r7   r   r   r   rt   é  s   ÿzEnum.__repr__c                 C   s   d| j j| jf S )Nú%s.%s)r9   r+   r„   r7   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   )rc   r}   )r]   r)   rn   r7   r   r   r»   ô  s    ýýz Enum.__dir__.<locals>.<listcomp>c                 S   s   g | ]
}|d  dkr|‘qS rÞ   r   rm   r   r   r   r»   ù  ó    )r9   r-   r(   )r9   ra   rc   )r%   Zadded_behaviorr   r7   r   rŸ   ð  s   
þûzEnum.__dir__c                 C   sJ   t | ƒjtjtjfv}| jtu s|rt}t| ƒ}n| j}| j}| ||¡S )z\
        Returns format using actual value type unless __str__ has been overridden.
        )	r“   ru   r   r   r~   r€   rK   rs   rv   )r%   Úformat_specZstr_overriddenr)   Úvalr   r   r   rv   ü  s   	
zEnum.__format__c                 C   rª   rk   )Úhashr„   r7   r   r   r   Ú__hash__  r¥   zEnum.__hash__c                 C   s   | j | jffS rk   ©r9   rs   r$   r   r   r   r'     s   zEnum.__reduce_ex__c                 C   ó   | j S )zThe name of the Enum member.)r„   r7   r   r   r   r     ó   z	Enum.namec                 C   rå   )zThe value of the Enum member.©rs   r7   r   r   r   r/   !  ræ   z
Enum.valueN)r+   r(   r,   r-   rq   r>   rÏ   r?   rt   ru   rŸ   rv   rã   r'   r   r   r/   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   rå   rk   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   sX   |s
|dur|S dS t |ƒD ]}zt|ƒ}W  n ty%   td| ƒd‚w 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>   3  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)   r/   Zoriginal_valueZpossible_memberr   r   r   r?   F  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®   Ú
_decomposerH   r,   r€   rq   r„   rs   rw   )r)   r/   Úpseudo_memberr   Úextra_flagsr   r   r   r=   S  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˜   )rJ   r9   r#   r“   r,   rs   ©r%   Úotherr   r   r   r™   g  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   ó   g | ]
}t |jp
|jƒ‘qS r   ©rK   r„   rs   rm   r   r   r   r»   x  rß   z!Flag.__repr__.<locals>.<listcomp>)r9   r„   r+   rs   rì   r{   ©r%   r)   rÆ   Ú	uncoveredr   r   r   rt   q  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 )NrÝ   r   r   z%s.%rrñ   c                 S   rò   r   ró   rm   r   r   r   r»   †  rß   z Flag.__str__.<locals>.<listcomp>)r9   r„   r+   rì   rs   r   r{   rô   r   r   r   ru   |  s   
þzFlag.__str__c                 C   rª   rk   )Úboolrs   r7   r   r   r   r�   ‰  r¥   zFlag.__bool__c                 C   s"   t || jƒstS |  | j|jB ¡S rk   ©rJ   r9   ÚNotImplementedrs   rï   r   r   r   Ú__or__Œ  ó   zFlag.__or__c                 C   s"   t || jƒstS |  | j|j@ ¡S rk   r÷   rï   r   r   r   Ú__and__‘  rú   zFlag.__and__c                 C   s"   t || jƒstS |  | j|jA ¡S rk   r÷   rï   r   r   r   Ú__xor__–  rú   zFlag.__xor__c                 C   sN   t | j| jƒ\}}|  d¡}| jD ]}||vr!|j| j@ s!||B }q|  |¡S r¿   )rì   r9   rs   )r%   rÆ   rõ   Zinvertedrn   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Ò   )rJ   ÚintrH   r,   r=   )r)   r/   Z
new_memberr   r   r   r?   ©  s   

zIntFlag._missing_c                 C   s®   | j  |d¡}|du rU|g}t| |ƒ\}}|r;t|ƒ}d| }|| j vr-||vr-| |¡ || kr5d}n||N }|st|ƒD ]}t | |¡}d|_||_	| j  
||¡}q?|S )rë   Nr   r   )r   r®   rì   ré   rP   r¬   rþ   rq   r„   rs   rw   )r)   r/   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 rk   ©rJ   r9   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 rk   r   rï   r   r   r   rû   Ú  ó   zIntFlag.__and__c                 C   s,   t || jtfƒs
tS |  | j|  |¡jA ¡S rk   r   rï   r   r   r   rü   ß  r  zIntFlag.__xor__c                 C   s   |   | j ¡}|S rk   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)r/   r   r   r   ré   í  s   ré   c                 C   s^   g }| j  ¡ D ]\}}||jkr| ||jf¡ q|r-d 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»   ý  rß   zunique.<locals>.<listcomp>z duplicate values found in %r: %s)r�   rd   r   rP   r{   rH   )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
|sG|}|rGdt|ƒ }|| jv r@| | j| ¡ || M }|| M }|s(|sV|| jv rV| | j| ¡ |jdd„ dd� t|ƒdkrq|d j |krq| d¡ ||fS )z-
    Extract all members from the value.
    r   r   c                 S   rå   rk   rç   )rn   r   r   r   r¾     s    z_decompose.<locals>.<lambda>T)rR   Úreverser   )r/   rP   ré   r   rÂ   r   rx   )	Zflagr/   Znot_coveredZnegativerÆ   rÖ   r¸   Ztmprÿ   r   r   r   rì     s0   

€


û
rì   )r±   Útypesr   r   Ú__all__r   r   r   r"   r*   r€   r.   r	   Údictr0   r   r“   r   rþ   r   rÃ   r   r   ré   r
   rì   r   r   r   r   Ú<module>   s4    
	T     vI