o
    éT•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/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é   éþÿÿÿÚ__Ú_éýÿÿÿ©Ú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)Úcls_namer   ÚpatternÚ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©ÚselfÚ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   r6   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 userB   z4_generate_next_value_ must be defined before membersÚ_generate_next_valuerD   ú,ú z-_ignore_ cannot specify already set names: %rÚ	__order__r@   zAttempted to reuse key: %rz%r already defined as: %rr   T)r%   Ú	_cls_nameÚwarningsÚwarnÚDeprecationWarningr    Ú
ValueErrorr:   r&   ÚsetattrÚ
isinstanceÚstrÚreplaceÚsplitÚlistr9   Úsetr7   r   r   r	   r3   r2   rE   r   r8   Úappendr5   Ú__setitem__)r(   Úkeyr3   rJ   Úalreadyr<   r   r   rV   Y   sj   	ÿü
ÿÿ€€



üz_EnumDict.__setitem__)r/   r,   r0   r1   r6   rV   Ú__classcell__r   r   r<   r   r4   K   s    r4   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 )NrB   )Ú_check_for_existing_membersr4   rI   Ú_get_mixins_Úgetattr)Úmetaclsr-   ÚbasesÚkwdsÚ	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 )NrD   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}rF   r1   zAn enumeration.c                 S   s.   h | ]}|j  ¡ D ]\}}t|tƒr	|’q	qS r   )Ú__dict__ÚitemsrO   r   )rd   Úcre   Úvr   r   r   Ú	<setcomp>Þ   s    þýÿz#EnumMeta.__new__.<locals>.<setcomp>r+   )Ú__getnewargs_ex__Ú__getnewargs__r+   Ú
__reduce__c                 3   ó   � | ]}|ˆ j v V  qd S ©N©rj   ©rd   Úm)ra   r   r   Ú	<genexpr>õ   ó   € z#EnumMeta.__new__.<locals>.<genexpr>Ú__new__c                 3   rr   rs   rt   ru   )Úbaser   r   rw     rx   FTÚ_value_)Ú__repr__Ú__str__Ú
__format__r+   rG   z#member order does not match _order_)&Ú
setdefaultrU   Úpopr[   Ú
_find_new_r7   rT   rM   ÚformatÚjoinr5   ry   Ú_member_names_Ú_member_map_Ú_member_type_rh   Ú_value2member_map_ÚobjectÚanyr.   Ú__mro__rj   rO   Útupler   r{   Ú_name_Ú__objclass__r6   rk   rN   r&   r\   r   Ú__new_member__rP   rQ   rR   )r]   r-   r^   rf   r_   ÚignorerW   rb   ry   Úsave_newÚuse_argsÚenum_membersr   r@   Úinvalid_namesÚ
enum_classÚdynamic_attributesÚmethodsÚsabotageÚchainÚmember_namer3   ÚargsÚenum_memberÚcanonical_memberÚclass_methodÚ
obj_methodÚenum_methodr<   )rz   rf   ra   r   ry   ´   sÐ   
ÿ
ÿÿ


ýÿ


€


þ

ÿ

€

zEnumMeta.__new__c                 C   s   dS )z6
        classes/types should always be True.
        Tr   r;   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¡   )ry   Ú_create_)r-   r3   Ú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')rO   r   rJ   rK   rL   r&   r¤   r0   r=   rŒ   r…   )r-   r   rJ   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/   r5   Ú__delattr__)r-   Úattrr<   r   r   r¬   š  s   
zEnumMeta.__delattr__c                 C   s   g d¢| j  S )N)r=   r1   Ú__members__r,   ©r„   r;   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 rs   ©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 rs   r´   ©rd   r   ©r-   r   r   rw   ¾  rx   z$EnumMeta.__iter__.<locals>.<genexpr>r¯   r¹   r   r¹   r   Ú__iter__º  s   zEnumMeta.__iter__c                 C   ó
   t | jƒS rs   )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   r|   Í  r¶   zEnumMeta.__repr__c                    s   ‡ fdd„t ˆ jƒD ƒS )z>
        Returns members in reverse definition order.
        c                 3   r·   rs   r´   r¸   r¹   r   r   rw   Ô  rx   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)rj   Úgetr«   r5   Ú__setattr__)r-   r   r3   Ú
