o
    K+g                     @   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   6/var/www/html/squashfs-root/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   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 rt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rd}tfdd|D sdv rt| n6d }|D ]+}|jD ]  tu rqt fdd|D rd} n
d jv rd} nq|d ur nq|rt| 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 qw dD ]+}|v rrqit ||}t |d }t ||d }|d ur||u rt||| qit!d ur|	r||_"t!j|_|d urt|t#r|$dd% }||jkrt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 rz
tdjd }W n tttfy   Y nw |du rt| 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   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   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 rt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   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_covered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