member_mapr<   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.
        NrF   rG   r   r   r/   )r=   r[   rc   rO   rP   rQ   rR   r‹   rS   Ú	enumeraterB   rU   ry   ÚsysÚ	_getframeÚ	f_globalsr«   rM   r±   r.   r,   r0   )r-   Ú
class_namer§   r¢   r£   r¤   r¥   r]   r^   r   rb   rf   Úoriginal_namesÚlast_valuesÚcountr   r3   Ú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   )rd   r   r3   ©Ú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>)rW   c                 S   s   | d S ©Nr   r   rÏ   r   r   r   rÑ   2  s    )r¢   )
ÚvarsrÃ   Úmodulesrk   Úsortr&   Ú_reduce_ex_by_namer+   Úupdater®   )r-   r   r¢   rÍ   ÚsourceÚ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Æ   r^   r˜   rz   r   r   r   rZ   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 )Nry   r   z%r: too many data types: %r)rT   rŠ   rˆ   rÜ   r   r†   Úaddrj   r   r&   r€   )r^   Ú
data_typesr˜   Ú	candidaterz   ©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Æ   r^   rá   rb   ra   r   rà   r   r[   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__
        ry   N)rŽ   ry   FT)r¿   r\   ry   rˆ   r   )	rf   ra   rb   ry   r�   ÚmethodÚpossibleÚtargetr‘   r   r   r   r�   r  s.   üùÿ

zEnumMeta._find_new_rs   )r/   r,   r0   r1   Úclassmethodrc   ry   r    r¨   rª   r¬   r°   r³   rµ   rº   r¼   Úpropertyr®   r|   r¾   rÀ   r¦   rÛ   ÚstaticmethodrZ   r[   r�   rY   r   r   r<   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…   Úvaluesr{   rC   Ú	ExceptionrO   rM   r0   r/   Ú__context__)r-   r3   ÚmemberÚexcÚresultÚeÚve_excr   r   r   ry   ¦  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   rB   Ô  s   	ÿzEnum._generate_next_value_c                 C   s   d S rs   r   )r-   r3   r   r   r   rC   å  s   zEnum._missing_c                 C   s   d| j j| j| jf S )Nú<%s.%s: %r>)r=   r/   rŒ   r{   r;   r   r   r   r|   é  s   ÿzEnum.__repr__c                 C   s   d| j j| jf S )Nú%s.%s)r=   r/   rŒ   r;   r   r   r   r}   í  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   )rj   r…   )rd   r-   rv   r;   r   r   rÎ   ô  s    ýýz Enum.__dir__.<locals>.<listcomp>c                 S   s   g | ]
}|d  dkr|‘qS rõ   r   ru   r   r   r   rÎ   ù  ó    )r=   r1   r,   )r=   rh   rj   )r(   Úadded_behaviorr   r;   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¤   r}   r   r   r†   rˆ   rP   r{   r~   )r(   Úformat_specÚstr_overriddenr-   Úvalr   r   r   r~   ü  s   	
zEnum.__format__c                 C   r»   rs   )ÚhashrŒ   r;   r   r   r   Ú__hash__  r¶   zEnum.__hash__c                 C   s   | j | jffS rs   ©r=   r{   r'   r   r   r   r+     s   zEnum.__reduce_ex__c                 C   ó   | j S )zThe name of the Enum member.)rŒ   r;   r   r   r   r     ó   z	Enum.namec                 C   rþ   )zThe value of the Enum member.©r{   r;   r   r   r   r3   !  rÿ   z
Enum.valueN)r/   r,   r0   r1   ry   rB   rå   rC   r|   r}   r°   r~   rü   r+   r   r   r3   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,   r0   r1   r   r   r   r   r   '  s    r   c                 C   rþ   rs   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ò   Úhigh_bitr   r   r   rB   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   )rA   )r-   r3   Úoriginal_valueÚpossible_memberr   r   r   rC   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¿   Ú
_decomposerM   r0   rˆ   ry   rŒ   r{   r   )r-   r3   Úpseudo_memberr   Úextra_flagsr   r   r   rA   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©   )rO   r=   r&   r¤   r0   r{   ©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   ©rP   rŒ   r{   ru   r   r   r   rÎ   x  rö   z!Flag.__repr__.<locals>.<listcomp>)r=   rŒ   r/   r{   r  rƒ   ©r(   r-   rÚ   Ú	uncoveredr   r   r   r|   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  ru   r   r   r   rÎ   †  rö   z Flag.__str__.<locals>.<listcomp>)r=   rŒ   r/   r  r{   r   rƒ   r  r   r   r   r}   |  s   
þzFlag.__str__c                 C   r»   rs   )Úboolr{   r;   r   r   r   r    ‰  r¶   zFlag.__bool__c                 C   s"   t || jƒstS |  | j|jB ¡S rs   ©rO   r=   ÚNotImplementedr{   r  r   r   r   Ú__or__Œ  ó   zFlag.__or__c                 C   s"   t || jƒstS |  | j|j@ ¡S rs   r  r  r   r   r   Ú__and__‘  r  zFlag.__and__c                 C   s"   t || jƒstS |  | j|jA ¡S rs   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  r=   r{   )r(   rÚ   r  Úinvertedrv   r   r   r   Ú
__invert__›  s   

€
zFlag.__invert__N)r/   r,   r0   r1   rB   rå   rC   rA   rª   r|   r}   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è   )rO   ÚintrM   r0   rA   )r-   r3   Ú
new_memberr   r   r   rC   ©  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  rU   r½   r  ry   rŒ   r{   r   )r-   r3   r	  Úneed_to_creater   r
  ÚbitÚ
flag_valuer   r   r   rA   ³  s(   


õzIntFlag._create_pseudo_member_c                 C   s0   t || jtfƒs
tS |  | j|  |¡jB ¡}|S rs   ©rO   r=   r  r  r{   )r(   r  rî   r   r   r   r  Ô  s   zIntFlag.__or__c                 C   s,   t || jtfƒs
tS |  | j|  |¡j@ ¡S rs   r   r  r   r   r   r  Ú  ó   zIntFlag.__and__c                 C   s,   t || jtfƒs
tS |  | j|  |¡jA ¡S rs   r   r  r   r   r   r  ß  r!  zIntFlag.__xor__c                 C   s   |   | j ¡}|S rs   rý   )r(   rî   r   r   r   r  è  s   zIntFlag.__invert__N)r/   r,   r0   r1   rå   rC   rA   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)r3   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   )rd   Úaliasr   r   r   r   rÎ   ý  rö   zunique.<locals>.<listcomp>z duplicate values found in %r: %s)r®   rk   r   rU   rƒ   rM   )ÚenumerationÚ
duplicatesr   rì   Ú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þ   rs   r   )rv   r   r   r   rÑ     s    z_decompose.<locals>.<lambda>T)rW   Úreverser   )r3   rU   r  r‡   rÕ   r   r€   )	Úflagr3   Únot_coveredÚnegativerÚ   rì   rË   Útmpr  r   r   r   r    s0   

€


û
r  )rÃ   Útypesr   r   Ú__all__r   r   r    r%   r.   rˆ   r2   r	   Údictr4   r   r¤   r   r  r   rÖ   r   r   r  r
   r  r   r   r   r   Ú<module>   s4    
	T     vI