o
    ٷi                    @   s  d dl mZ ddlT ddlmZ ddlmZ d dlmZ d dl	Z	d dl
Zg dZeZzd dlZW n ey@   dZed	 Y nw ze W n eyP   eZY nw ze W n eyb   d
d ZY nw dZz%d dlZeedrsedd dlmZmZmZ d Z Z  Z!Z"eefZW n ey   d Z Z Z Z  Z Z! Z!Z"Y nw erzd dlm#Z m$Z eee f7 ZW n	 ey   Y nw zd dlm%Z! ee!f7 ZW n	 ey   Y nw zd dlm&Z" ee"f7 ZW n	 ey   Y nw d Z' Z( Z) Z*Z+dddZ,dd Z-dd Z.dddZdd Z/z
d dl0m1Z1 e1Z2W n ey&   e3Z2dZ1Y nw dd  Z4G d!d" d"e2Z5e5Z6e1du r<e5Z1e5Z7G d#d$ d$e8Z9e9d%e3fi Z:d&d' Z;d(d) Z<d*d Z-d+d, Z=d-d. Z>d/d0 Z?d1d2 Z@e,eA G d3d4 d4eZBd Z Z& Z Z% Z$ Z# ZCZDG d5d6 d6e3Ze9d7e3fi ZEG d8d9 d9eZFdd:lGmZ e5e_5eFe_F[G d;d< d<eZHG d=d> d>ZIG d?d@ d@eJZKe9dAe8fi ZLG dBdC dCe8ZMerG dDdC dCeMeZMeMZeNeMOdEe3fdFeA dGZPePeQdHdI ZRePdJdK ZSePdLdM ZTePeQdNdO ZUePeVdPdQ ZWePeQdRdS ZXePeQdTdU ZYePeQdVdW ZZePdXdY Z[ePdZd[ Z\e]r<ePd\d] Z^ePd^d_ Z_ePd`da Z`ePdbdc ZaePddde ZbePdfdg ZcePdhdi ZdePdjdk ZeePdldm ZfePdndo ZgePe5dpdq ZhePe5drds ZiePe5dtdu Zjepe3ZkeMdEekfePl Z[Pdvdw ZmemZndxdy Zodzd{ Zpe"ree"fZqnefZqeMd|eqd}d~iZ&G dd dere&ZG dd dese&Z%G dd de%ZtG dd de%Zue]rG dd deZvewd G dd deZxG dd deZyG dd deZzG dd deZ{G dd deZ|erG dd	 d	eZ}G dd deZ~dddZdd ZdddZdd Zzd dlmZ W n eyS   G dd de%ZY nw e,eeA  erbeefZnefZeNeMOdedeA dGZeed< eed< eddQ ZWeeQdd Zeed< eeQdd ZeeQddS ZXeeQdd ZeeQdd Zedd Zedd Zedd ZeddY Z[edd[ Z\eredd Znedd Zedd Zedd Zedd ZeddÄ Zeddń Zeed< eed< eed< eMdeel Z$[G ddʄ dere&e$Z#dd̄ Zdd΄ ZddЄ Zdd҄ ZdddԄZer<d dlmZ ddׄ Zddل Zddۄ Zdd݄ ZG dd߄ de3ZdS )    )print_function   )*)NamedConstant)
NamedTuple)defaultdictN).	bit_countis_single_bitbinpropertybitsAddValue
MagicValue
MultiValueNoAliasUniqueenumautoAddValueEnumMultiValueEnumNoAliasEnum
UniqueEnumAutoNumberEnumOrderedEnumuniqueno_argextend_enumenum_propertyEnumTypeEnumMetaEnumDictEnumIntEnumStrEnumFlagIntFlagLowerStrEnumUpperStrEnumReprEnum
SqliteEnumsqlite3FlagBoundarySTRICTCONFORMEJECTKEEPadd_stdlib_integrationremove_stdlib_integrationexport
cls2module_reduce_ex_by_nameshow_flag_valuesr)   c                 C   s   | D ]}|r	 dS qdS )NTF )iterableelementr6   r6   ?/home/ubuntu/.local/lib/python3.10/site-packages/aenum/_enum.pyany(   s
   r:   r6   versionzwrong version)r   r!   r"   )r%   r$   )r#   )r(   c                    s    du r|   fdd}|S t | tr(| j D ]\}}t|tr%| |< q| S t | ts4trFt | trF| j }|D ]\}}| |< q;| S td| f )z
    export([collection,] namespace) -> Export members to target namespace.

    If collection is not given, act as a decorator.
    Nc                    s
   t |  S N)r2   )
collection	namespacer6   r9   export_decoratorW      
z export.<locals>.export_decoratorz %r is not a supported collection)	
issubclassr   __dict__items
isinstancer!   stdlib_enums__members__	TypeError)r=   r?   r@   ncdatamr6   r>   r9   r2   O   s    



r2   c                 C   $   d}| r| | d M } |d7 }| s|S )aR  
    return number of set bits

    Counting bits set, Brian Kernighan's way*

        unsigned int v;          // count the number of bits set in v
        unsigned int c;          // c accumulates the total bits set in v
        for (c = 0; v; c++)
        {   v &= v - 1;  }       //clear the least significant bit set

    This method goes through as many iterations as there are set bits. So if we
    have a 32-bit word with only the high bit set, then it will only go once
    through the loop.

    * The C Programming Language 2nd Ed., Kernighan & Ritchie, 1988.

    This works because each subtraction "borrows" from the lowest 1-bit. For
    example:

          loop pass 1     loop pass 2
          -----------     -----------
               101000          100000
             -      1        -      1
             = 100111        = 011111
             & 101000        & 100000
             = 100000        =      0

    It is an excellent technique for Python, since the size of the integer need
    not be determined beforehand.

    (from https://wiki.python.org/moin/BitManipulation)
    r   r   r6   numcountr6   r6   r9   r   f   s   !r   c                 c   s.    | r| |  d @ }|V  | |N } | sdS dS )zZ
    Return each bit value one at a time.

    >>> list(_iter_bits_lsb(6))
    [2, 4]
    r   Nr6   )valuebitr6   r6   r9   _iter_bits_lsb   s   rS   Fc                 C   s   d|    }| dkrt| | ddd}n|s$t|  |d | A }nt|  | ddd}|dd }|dd }|s@d}|durWt||k rW|d | | | d }| dk re|re|dd d	 }d
||f S )a^  
    Like built-in bin(), except negative values are either represented
    in twos-compliment with the leading bit indicating sign (0=positive, 1=negative),
    or shown as positive with a sign bit of '~'.

    >>> bin(10)
    '0b0 1010'
    >>> bin(~10)   # ~10 is -11
    '0b1 0101'
    >>> bin(~10, invert=True)   # ~10 is -11
    '0b~ 1010'
       r   10r   N   ~z%s %s)
bit_length
_bltin_binreplacelen)rQ   max_bitsinvertceilingssigndigitsr6   r6   r9   r
      s    r
   c                 C   s   t t| S r<   )listrS   rQ   r6   r6   r9   r5      s   r5   )DynamicClassAttributec                 C   s   t d| j }|| t| f; }t| tr>| j }|t d| jt	| j|d| jt	| j
|d| j
t	| j|d| jd 7 }t| dS )z,
    show details about given enum/flag
    a              %%r    member type: %(_member_type_)r    members: %%r
            __new__:  %(_new_member_)r
            use args: %(_use_args_)r
            settings: %(_settings_)r
            member names: %(_member_names_)r
            start value:  %(_start_)r
            auto init:    %(_auto_init_)r
            new args:     %(_new_args_)r
            auto args:    %(_auto_args_)r
            ordering:     %(_order_function_)r
            value repr:   %(_value_repr_)r
            z            boundary:     %(boundary)r
            all bits:     %(all_bits)r   (%(iall_bits)r)
            flag mask:    %(flag_mask)r   (%(iflag_mask)r)
            singles mask: %(singles_mask)r   (%(isingles_mask)r)
            )r^   )boundaryall_bits	iall_bits	flag_mask
iflag_masksingles_maskisingles_maskN)textwrapdedentrC   r]   rB   r$   
_all_bits_rZ   
_boundary_r
   _flag_mask__singles_mask_print)r   textr^   r6   r6   r9   info   s"   

rv   c                   @   s`   e Zd ZdZdZdddZdd Zdd Zd	d
 Zdd Z	dddZ
dd Zdd Zdd ZdS )r   a  
    This is a descriptor, used to define attributes that act differently
    when accessed through an enum member and through an enum class.
    Instance access is the same as property(), but access to an attribute
    through the enum class will look in the class' _member_map_.
    Nc                 C   s>   || _ || _|| _|p|j| _|d u | _tt|dd| _d S )N__isabstractmethod__F)fgetfsetfdel__doc__overwrite_docboolgetattrrw   )selfrx   ry   rz   docr6   r6   r9   __init__   s   
zproperty.__init__c                 C   s<   | j r|jnd }t| || j| j|p| j}| jd u |_ |S r<   )r|   r{   typery   rz   )r   rx   fdocresultr6   r6   r9   getter     zproperty.getterc                 C   s<   | j r|jnd }t| | j|| j|p| j}| jd u |_ |S r<   )r|   r{   r   rx   rz   )r   ry   r   r   r6   r6   r9   setter	  r   zproperty.setterc                 C   s<   | j r|jnd }t| | j| j||p| j}| jd u |_ |S r<   )r|   r{   r   rx   ry   )r   rz   r   r   r6   r6   r9   deleter  r   zproperty.deleterc                 C   sR   | j p| jp| j}g }| jd ur|d| j  |r"|d|j  dd| S )N%rzfunction=%szproperty(%s), )rx   ry   rz   memberappend__name__join)r   funcstringsr6   r6   r9   __repr__  s   
zproperty.__repr__c                 C   s   |d u r| j d ur| j S td|| jf | jd ur| |S | jd ur-td| j|f z|j| j W S  tyD   td|| jf w )Nz%r has no attribute %rzcannot read attribute %r on %rz%r member has no attribute %r)r   AttributeErrornamerx   ry   rC   KeyError)r   instance
ownerclassr6   r6   r9   __get__  s&   



zproperty.__get__c                 C   sD   | j d u r| jd urtd| j| jf ||j| j< d S |  ||S )Nz%cannot set attribute %r on <aenum %r>)ry   rx   r   r   clsnamerC   )r   r   rQ   r6   r6   r9   __set__6  s   

zproperty.__set__c                 C   sb   | j d u r,| js| jrtd| j| jf | j|jv r"|j| j= d S td| j| jf |  |S )Nz(cannot delete attribute %r on <aenum %r>z$no attribute %r on <aenum %r> member)rz   rx   ry   r   r   r   rC   )r   r   r6   r6   r9   
__delete__A  s   

zproperty.__delete__c                 C   s   || _ |j| _d S r<   )r   r   r   )r   r   r   r6   r6   r9   __set_name__P  s   zproperty.__set_name__)NNNNr<   )r   
__module____qualname__r{   r   r   r   r   r   r   r   r   r   r   r6   r6   r6   r9   r      s    


	r   c                   @      e Zd Zdd ZdS )SentinelTypec                 C   s
   d| j  S )Nz<%s>)r   clsr6   r6   r9   r   ]  rA   zSentinelType.__repr__N)r   r   r   r   r6   r6   r6   r9   r   \      r   Sentinelc                 C   s   | dk rdS | dt |  kS )Nr   FrT   )	_high_bitre   r6   r6   r9   _power_of_twoa  s   r   c                 C   s^   | dv rt | S d}| dk rd}|  } t| d? t | d@  }|r-dddd	 |D  }|S )
N)r   r   Fr   Tr   rU    c                 S   s   g | ]}d |dk qS )10rU   r6   ).0dr6   r6   r9   
<listcomp>o      zbits.<locals>.<listcomp>)strr   r   )rO   negativer   r6   r6   r9   r   f  s   r   c                 C   rM   )ae  
        return number of set bits

        Counting bits set, Brian Kernighan's way*

            unsigned int v;          // count the number of bits set in v
            unsigned int c;          // c accumulates the total bits set in v
            for (c = 0; v; c++)
            {   v &= v - 1;  }       //clear the least significant bit set

        This method goes through as many iterations as there are set bits. So if we
        have a 32-bit word with only the high bit set, then it will only go once
        through the loop.

        * The C Programming Language 2nd Ed., Kernighan & Ritchie, 1988.

        This works because each subtraction "borrows" from the lowest 1-bit. For example:

              loop pass 1     loop pass 2
              -----------     -----------
                   101000          100000
                 -      1        -      1
                 = 100111        = 011111
                 & 101000        & 100000
                 = 100000        =      0

        It is an excellent technique for Python, since the size of the integer need not
        be determined beforehand.
    r   r   r6   rN   r6   r6   r9   r   s  s   c                 C   s    d}| r|d7 }| dL } | s|S )Nr   r   r6   )rO   lengthr6   r6   r9   bit_len  s   r   c                 C   s   | dko| | d @ dkS )z<
    True if only one bit set in num (should be an int)
    r   r   r6   )rO   r6   r6   r9   r	     s   r	   c                 C   s@   t | tr
| t} t| d| } t| \}}}}|duo|duS )z6check if new generate method supports *args and **kwdsim_funcN)rE   staticmethodr   r   r~   
getargspec)methodargsvarargskeywordsdefaultsr6   r6   r9   _check_auto_args  s
   

r   c                    s   | s| S t | d  t ts&t fdd| dd D s"tdt| S t | d d  zt fdd| dd D rGt| dd	 d
W S td ty[   t| dd	 d
 Y S w )zC
    sorts things by value if all same type; otherwise by name
    r   c                 3   s    | ]	}t | u V  qd S r<   r   r   v	sort_typer6   r9   	<genexpr>      zenumsort.<locals>.<genexpr>r   Nz$cannot sort items of different typesc                 3   s     | ]}t |d   u V  qdS )r   Nr   r   r   r6   r9   r     s    c                 S      | d S Nr   r6   ir6   r6   r9   <lambda>      zenumsort.<locals>.<lambda>keyztry name sort insteadc                 S   r   Nr   r6   r   r6   r6   r9   r     r   )r   rB   tupleallrH   sorted)thingsr6   r   r9   enumsort  s   
r   c                   @   sF   e Zd ZeddZeddZeddZeddZed	d
Zdd Z	dS )EnumConstantsaddvaluez;prepends value(s) from _generate_next_value_ to each member
magicvaluez7calls _generate_next_value_ when no arguments are given
multivaluez#each member can have several valuesnoaliasz2duplicate valued members are distinct, not aliasedr   z(duplicate valued members are not allowedc                 C   s   | j d u rtd| j | j S )NzEnumConstant for %r has no name)_name_
ValueError_value_r   r6   r6   r9   r     s   
zEnumConstants.__repr__N)
r   r   r   constantr   r   r   r   r   r   r6   r6   r6   r9   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S )r   z+
    Helper class to track args, kwds.
    c                 O   s(   || _ t| | _t|| _d | _d S r<   )_argsdictrD   _kwdshash_hashr   )r   r   kwdsr6   r6   r9   r     s   

zenum.__init__c                 C      | j S r<   )r   r   r6   r6   r9   r        z	enum.argsc                 C   
   | j  S r<   )r   copyr   r6   r6   r9   r        
z	enum.kwdsc                 C   r   r<   )r   r   r6   r6   r9   __hash__   s   zenum.__hash__c                 C   s(   t || jstS | j|jko| j|jkS r<   rE   	__class__NotImplementedr   r   r   otherr6   r6   r9   __eq__     zenum.__eq__c                 C   s(   t || jstS | j|jkp| j|jkS r<   r   r   r6   r6   r9   __ne__  r   zenum.__ne__c                 C   sn   g }d dd | jD }|r|| d dd tt| j D }|r,|| d| jjd |f S )Nr   c                 S   s   g | ]}d |f qS )r   r6   r   ar6   r6   r9   r     s    z!enum.__repr__.<locals>.<listcomp>c                 S      g | ]
\}}d ||f qS )%s=%rr6   r   kr   r6   r6   r9   r         %s(%s))	r   r   r   r   rd   r   rD   r   r   )r   finalr   r   r6   r6   r9   r     s   
"
zenum.__repr__N)r   r   r   r{   r   bltin_propertyr   r   r   r   r   r   r6   r6   r6   r9   r     s    

r   no_valuec                   @   s<  e Zd ZdZeZeZg 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d Zdd Zdd Zdd ZerBd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,d- Zd.d/ Zd0d1 Z d2d3 Z!d4d5 Z"d6d7 Z#d8d9 Z$d:d; Z%d<d= Z&d>d? Z'e(d@dA Z)e)j*dBdA Z)dFdDdEZ+dCS )Gr   zP
    Instances are replaced with an appropriate value in Enum class suites.
    c                 C   0   |   }| jd d  |_|jt| |ff |S r<   r   _operationsr   _and_r   r   new_autor6   r6   r9   __and__      zauto.__and__c                 C   0   |   }| jd d  |_|jt|| ff |S r<   r   r   r6   r6   r9   __rand__&  r   zauto.__rand__c                 C   .   |   }| jd d  |_|jt| ff |S r<   )r   r   r   _inv_r   r   r6   r6   r9   
__invert__,     zauto.__invert__c                 C   r   r<   r   r   r   _or_r   r6   r6   r9   __or__2  r   zauto.__or__c                 C   r   r<   r  r   r6   r6   r9   __ror__8  r   zauto.__ror__c                 C   r   r<   r   r   r   _xor_r   r6   r6   r9   __xor__>  r   zauto.__xor__c                 C   r   r<   r
  r   r6   r6   r9   __rxor__D  r   zauto.__rxor__c                 C   r  r<   )r   r   r   _abs_r  r6   r6   r9   __abs__J  r  zauto.__abs__c                 C   r   r<   r   r   r   _add_r   r6   r6   r9   __add__P  r   zauto.__add__c                 C   r   r<   r  r   r6   r6   r9   __radd__V  r   zauto.__radd__c                 C   r  r<   )r   r   r   _neg_r  r6   r6   r9   __neg__\  r  zauto.__neg__c                 C   r  r<   )r   r   r   _pos_r  r6   r6   r9   __pos__b  r  zauto.__pos__c                 C   r   r<   r   r   r   _div_r   r6   r6   r9   __div__i  r   zauto.__div__c                 C   r   r<   r  r   r6   r6   r9   __rdiv__o  r   zauto.__rdiv__c                 C   r   r<   r   r   r   
_floordiv_r   r6   r6   r9   __floordiv__u  r   zauto.__floordiv__c                 C   r   r<   r  r   r6   r6   r9   __rfloordiv__{  r   zauto.__rfloordiv__c                 C   r   r<   r   r   r   	_truediv_r   r6   r6   r9   __truediv__  r   zauto.__truediv__c                 C   r   r<   r   r   r6   r6   r9   __rtruediv__  r   zauto.__rtruediv__c                 C   r   r<   r   r   r   _lshift_r   r6   r6   r9   
__lshift__  r   zauto.__lshift__c                 C   r   r<   r$  r   r6   r6   r9   __rlshift__  r   zauto.__rlshift__c                 C   r   r<   r   r   r   _rshift_r   r6   r6   r9   
__rshift__  r   zauto.__rshift__c                 C   r   r<   r(  r   r6   r6   r9   __rrshift__  r   zauto.__rrshift__c                 C   r   r<   r   r   r   _mod_r   r6   r6   r9   __mod__  r   zauto.__mod__c                 C   r   r<   r,  r   r6   r6   r9   __rmod__  r   zauto.__rmod__c                 C   r   r<   r   r   r   _mul_r   r6   r6   r9   __mul__  r   zauto.__mul__c                 C   r   r<   r0  r   r6   r6   r9   __rmul__  r   zauto.__rmul__c                 C   r   r<   r   r   r   _pow_r   r6   r6   r9   __pow__  r   zauto.__pow__c                 C   r   r<   r4  r   r6   r6   r9   __rpow__  r   zauto.__rpow__c                 C   r   r<   r   r   r   _sub_r   r6   r6   r9   __sub__  r   zauto.__sub__c                 C   r   r<   r8  r   r6   r6   r9   __rsub__  r   zauto.__rsub__c                 C   s   | j rdS d| j| j| jf S )Nz	auto(...)zauto(%r, *%r, **%r))r   _valuer   r   r   r6   r6   r9   r     s   zauto.__repr__c                 C   sF   | j tur| jrtd| j tu r| js| j S | j tur| j S |  S )Nzauto() object out of sync)r<  
_auto_nullr   rH   _resolver   r6   r6   r9   rQ     s   
z
auto.valuec                 C   s   | j r| |}|| _d S r<   )r   r>  r<  r   rQ   r6   r6   r9   rQ     s   

Nc                 C   s   | j }| jD ]5\}}g }|D ](}t||r1|jtu r*|d u r$t    S || q||j q|| q|| }qg | jd d < || _|S r<   )r   r   rE   rQ   r=  r   r<  )r   
base_valuer   opparamsvaluesparamrQ   r6   r6   r9   r>    s   


zauto._resolver<   ),r   r   r   r{   r=  enum_memberr<  r   r   r   r  r  r	  r  r  r  r  r  r  r  PY2r  r  r  r  r"  r#  r&  r'  r*  r+  r.  r/  r2  r3  r6  r7  r:  r;  r   r   rQ   r   r>  r6   r6   r6   r9   r     sT    


r   )_commonc                   @   s(   e Zd ZdZdZdZdZdZdd ZdS )	_EnumArgSpec)r   z all args except *args and **kwds)r   zthe name of the *args variable)rT   zthe name of the **kwds variable)rW   zany default values)   z0number of required values (no default available)c                 C   sN   t |}|\}}}}|r|dt|  }n|dd  }tt|||||fS r   )r   r]   r   __new__rH  )r   	_new_funcargspecr   r   r   r   reqsr6   r6   r9   rJ    s   z_EnumArgSpec.__new__N)	r   r   r   r   r   r   r   requiredrJ  r6   r6   r6   r9   rH    s    rH  c                   @       e Zd ZdZdd Zdd ZdS )_proto_memberzW
    intermediate step for enum members between class execution and final creation
    c                 C   s
   || _ d S r<   re   r?  r6   r6   r9   r     rA   z_proto_member.__init__c              
      sz  t || | j i }d}d}d}d}t tr& r&t d tr& } d  t tr7 jtu r7 j} j}n6t trJ j} jf j } j n#t trV j} j}nt t	rb j  f}nt tsk f}n }|dur f|dd   i } }~|j
sd|jv r|j
r|d }|dd }d|jv r|dd }n|}|dd }|d  nE|jr|jr|t|j d d }|js|dt|jj }|d  n!|jr|dd }|dd }|d  n|jr|d  n|}n|}|jtu r|f}|js||}	n|j|g|R i |}	t|	dsB|jtu r  |	_n"z|j|i ||	_W n tyA }
 z	td}|
|_|d}
~
ww |	j ||	_||	_|	j|i | t|j|	_tdurt|tr dur |j krv| j! O  _!t" r| j# O  _#|j$r|j%| nt&t'}zCz|j(  }	|j)r||	j* %| W n- ty   |j+D ]\}}|j*}||	jkr|j)r|| %| |}	 nqt,Y nw W n7 t,y   tdu st|ts|j%| ntdur	t|tr	 du st" r	|j%| Y nw |r9g }|- D ]\}}d.|}|%d	|||| jf  qt/d
|j0d.|f t| jtrD|	| j_1d}d}d}|j2dd D ]5}|j34|}|durt|t5t6frn|}|}d} nt7|r|}|pyd}|p~|}qQd}|}qQ|rt5 }|	|_8|9|| |dv rt:|dd|_;t:|dd|_<t:|dd|_=t:|dd|_>t:|dd|_?t:|dd|_@||_A||_BtC||| ntC|||	 |	|jD|<  f| }|j
r||vr||f7 }||	_E|D ]E |j
r |j(v stF fdd|j+D rt/d f z|j$rtd|	|j( < W q ty:   | j+ |	ff7  _+Y qw dS )zR
        convert each quasi-member into an instance of the new enum class
        r6   Nr   r   rQ   r   z/_value_ not set in __new__, unable to create it,z%s --> %s [%r]z%s: duplicate names found: %sz;  r   descattr)r   rR  rx   r   ry   r   rz   r   c                 3   s    | ]	\}}| kV  qd S r<   r6   r   r   rL   re   r6   r9   r     r   z-_proto_member.__set_name__.<locals>.<genexpr>z%r has already been usedzcannot use dict to store value)GdelattrrQ   rE   r   r   r=  r   r   r   Member_multivalue__creating_init__auto_init_
_new_args_r]   _auto_args__member_type_
_use_args__new_member_hasattrobjectr   	ExceptionrH   	__cause__r   __objclass__r   _member_names__sort_order_r$   rB   rp   rr   r	   rs   	_noalias_r   r   rd   _value2member_map__unique_r   _value2member_seq_r   rD   r   r   r   rE  __mro__rC   getr   rf   is_descriptorr   r   r~   rx   _getry   _setrz   _del
_attr_type	_cls_typesetattr_member_map__values_r:   )r   
enum_classmember_namer   r   	init_argsextra_mv_argsr   mv_argrE  excte	nonuniqueunhashable_valuecanonical_memberr   messagealiasesbad_aliasesfound_descriptordescriptor_type
class_typebaserS  redirectrC  r6   re   r9   r     sd  










 












z_proto_member.__set_name__N)r   r   r   r{   r   r   r6   r6   r6   r9   rP    s    rP  c                       sH   e Zd ZdZ fddZ fddZ fddZdd	 Zd
d Z  Z	S )r    zTrack enum member order and ensure member names are not reused.

    EnumType will use the names found in self._member_names as the
    enumeration member names.
    c                    s   t t|   || _|| _|| _|| _d | _g | _t	 | _
|| _t|v | _t|v | _t|v | _| jr;| jr;td| | jrG| jrGtd| || _|| _d| _d| _t|v| _g | _g | _| jrfg d| _d| _d| _g | _d| _d S )Nz2%r: AddValue and MagicValue are mutually exclusivez4%r: MultiValue and MagicValue are mutually exclusiver6   F)r   r   classmethodT)superr    r   	_cls_name_constructor_init_constructor_start_constructor_boundary_generate_next_value_member_namesset_member_names_set	_settingsr   	_addvaluer   _magicvaluer   _multivaluerH   _start_addvalue_value	_new_args
_auto_args_locked_init_ignore_ignore_init_done_allow_init_last_values_auto_called)r   cls_namesettingsstartconstructor_initconstructor_startconstructor_boundaryr   r6   r9   r   	  s:   





zEnumDict.__init__c                    s   || j kr| j | vrtS | js || v s || jv s t|s t|r(tt| |S | j	rD| 
|| jt| j| jd d  }| || |S td)Nz"Magic is not set -- why am I here?)r  r   r  r  	is_sunder	is_dunderr  r    __getitem__r  r  r  r]   r  r  __setitem__ra  r   r   rQ   r  r6   r9   r  ,  s    
"zEnumDict.__getitem__c                    s*  d}t | j|r
n+t| j|rn#t|r|dvr$td| j|f | js4|dvr4td| j|f |dkrr| jrBtd| j t|t	rL|
 }nt|}|| _t|| j@ }|rmtd| jd	d
d |D f d| _n|dkr| jrtd| j n|dkr| jrtd| j || _n|dkr.t|ttfs|f}t|tst|}|  j|O  _t|v rt|v rtd| j t|v rt|v rtd| j tg d}| jD ]}||vrtd| j||f d||< q|d | _|d | _|d | _| j | _| jr| jsg d| _| jr'| jr'd| jvr'| jdd t| j}n|dkrq| j r>td| j |}t|t	rN|!dd
 }| jr_d| jvr_| jdd | jrjtd| j || _|}n|d kr| j"r~td!|}|d"urt|t#r|j$}nt|t%rtd#| j |}t#|}t&|| _'t(| d$| nt)|r|d%krd&}| jstd| j|f n#|d'krt|t#r|j$}t*|| _+n|d(krt|t%st%|}t,|rd| _n?|| jv rtd)| j|f || jv rn(t,|s/d*| _|| v r&td+| j|| | f t-|t.u r<||_/| jr;td,| j n| jrK| jsK| 0||}n| jr{t-|turY|f}t|d t1rp| 2||d f|d-d"  }| jrz| 0||}nwt|t1r| 2||}njt-|tu rt3d.d |D rg }	|D ]}
t|
t1rd*}| 2||
}
|
j4}
| j56|
 |	6|
 qt|	}n0t|t1s| j+o| j+j7}t8| jp|}t|trt8|}nd-}||k r| 0||}n	 | jr"t|t1r |j9}nt|ts
|f}n|}t8| jt8|kr"td0| j|| j|f | j:6| | j;| nd| _d*| _t|st)|st| j|st,|s|sQd}n9t|t1r_| j56|j4 n+t-|tu r|rt|d t1r{| j56|d j4 n| j56|d  n| j56| t<t=| >|| d"S )1zChanges anything not sundured, dundered, nor 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.
        T)_init_
_settings__order__ignore__start__create_pseudo_member__create_pseudo_member_values__generate_next_value_rq   _numeric_repr_	_missing__missing_value__missing_name__iter_member__iter_member_by_value__iter_member_by_def_z@%r: _sunder_ names, such as %r, are reserved for future Enum use)create_pseudo_member_r  r  r  z"%r: cannot set %r after init phaser  z%%r: ignore can only be specified oncez0%r: _ignore_ cannot specify already set names %sr   c                 s       | ]}t |V  qd S r<   reprr   r6   r6   r9   r   j      z'EnumDict.__setitem__.<locals>.<genexpr>rq   z4%r: boundary specified in constructor and class bodyr  z1%r: start specified in constructor and class bodyr  -%r: NoAlias and Unique are mutually exclusivez*cannot specify both MultiValue and NoAliasr   r   r   r   r   z"%r: unknown qualifier %r (from %r)r   r   r   )r   r  r   rQ   r   r  z3%r: init specified in constructor and in class bodyrQ   z0%r: _init_ and MagicValue are mutually exclusiver  z4_generate_next_value_ must be defined before membersNzB%r: _generate_next_value must be a staticmethod, not a classmethodr  	__order__r  rJ  __init_subclass__z%r: attempt to reuse name: %rFz%r: %s already defined as %rz(%r: enum() and AddValue are incompatibler   c                 s       | ]}t |tV  qd S r<   )rE   r   r   r6   r6   r9   r         r6   z=%s.%s: number of fields provided do not match init [%r != %r])?is_internal_classr  is_private_namer  r   r  r  rH   rE   
basestringsplitrd   r  r  r  r   r  r  r  r   r  r   r   r   r   fromkeysr  r  r  r  r  insertr  r\   r  r   __func__r  r   r  rr  r  rH  r  rl  r   r   r   _gnvr   _convert_autor:   rQ   r  r   rN  r]   r   r  addr  r    r  )r   r   rQ   
auto_storealreadyallowed_settingsargr  gnvauto_valuedr   new_args
target_len
source_len
test_valuer  r6   r9   r  >  s\  
























"


,zEnumDict.__setitem__c                 C   s   |j s|js|jtu rL|j s|jr|j }nd}| jo| jj}t| jp#|p&d}t|t	u r2t|}nd}||k rL| 
||}d| _|j rI||_|S ||_|S )Nr6   r   T)r   r   rQ   r=  r  rN  r]   r  r   r   r  r  r   )r   r   rQ   rC  r  r  r  r6   r6   r9   r    s"   
zEnumDict._convert_autoc                 C   s   | j r!t|ts|f}| j|| jt| j| jd d  g|R  }n| || jt| j| jd d  }t|trAt|dkrA|d }|S Nr   r   )r  rE   r   r  r  r]   r  r  r  r6   r6   r9   r  %  s   
,"zEnumDict._gnv)
r   r   r   r{   r   r  r  r  r  __classcell__r6   r6   r  r9   r      s    # Qr    r   c                       s  e Zd ZdZed6ddZdd Zd6 fdd		Zd
d Ze	ddddddfddZ
dd Zdd Zdd Zedd Zdd Zdd Zdd Zdd ZeZdd  Zd!d" Zd#d$ Zd7d&d'Zd8d(d)Zed*d+ Zed,d- Zed.d/ Zed0d1 Zed2d3 Zed4d5 Z   Z!S )9r   zMetaclass for EnumNr6   c                    s  |  || td u r|dkrd}nd}|d u}	|d u}
|d u}t|ts'|f}t|}d }d }| ||\ }|d urbt|dd }t|d|}|| |O }|pV|jd d  }|j	}|d u ra|j
}nd}t|v r~|r~d|vr~t|trz|dd nd	| }t|v rt|v rtd
| t|v rt|v rtd| tg d}|D ]}||vrtd||f qt||||	|
|d} |_dtd u r|dkptd uotdd |D  |_td urtdd |D r ttf vrt|v rdd }t||d<  fdd}||d< nOzt|j|_W nF ty   Y n=w |sKt|dr*t|j|_|r4||d< d|_|d urJt|t rG|!dd" }||_#nt|drWt|j|_|d urbt||d< |S )Nr$   TFr  r   r   rQ   r   zvalue r  z1%r: MultiValue and NoAlias are mutually exclusiver  z%r: unknown qualifier %r)r  r  r  r  r  r  )r   flagc                 s   r  r<   )rB   r$   r   br6   r6   r9   r   f  r  z'EnumType.__prepare__.<locals>.<genexpr>c                 s   s    | ]}|t u V  qd S r<   )r$   r  r6   r6   r9   r   h  r  c                 _   s   d| f| S )NrT   r6   )r   r  rP   rC  r   r   r6   r6   r9   r  q  s   z3EnumType.__prepare__.<locals>._generate_next_value_c                    s     | |}||_|S r<   )rJ  r   )r   
flag_value
type_valueobjmember_typer6   r9   rJ  t  s   z%EnumType.__prepare__.<locals>.__new__rJ  __new_member__rQ  r  r  )$_check_for_existing_members_r$   rE   r   r  _get_mixins_r~   _get_settings_rY  _order_function_r  r   rd   r  r   r   rH   r   r   r  r    _member_typer:   
_base_typebaseintegerr`  r   rH  r  r  r_  _inherited_gnvr  r\   r  r  )metaclsr   basesinitr  r  rg   r   initial_flagr  r  r  generateorder
first_enumr  r  	enum_dictr  rJ  r6   r  r9   __prepare__6  s   

.



zEnumType.__prepare__c                 O   s   d S r<   r6   )r   r   r   r6   r6   r9   r     s   zEnumType.__init__c           ?   
      s~  t |tur|dd }|dd }|dd}|d|dd }	|dd }
|dd }|d	d }|d
d }|dd }|dd }|dd }|dd }|dd }|dd }|dd }|dd }t|d|}t|d|}t fdd| D }|}| j |||d}|r||d< |p|j}|	d u r|d}	|	d ur|		 }	t
|tr|}n|	d u rdd tt| D }nt
|	tr|	dd  }}	nwt|	rK|rt
|tsd|}td|rd| pddg}g }| D ]D\}}|rt
|ts
|f}|f| }nt||f}|jt|kr7td|jd |jt|d d!d |D f |||  qd"d t||	d#D }n|	}d$D ]}t | }|d ur_|||< qO|D ]}z	|| ||< W qc tyy   Y qcw | D ]\}}||vr|||< q~~	~
~~~~~~d%|_|j} t| td&d'g@ }!|!rt d(d |!f |dd }	t
|	tr|	dd }	|j}|j!}|j"}g }"|j#}#|j$}$d)}%|d urd%}%|d d  }"d|"v r|"d* dkrtd+t%|v }&t&|v }'t'|v }(t(|v })|)dg d |d }*|*D ]	}+||+d  q|p'|dd }|d
},|,d ur=t |,t*ur=t*|,},t| }|,d urL|,|d
< | + |\}-| ,||-\}}.}/t*||d,< |/|d-< d*}0| D ]K}||  }}1t
|t-r|j.t/ur|j.}1t
|1t0r|1d*kr|0|1O }0t
|1tr|1rt
|1d* t0r|1d* d*kr|0|1d* O }0t1|||< qld.|02  d/ }2|"|d0< |'|d1< |&|d2< |(|d3< |)|d4< g |d5< t |d6< |d7< i |d8< d|d9< ||d< ||d< ||d:< |#|d;< |$|d<< d |d=< | 3 ||d>< |pt|-dd |d< d*|d?< d*|d@< |2|dA< d |dB< t4d urq|rqt5|dC t4rq| D ]:}3||3 }4t
|4j.t6rQ|4j.d*k rO|0|4j.@ |4_.q6|4j.d u rYq6t
|4j.t-ro|4j.j.d*k ro|0|4j.j.@ |4j._.q6| D ]\}}5t
|5t7r|5j.||< qud)}6dD|vrt8urdE}7t9fdFdG|7D st:| d%}6dH|vrdI|dH< zd }8t ;|  ||W n* t<y }9 z|9j=p|9}8|8d }9~9w t>y }9 z	t?|9dJr|9`@ d }9~9ww tAtBk r*| D ]}jC| D| qjC D ]\}}5|| v r
qt?|5dKr|5D| qtEd ur*t?dLr*tFG  tHd urdtH|v rdt8u r=tdMdN|vrKjI_IjI|dN< dO|vrdjJ}:|:t8jJu r\jK}:|:_JjJ|dO< dPD ]9}||v roqft|};t|d }<t|-|d }=|<d ur|<|;kr|dDkr|6rqftL||= |=||< qft4d urt5t4rdQD ]}||vrtL|tt4| |=||< qtAtMk rt5t6rtLdRtt6dR ntNrt5t6rdSD ]}:tL|:tt6|: qtEd ur
|.rtLdTjCd  tLdtEjCd  |	r+t
|	t*r|	jO}	t|	r+t*|	_PdUd t|	d#D }	t4d u r5 dVks@t4d urZt5t4sZtQd tQd? tQd@ tQdA tQdB n)t4d urt5t4rdWd D }>|>t|>krwjR_S|	rfdXd|	D }	jC D ]\}}t
|tTrt
|j.t-r|j.j.|_.q|	rfdYd|	D }	|	jUkrtdZjU|	f S )[Nr  r  r  r6   r  r  r  r  r  r  r  r  r  rq   r  r  r  rJ  r   r  c                    s:   g | ]\}}t |st|st |st|s||fqS r6   )r  r  r  rl  r   r   r6   r9   r     s    z$EnumType.__new__.<locals>.<listcomp>)r  r  c                 S      g | ]\}}|qS r6   r6   r   r   rQ   r6   r6   r9   r         rQ  r  r   zname r   rQ   z)%d values expected (%s), %d received (%s)r   c                 S   s   g | ]}t |qS r6   r  r   r6   r6   r9   r     r  c                 S      g | ]}|j qS r6   r   r   rL   r6   r6   r9   r         r   )r  r  r  r  r  r  r  r  rJ  r  r  r  rq   r  r  r  Tmror   zinvalid enum member name(s): %sFr   z7'value', if specified, must be the first item in 'init'r^  r]  rT   r   rX  rW  _magicvalue_rf  rh  rd  rs  r\  rg  ri  rY  rZ  r[  r  _value_repr_rr   rs   rp   
_inverted_rX   __reduce_ex__)__getnewargs_ex____getnewargs__r  
__reduce__c                 3   s    | ]}| j v V  qd S r<   rC   r  r  r6   r9   r   q  r  z#EnumType.__new__.<locals>.<genexpr>r{   zAn enumeration.	__notes__r   r  zOReprEnum subclasses must be mixed with a data type (i.e. int, str, float, etc.)
__format____str__)r   r	  r  r  )r  r   r  r	  r   r  r  __cmp__)__le____lt____gt____ge__r   r   r   r  c                 S   r  r6   r  r  r6   r6   r9   r     r  r$   c                 S   s   g | ]
}|j d ur|j qS r<   r   r  r6   r6   r9   r      r   c                    s(   g | ]}| j vst | jr|qS r6   )rs  r	   r   r   oru  r6   r9   r     s
    c                    s.   g | ]}| j vs| j v r| jv r|qS r6   )rs  rd  r  r  r6   r9   r     s    
z*member order does not match _order_:
%r
%r)Vr   r    popr~   r   rD   r  r  rk  r   rE   OrderedDictr   rd   r  r\   r  callabler   r   r   _defined_len_r]   rH   _fields_r   r   localsr   r  r  r  r   r  r  r  r  r   r   r   r   
setdefaultr   r  
_find_new_r   rQ   r=  r  rP  rZ   _find_data_repr_r$   rB   int	nonmemberr`  r:   make_class_unpicklablerJ  RuntimeErrorrb  ra  r_  r  pyverPY3_6rC   r   r!   r  r  r(   r  r	  r   rr  PY2_6rF  r  r  rU  r  r  r   rd  )?r  r   r  clsdictr  r  r  rg   r   r  r  r  r  r  r  r  r  rq   r  r  r  rJ  enum_membersoriginal_dictcalced_orderr   r   rQ   
name_valuerS  r   r   member_namesinvalid_namescreating_initr  	auto_args	auto_initr   r   r   r   ignorer   r  r  save_newnew_uses_argsrj   r  rh   rI   pr  unpicklablemethodsrz  er   class_method
obj_methodenum_methodmember_valuesr  )r   ru  r  r9   rJ    s<  















0

 




	









	









	zEnumType.__new__c                 C      dS )z6
        classes/types should always be True.
        Tr6   r   r6   r6   r9   __bool__"     zEnumType.__bool__r   c              	   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: `module`, if set, will be stored in
        the new class' __module__ attribute; `type`, if set, will be mixed in
        as the first base class.

        Note: if `module` is not set this routine will attempt to discover the
        calling module by walking the frame stack; if this is unsuccessful
        the resulting class will not be pickleable.
        N)modulequalnamer   r  rg   )rJ  _create_)r   rQ   namesr;  r<  r   r  rg   r6   r6   r9   __call__(  s   zEnumType.__call__c                 C   sB   t || rdS z|| jv W S  ty    |dd | jD v  Y S w )zReturn True if `value` is in `cls`.

        `value` is in `cls` if:
        1) `value` is a member of `cls`, or
        2) `value` is the value of one of the `cls`'s members.
        Tc                 S   r  r6   r6   rT  r6   r6   r9   r   H  r  z)EnumType.__contains__.<locals>.<listcomp>)rE   rg  rH   ri  r   rQ   r6   r6   r9   __contains__<  s   
zEnumType.__contains__c                 C   sn   || j v rtd| j|f t| |}t|tr!td| j|f t|tr/td| j|f t| | d S )Nz!%s: cannot delete Enum member %r.z%s: cannot delete constant %rz%s: cannot delete property %r)	rs  r   r   get_attr_from_chainrE   r   r   r   __delattr__)r   rS  
found_attrr6   r6   r9   rC  J  s   



zEnumType.__delattr__c                 C   s   t | jg d }| jtjur|d | jtjur|d ttdr)|d dD ]}t	| |t	t|t	t
|fvrA|| q+| jtu rKt|S tt t| j|B S )N)	r   rA  r{   r  __iter____len__rG   r   r   rJ  r  r   )r   r  r   r	  )r  rd  r^  r`  rJ  r  r  r!   r_  r~   r$   r\  r   dir)r   interestingr   r6   r6   r9   __dir__\  s   





zEnumType.__dir__c                 C   r   )zReturns a mapping of member name->value.

        This mapping lists all enum members, including aliases. Note that this
        is a copy of the internal mapping.
        )rs  r   r   r6   r6   r9   rG   q  s   
zEnumType.__members__c                 C   s   z| j | W S  ty   t d }Y nw td urBt| trBd|v rBz| d}|dD ]}|| | O }q-|W S  tyA   |w | |}t|| rN|S |)Nr   |r   )	rs  r   _sysexc_infor$   rB   r  r  rE   )r   r   rz  r   rI   r6   r6   r9   r  z  s$   

zEnumType.__getitem__c                    s    fdd j D S )Nc                 3       | ]} j | V  qd S r<   rs  r   r   r   r6   r9   r     r  z$EnumType.__iter__.<locals>.<genexpr>rd  r   r6   r   r9   rE    s   zEnumType.__iter__c                    s    fddt  jD S )Nc                 3   rM  r<   rN  rO  r   r6   r9   r     r  z(EnumType.__reversed__.<locals>.<genexpr>)reversedrd  r   r6   r   r9   __reversed__  s   zEnumType.__reversed__c                 C   
   t | jS r<   )r]   rd  r   r6   r6   r9   rF    rA   zEnumType.__len__c                 C   sH   t d urt| t rd| jf S td urt| trd| jf S d| jf S )Nz
<aenum %r>z
<aflag %r>z<aenum obj %r>)r!   rB   r   r$   r   r6   r6   r9   r     s
   zEnumType.__repr__c                 C   s   | j di }||v rtd| j|f t| |}t|tr'td| j|f t|ttfr<t|ts<td| j|f t	
| || dS )a  Block attempts to reassign Enum members/constants.

        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.
        rs  z%s: cannot rebind member %r.z%s: cannot rebind constant %rz%s: cannot rebind property %rN)rC   rk  r   r   rB  rE   r   r   r   r   __setattr__)r   r   rQ   
member_maprD  r6   r6   r9   rT    s   

zEnumType.__setattr__c                 O   s(   dd l }|jdtdd | j|i |S )Nr   zB_convert is deprecated and will be removed, use _convert_ instead.rT   )
stacklevel)warningswarnDeprecationWarning	_convert_)r   r   r   rW  r6   r6   r9   _convert  s
   zEnumType._convertFc           	         s   t tj| }rt n| fdd D }z
|jdd d W n ty7   |jdd d Y nw | ||||p?td} t| _|rLt	|  n|
| j | ||< | S )z[
        Create a new Enum subclass that replaces a collection of global constants
        c                    s    g | ]} |r|| fqS r6   r6   )r   r   filtersourcer6   r9   r     s     z&EnumType._convert_.<locals>.<listcomp>c                 S   s   | d | d fS r  r6   tr6   r6   r9   r     s    z$EnumType._convert_.<locals>.<lambda>r   c                 S   r   r   r6   r_  r6   r6   r9   r     r   )r;  rg   )varsrK  moduleskeyssortrH   r/   r4   r  global_enumupdaterG   )	r   r   r;  r]  r^  rg   	as_globalmodule_globalsmembersr6   r\  r9   rZ    s"   	

zEnumType._convert_c              	   C   s  t rt|trz|d}W n ty   td|f w | j}|du r(| f}	n|| f}	| ||	\}
}t|dd}t|d|}t|t	rM|
dd }t|ttfr|rt|d t	r|g }}g }t|D ]\}}|||||dd }|| |||f qhd}d}|D ])}|du rt|t	ri }n|||	}t|t	r||| }}n|\}}|||< q|du r|||	}|j|||	||d	}|du rz
td
jd }W n 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 auto-numbered from 1.
        * An iterable of member names.  Values are auto-numbered from 1.
        * An iterable of (member name, value) pairs.
        * A mapping of member name -> value.
        asciiz %r is not representable in ASCIINr  r   rQ  r  r   )rg   rT   r   )rF  rE   unicodeencodeUnicodeEncodeErrorrH   r   r  r~   r  r\   r  r   rd   	enumerater   r  rJ  rK  	_getframe	f_globalsr   r   r  r   r   )r   
class_namer>  r;  r<  r   r  rg   r  r  _r  r  original_nameslast_valuesrP   r   rQ   itemr#  rv  member_valueru  r6   r6   r9   r=    sb   

 





zEnumType._create_c                 C   sF   t d u rd S |D ]}|jD ]}t|t r|jrtd||f qqd S )Nz<aenum %r> cannot extend %r)r!   rj  rB   rd  rH   mclsrq  r  chainr  r6   r6   r9   r  #  s   
z%EnumType._check_for_existing_members_c                 C   sp   |rt du r
tt fS | || |d }|tv r|d }t|t s%td| ||p,t}|jr4td||fS )zReturns the type for creating enum members, and the first inherited
        enum class.

        bases: the tuple of bases that was given to __new__
        NrX   zZnew enumerations should be created as `EnumName([mixin_type, ...] [data_type,] enum_type)`z*cannot extend enumerations via subclassing)r!   r`  r  rF   rB   rH   _find_data_type_rd  )rx  rq  r  r  r  r6   r6   r9   r  .  s   
zEnumType._get_mixins_c                 C   s   |D ]@}|j D ]:}|tft v rqt|tr|j    S d|jv rAd|jv r8d|jv r8|jd jr8t    S |jd     S qqd S )Nr   __dataclass_fields____dataclass_params__)	rj  r`  rF   rE   r   r   rC   r  _dataclass_reprrw  r6   r6   r9   r  H  s    





zEnumType._find_data_repr_c                 C   s   t  }|D ]L}d }|jD ]D}|tft v rqt|tr)|jtur(||j  n)qd|jv s3d|jv rLt|tr9qt	d urCt
|t	rCq||pH|  n|pO|}qqt|dkr`td||f |rf| S d S )NrJ  r|  r   z%r: too many data types: %r)r  rj  r`  rF   rE   r   r\  r  rC   
StdlibFlagrB   r]   rH   r  )rx  rq  r  
data_typesry  	candidater  r6   r6   r9   r{  ^  s2   




zEnumType._find_data_type_c                 C   s@   t  }| D ]}|jD ]}t|tr|jD ]}|| qq
q|S )zuReturns the combined _settings_ of all Enum base classes

        bases: the tuple of bases given to __new__
        )r  rj  rB   r!   r  r  )r  r  ry  r  ra   r6   r6   r9   r  z  s   


zEnumType._get_settings_c           
      C   s   | dd}|duo|du}|du r>dD ]&}||fD ]}t||d}|ddjtjtjtjfvr3|} nq|dur: nqtj}|du sJ|tjtjfv rMd}	nd}	|||	fS )a
  Returns the __new__ to be used for creating the enum members.

        clsdict: 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__
        rJ  N)r  rJ  FT)rk  r~   rJ  r`  r!   
StdlibEnum)
rx  r#  r  r  rJ  r.  r   possibletargetr/  r6   r6   r9   r    s0   	
zEnumType._find_new_)NNr6   N)NNF)NNNr   N)"r   r   r   r{   r  r  r   rJ  r9  r   r?  rA  rC  rI  r   rG   r  rE  rR  rF  __nonzero__r   rT  r[  rZ  r=  r  r  r  r{  r   r  r  r  r6   r6   r  r9   r   3  sL    W   


G





r   c                   @   s   e Zd ZdS )r   N)r   r   r   r6   r6   r6   r9   r     s    r!   zNGeneric enumeration.

    Derive from this class to define new enumerations.

)r   r   nsc                 C   s   | j rdS dS )Nz	(*values)z\(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)rP  r   r6   r6   r9   __signature__  s   r  c                 O   s   | j }|d u r	d S d|v r|dd  }|rtt|t|k r+tdt||t||f t||D ]
\}}t| || q0t|t|k rv|t|d  }|D ]}||t}|tu r`td|f t| || qM|rxtdd|  d S d S d S )NrQ   r   z,%d arguments expected (%s), %d received (%s)zmissing value for: %rzinvalid keyword(s): %sr   )	rY  r]   rH   ziprr  r  	undefinedr   rc  )r   r   r   rY  r   r  remaining_argsrQ   r6   r6   r9   r     s0   r   c                 C   s   t | jv r	tdt|| u r|S z| j| W S  ty    Y n ty:   | jD ]\}}||kr7|   Y S q)Y nw | |}t|| rG|S |d urUt	| dd t
u rU|S |d u rn|tu retd| jf td|| jf td| j|f )Nz1NoAlias enumerations cannot be looked up by valuerq   z"%s() should be called with a value%r is not a valid %szDerror in %s._missing_: returned %r instead of None or a valid member)r   r  rH   r   rg  r   ri  r  rE   r~   r.   r   r   r   )r   rQ   rv  r   r   r6   r6   r9   rJ    s:   


rJ  c                 K   s8   t tk r|rtd|f d S tt| jdi | d S )Nz unconsumed keyword arguments: %rr6   )r   r!  rH   r  r!   r  )r   r   r6   r6   r9   r  	  s
   r  c              	   O   sD   t |D ]}z|d }W  n ty   Y qw |}|r |f| S |S r   )rQ  rH   )r   r  rP   rt  r   r   
last_value	new_valuer6   r6   r9   r  	  s   
r  c                 C   r8  )z'deprecated, use _missing_value_ insteadNr6   r@  r6   r6   r9   r  +	  r:  r  c                 C   
   |  |S )zused for failed value access)r  r@  r6   r6   r9   r  1	  s   
r  c                 C   r8  )zused for failed item accessNr6   )r   r   r6   r6   r9   r  7	  r:  r  c                 C   s,   | j jp| jj j}d| j j| j|| jf S )Nz<%s.%s: %s>)r   r   r   r   r   r   )r   v_reprr6   r6   r9   r   =	  s   r   c                 C   s   d| j j| jf S N%s.%s)r   r   r   r   r6   r6   r9   r	  B	  s   r	  c                    s    j jtu rtg d}nt fddt D }t dg D ]}|d dkr3| jvr3|| q! j  D ]9}|j	
 D ]1\}}|d dkrKq@t|trf|jdusZ| jvr`|| q@|| q@t| j sq|| q@q9t|S )z,
        Returns all public methods
        )r   r{   r   r   r   c                 3   s    | ]
}| j vr|V  qd S r<   rN  )r   rI   r   r6   r9   r   O	  s    z__dir__.<locals>.<genexpr>rC   r   rr  N)r   r\  r`  r  rI  r~   rs  r  r  rC   rD   rE   r   rx   discardr   )r   rH  r   r   r  r6   r   r9   rI  G	  s(   


rI  c                 C   s   t t | |S r<   )r   r  )r   format_specr6   r6   r9   r  b	     r  c                 C   rS  r<   )r   r   r   r6   r6   r9   r   f	  r   r   c                 C   s   | j | jffS r<   )r   r   r   protor6   r6   r9   r  j	  s   r  c                 C      t d| jj|jjf )Nzunorderable types: %s() <= %s()rH   r   r   r   r6   r6   r9   r  n	     r  c                 C   r  )Nzunorderable types: %s() < %s()r  r   r6   r6   r9   r  r	  r  r  c                 C   r  )Nzunorderable types: %s() >= %s()r  r   r6   r6   r9   r  v	  r  r  c                 C   r  )Nzunorderable types: %s() > %s()r  r   r6   r6   r9   r  z	  r  r  c                 C   s   t || jr
| |u S tS r<   rE   r   r   r   r6   r6   r9   r   	     r   c                 C   s   t || jr
| |uS tS r<   r  r   r6   r6   r9   r   	  r  r   c                 C   r   r<   r   r   r6   r6   r9   r   	     r   c                 C   r   r<   r  r   r6   r6   r9   rQ   	  r  rQ   c                 C   r   r<   )rt  r   r6   r6   r9   rC  	  r  rC  c                 C   r   r<   r  r  r6   r6   r9   pickle_by_global_name	  r   r  c                 C   s   t | j| jffS r<   )r~   r   r   r  r6   r6   r9   pickle_by_enum_name	  r  r  c                    s$   j  d fdd  D S )Nr   c                 3   s,    | ]} | j rd |t|f V  qdS )r   N)r  r~   )r   r   dcfr   r6   r9   r   	  s    
z"_dataclass_repr.<locals>.<genexpr>)r|  r   rc  r   r6   r  r9   r~  	  s   r~  r(   r{   zIOnly changes the repr(), leaving str() and format() to the mixed-in type.c                   @   s   e Zd ZdZdS )r"   z8
    Enum where members are also (and must be) ints
    N)r   r   r   r{   r6   r6   r6   r9   r"   	      r"   c                   @   s&   e Zd ZdZdd ZejZdd ZdS )r#   zr
    Enum where members are also (and must already be) strings

    default value is member name, lower-cased
    c                 O   sb   |r	t d| j |r"t|d ts"t d| j|d t|d f t| }t| |}||_|S )Nz#%r: keyword arguments not supportedr   z#%s: values must be str [%r is a %r])rH   r   rE   r   r   rJ  r   )r   rC  r   rQ   r   r6   r6   r9   rJ  	  s    zStrEnum.__new__c                 C      |   S )zD
        Return the lower-cased version of the member name.
        )lower)r   r  rP   rt  r6   r6   r9   r  	  s   zStrEnum._generate_next_value_N)r   r   r   r{   rJ  r   r	  r  r6   r6   r6   r9   r#   	  s
    r#   c                   @      e Zd ZdZdd ZdS )r&   z}
    Enum where members are also (and must already be) lower-case strings

    default value is member name, lower-cased
    c                 O   6   t j| |g|R i |}|| krtd| |S )Nz%r is not lower-case)r#   r  r  r   r   rQ   r   r   r  r6   r6   r9   rJ  	     zLowerStrEnum.__new__Nr   r   r   r{   rJ  r6   r6   r6   r9   r&   	  s    r&   c                   @   rO  )r'   z}
    Enum where members are also (and must already be) upper-case strings

    default value is member name, upper-cased
    c                 O   r  )Nz%r is not upper-case)r#   r  upperr   r  r6   r6   r9   rJ  	  r  zUpperStrEnum.__new__c                 O   r  r<   )r  )r   r  rP   rt  r   r   r6   r6   r9   r  
  s   z"UpperStrEnum._generate_next_value_N)r   r   r   r{   rJ  r  r6   r6   r6   r9   r'   	  s    r'   c                   @      e Zd ZdZeZdS )AutoEnumza
        automatically use _generate_next_value_ when values are missing (Python 3 only)
        N)r   r   r   r{   r   r  r6   r6   r6   r9   r  
      r  c                   @   r  )r   z
    Automatically assign increasing values to members.

    Py3: numbers match creation order
    Py2: numbers are assigned alphabetically by member name
         (unless `_order_` is specified)
    c                 O   sR   t | jd }| jtu rt| |}n| jtu rt| |}nt| }||_|S r   )r]   rG   r\  r  rJ  longr`  r   )r   r   r   rQ   r  r6   r6   r9   rJ  
  s   


zAutoNumberEnum.__new__Nr  r6   r6   r6   r9   r   
  s    r   c                   @   s   e Zd ZeZdS )r   N)r   r   r   r   r  r6   r6   r6   r9   r   %
  r  r   c                   @   r  )r   z1
    Multiple values can map to each member.
    N)r   r   r   r{   r   r  r6   r6   r6   r9   r   )
  r  r   c                   @   r  )r   zQ
    Duplicate value members are distinct, but cannot be looked up by value.
    N)r   r   r   r{   r   r  r6   r6   r6   r9   r   0
  r  r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )r   z7
    Add ordering based on values of Enum members.
    c                 C   s   | j |j u r| j|jkS tS r<   r   r   r   r   r6   r6   r9   r  <
     zOrderedEnum.__ge__c                 C   s   | j |j u r| j|jkS tS r<   r  r   r6   r6   r9   r  A
  r  zOrderedEnum.__gt__c                 C   s   | j |j u r| j|jkS tS r<   r  r   r6   r6   r9   r  F
  r  zOrderedEnum.__le__c                 C   s   | j |j u r| j|jk S tS r<   r  r   r6   r6   r9   r  K
  r  zOrderedEnum.__lt__N)r   r   r   r{   r  r  r  r  r6   r6   r6   r9   r   7
  s    r   c                   @   r   )r)   c                 C   s   |t ju r| jS d S r<   )r*   PrepareProtocolr   )r   protocolr6   r6   r9   __conform__S
  s   
zSqliteEnum.__conform__N)r   r   r   r  r6   r6   r6   r9   r)   R
  r   c                   @   r  )r   z+
    Ensure no duplicate values exist.
    N)r   r   r   r{   r   r  r6   r6   r6   r9   r   X
  r  r   c                    sf   t tj| }|rt |}n|}t fdd| D }| |||d} t| _|| j | ||< dS )aL  
    Create a new Enum subclass that replaces a collection of global constants

    enum: Enum, IntEnum, ...
    name: name of new Enum
    module: name of module (__name__ in global context)
    filter: function that returns True if name should be converted to Enum member
    source: namespace to check (defaults to 'module')
    c                 3   s$    | ]\}} |r||fV  qd S r<   r6   r  r]  r6   r9   r   s
  s   " zconvert.<locals>.<genexpr>r;  N)	ra  rK  rb  r   rD   r4   r  rf  rG   )r   r   r;  r]  r^  rh  ri  r6   r  r9   convert_
  s   
r  c           $      O   s  || j v s|| jv s|dd t| ddD v r&td|| j || | f d}| jdd D ]}|j |}|durMt|ttfrD n
td||j	f q/z| j}| j
}| j}| j}	td	d |  D }
W n tyu   td
| f w z| j}t| jv }t| jv }t| jv }| jpg }W n ty   g }d}d}d}g }Y nw |r|std| j	 |j}t| ddpt| ddp|}|sdd | D }t| }t| dd}|du r|r|d d pd}t| dd}|dur|||||f}n|f}|tju rd}nd}t|dkr|\}n|}d}i }t|tr|j}|j}t|ts'|f}n|}d|v rEd|v r9|d}n#|d |dd }}n|r\|d |dd d}}}|r\|f}|tu rd|f}|su|| }t|dst||_ n|| g|R i |}t|ds|| |_ |j }|rd|v r|}n|f| }||_!| j"|_#|j$|  |f| |_%t| j
|_&d }}t| dr| j'|B }| j(|B }| j)dkrt*t+|| @ }|rtd| j	d,dd |D f |rt-| |||dS |j%}|. D ]:}t|d|j g}|D ],} |D ]&}!| |!kr4|s|r$td||f t-| ||||dd       S qqqt/t0k rCt1f}"nt1t2f}"t3| |"rt| drt4|r`t-| |||dS || j(@ |kr|	|dur|	|}#t-| |#|||dd S t-| |||dd!S t-| |S )"z/
    Add a new member to an existing Enum.
    c                 S   s   g | ]}|d  qS )r   r6   )r   r`  r6   r6   r9   r   
  r  zextend_enum.<locals>.<listcomp>ri  r6   z%r already in use as %rNr   "%r already in use in superclass %rc                 S   s   g | ]
}|j D ]}|qqS r6   r  )r   r  r   r6   r6   r9   r   
  r   z%r is not a supported EnumFz*no values specified for MultiValue enum %rr^  r  c                 S   r  r6   re   r  r6   r6   r9   r   
  r  r  rX   r  TrQ   r   r   rp   keepz%invalid Flag %r -- missing values: %sr   c                 s   r  r<   )r   )r   r   r6   r6   r9   r   
  r  zextend_enum.<locals>.<genexpr>)r   maskrt  z%r is a duplicate of %r)r   r   r  is_alias)r   r  r  )5rC   rs  r~   rH   rk  rj  rE   r   rf   r   rd  r\  rg  r  r  r   ri  r   r  r   r   rY  r   rJ  r]   r`  r   r   r   r   r  r_  r   r   r   rc  r   rt  re  rp   rr   rq   rd   rS   r   _finalize_extend_enumrC  r   r!  r$   r  rB   r	   )$enumerationr   r   r   
descriptorr  rs  rd  r\  rg  base_attributesri  _multi_value_
_no_alias_rh  rY  mt_new_newrt  rP   r  r  r/  rQ   more_values
new_memberrp   rr   missed
new_valuesr~  canonical_values_canonical_valuer  
flag_bases	canonicalr6   r6   r9   r   y
  s   















 

 

r   c           
   	   C   s2  |p|j }d }| jdd  D ]}|j|}|d ur,t|ttfr# n
td||jf q|sBt }|	| | ||_
t| || n|| jvrP||_
t| || |sX| j| || j|< t|d|jgD ]}	z|| j|	< W qe ty   |  j|	|ff7  _Y qew |r|| _|| _t|jr|  j|jO  _|S )Nr   r  rt  )r   rj  rC   rk  rE   r   rf   rH   r   r   r   rr  rd  r   rs  r~   r   rg  ri  rp   rr   r	   rs   )
r  r  r   r   r  r  r  r  r  r   r6   r6   r9   r  %  s@   



r  c                 C   s^   g }| j  D ]\}}||jkr|||jf q|r-ddd |D }td| |f | S )zS
    Class decorator that ensures only unique members exist in an enumeration.
    r   c                 S   r   )z%s -> %sr6   )r   aliasr   r6   r6   r9   r   Q  r   zunique.<locals>.<listcomp>zduplicate names found in %r: %s)rG   rD   r   r   r   r   )r  
duplicatesr   r   duplicate_namesr6   r6   r9   r   G  s   
r   )r+   c                   @   s(   e Zd ZdZe Ze Ze Ze ZdS )r+   a1  
        control how out of range / unnamed / absent flags are handled
        "strict" -> error is raised  [Flag default]
        "conform" -> extra bits are discarded [`_flag_mask_` bits retained]
        "eject" -> lose flag status (becomes a normal integer)
        "keep" -> retain flag status, retain extra bits [IntFlag default]

        when there are missing flags, negative numbers are handled as
        "strict" -> missing flag bits are discarded
        "eject" -> original integer is returned
        "keep" -> missing flag bits are kept

        N)	r   r   r   r{   r   r,   r-   r.   r/   r6   r6   r6   r9   r+   ]  s    
r+   r$   zRGeneric flag enumeration.

Derive from this class to define new flag enumerations.rq   r  c           	      O   s   |s|rd|f|du f| S d|f|du S t |}zt|}d|d  }|r.|f| W S |W S  ty9   Y nw td| )z
    Generate the next value when not given.

    name: the name of the member
    start: the initital start value or None
    count: the number of existing members
    last_value: the last value assigned or None
    r   NrT   zinvalid Flag value: %r)maxr   ra  rH   )	r   r  rP   rt  r   r   r  high_bitr   r6   r6   r9   r    s   
c                 c   s4    t || j@ D ]}| j|}|dur|V  qdS )zY
    Extract all members from the value in definition (i.e. increasing value) order.
    N)rS   rs   rg  rk  )r   rQ   valr   r6   r6   r9   r    s   r  r  c                 c   s4    t | |}|jdd d |D ]}|V  qdS )zA
    Extract all members from the value in definition order.
    c                 S   r   r<   )re  )rL   r6   r6   r9   r     s    z&_iter_member_by_def_.<locals>.<lambda>r   N)rd   r  rd  )r   rQ   ri  r   r6   r6   r9   r    s   r  c                 C   r  )z;
    return a member matching the given value, or None
    )r  r@  r6   r6   r9   r    s   
c                 G   s  |d  }}t |tstd|| jf | j}| j}| j}| j}d}|tu r1|dk r,|}||M }n|t	u rW| |  krA|ksD|S  |S |dk rN|}||M }|||A @ rV|S nq|t
u rv|dk ru|}| |krk||M }n]|d|  d M }nR|tu rt| | }	| |  kr|ksn td| |t||	t||	f |dk r|}||M }|||A @ rtd| |t||	t||	f ntd| |f |f|dd  }|| jv r| j| }
n|| @ }|| @ }||@ }t| |}| j|g|R  }t| dd}| jtu r|st| }
n|p| jj| g|R  }
t|
d	s%||
_|s+|rd}|D ]}||jO }q/|rh| j D ]'\}}||vrf|jrf|j|@ |jkrf|| ||jO }||j @ }q@|||A B }d
dd |D |
_|s|r|tu rtd| |f |t	u r|S |tt
fv rntd| |f d|
_n*|r|tu r||@ |krtd| |f |r|
 jd| | 7  _nd|
_| j||
}
|dur|
| j|< |
S )z$
    Create a composite member.
    r   r  NrT   r   z-%r invalid value %r
    given %s
  allowed %sz%r unknown flag boundary %rr  r   rJ  c                 S   r  r6   r  r  r6   r6   r9   r     r  z*_create_pseudo_member_.<locals>.<listcomp>z%r: no members with value %rz|%s) rE   r  r   r   rr   rs   rp   rq   r-   r.   r/   rZ   r,   r  r
   rg  rd   r  r  r~   r\  r`  rJ  r_  r   rs  rD   r   r   r   r  r  )r   rC  rQ   error_valuerj   rl   rh   rg   	neg_valuer^   pseudo_memberunknownr  rv  ri  rJ  combined_valuerL   rI   pmr6   r6   r9   r    s   







$






r  c                 G   s2   | j ttf v r
|S t|dk r||   f S |S )zB
    Return values to be fed to __new__ to create new member.
    rT   )r\  r  r`  r]   )r   ri  rC  r6   r6   r9   r  1  s
   r  c                 C   sP   t || jstdt|j| jjf |jdks| jdkrdS |j| j@ |jkS )zH
    Returns True if self has at least the same flags set as other.
    3unsupported operand type(s) for 'in': '%s' and '%s'r   F)rE   r   rH   r   r   r   r   r6   r6   r9   rA  >  s   rA  c                 c   s    |  | jD ]}|V  qdS )z,
    Returns flags in definition order.
    N)r  r   )r   r   r6   r6   r9   rE  K  s   rE  c                 C   rS  r<   )r   r   r   r6   r6   r9   rF  S  r   rF  c                 C   s4   | j }| jd u rd|j| jf S d|j| j| jf S )Nz<%s: %r>z<%s.%s: %r>r   r   r   r   r   r   r6   r6   r9   r   W  s   
c                 C   s0   | j }| jd u rd|j| jf S d|j| jf S )Nr   r  r  r  r6   r6   r9   r	  `  s   
c                 C   rS  r<   r}   r   r   r6   r6   r9   r  i  r   r  c                 C   rS  r<   r  r   r6   r6   r9   r9  m  r   r9  c                 C   s0   t || jr	|jS | jturt || jr|S tS r<   )rE   r   r   r\  r`  r   )r   r  r6   r6   r9   
_get_valueq  s
   r  c                 C   sT   |  |}|tu rtS | |fD ]}|  |d u rtd|f q| j}| ||B S )Nz/'%s' cannot be combined with other flags with |r  r   rH   r   r   r   r   other_valuer  rQ   r6   r6   r9   r  y     
r  c                 C   sT   |  |}|tu rtS | |fD ]}|  |d u rtd|f q| j}| ||@ S )Nz/'%s' cannot be combined with other flags with &r  r  r6   r6   r9   r     r  r   c                 C   sT   |  |}|tu rtS | |fD ]}|  |d u rtd|f q| j}| ||A S )Nz/'%s' cannot be combined with other flags with ^r  r  r6   r6   r9   r    r  r  c                 C   s<   |  | d u rtd| f | jd u r| | j | _| jS )Nz'%s' cannot be inverted)r  rH   r  r   r   r   r6   r6   r9   r    s
   
r  r	  r   r  c                   @   s   e Zd ZdZeZdd ZdS )r%   zSupport for integer-based Flagsc                 C   sf   t |tr| |}nt || jstdt|j| jjf |jdks(| jdkr*dS |j| j@ |jkS )zP
        Returns True if self has at least the same flags set as other.
        r  r   F)rE   r  r   rH   r   r   r   r   r6   r6   r9   rA    s   
zIntFlag.__contains__N)r   r   r   r{   r/   rq   rA  r6   r6   r6   r9   r%     s    r%   c                 C   s   |   d S )z@returns index of highest bit, or -1 if value is zero or negativer   )rZ   re   r6   r6   r9   r     s   r   c                 C   s    | j jdd }d|| jf S )z{
    use module.enum_name instead of class.enum_name

    the module is the last module in case of a multi-module name
    .rX   r  )r   r   r  r   )r   r;  r6   r6   r9   global_enum_repr  s   r  c                    s   | j jdd  | j j}| jdu rd || jf S t| r%d | jf S | jtj	ur;d
 fdd| jdD S g }| jdD ]}|d	  rQ|| qC|d |f  qCd
|S )
z{
    use module.flag_name instead of class.flag_name

    the module is the last module in case of a multi-module name
    r  rX   Nz	%s.%s(%r)r  rJ  c                    s   g | ]}d  |f qS )r  r6   rO  r  r6   r9   r     r   z$global_flag_repr.<locals>.<listcomp>r   )r   r   r  r   r   r   r	   rq   r+   r/   r   r   isdigitr   )r   r  r   rI   r6   r  r9   global_flag_repr  s   
 
r  c                 C   s&   | j du r| jj}d|| jf S | j S )z2
    use enum_name instead of class.enum_name
    Nz%s(%r))r   r   r   r   )r   r  r6   r6   r9   
global_str  s   
r  c                 C   sF   t | tr	t| _nt| _t | tr|rt| _tj	| j
 j| j | S )z
    decorator that makes the repr() of an enum member reference its module
    instead of its class; also exports all members to the enum's module's
    global namespace
    )rB   r$   r  r   r  r(   r  r	  rK  rb  r   rC   rf  rG   )r   
update_strr6   r6   r9   re    s   
re  )WeakSetc                 C   sl  t |tstd|f z| jd  W n, ty$   t | _t | _Y n ty?   ddl	}|
 \}} }td}t| Y nw || jv rGdS || jv rNdS | |u rZ| j| dS | t|dd	v rj| j| dS | tu r{t|tr{| j| dS | tu rt|tr| j| dS | tu rt|tr| j| dS | tu rt|tr| j| dS | j| dS )
z9
        Override for issubclass(subclass, cls).
        z+issubclass() arg 1 must be a class (got %r)_subclass_cache_r   Npossible causes for endless recursion:
    - __getattribute__ is not ignoring __dunder__ attibutes
    - __instancecheck__ and/or __subclasscheck_ are (mutually) recursive
    see `aenum.remove_stdlib_integration` for temporary work-aroundTFrj  r6   )rE   r   rH   rC   r   r  r  _subclass_negative_cache_RecursionErrorsysrL  raise_from_noner  r~   StdlibIntFlagrB   r%   r  r$   StdlibIntEnumr"   r  r!   )r   subclassr  rz  tbr6   r6   r9   __subclasscheck__  sJ   


r  c                 C   sN   |j }z| |W S  ty&   dd l}| \}} }td}t| Y d S w )Nr   r  )r   r  r  r  rL  r  )r   r   r  r  rz  r  r6   r6   r9   __instancecheck__0  s   r  c                   C   s   t r
tt_tt_d S d S r<   )r  r  StdlibEnumMetar  r6   r6   r6   r9   r0   ;  s   
r0   c                   C   s   t rt`t`dS dS )a  
    Remove the __instancecheck__ and __subclasscheck__ overrides from the stdlib Enum.

    Those overrides are in place so that code detecting stdlib enums will also detect
    aenum enums.  If a buggy __getattribute__, __instancecheck__, or __subclasscheck__
    is defined on a custom EnumMeta then RecursionErrors can result; using this
    function after importing aenum will solve that problem, but the better solution is
    to fix the buggy method.
    N)r  r  r  r  r6   r6   r6   r9   r1   @  s   
r1   c                   @   s   e Zd Zdd Zdd ZdS )r3   c                 G   sZ   |j | _ |j| _g | _|j}|sdd | D }|D ]}|| | j|< | j| qd S )Nc                 S   s"   g | ]\}}t |ttfr|qS r6   )rE   r   r!   r   r6   r6   r9   r   U  s   " z'cls2module.__init__.<locals>.<listcomp>)r   r   _parent_module__all__rC   rD   r   )r   r   r   all_objectsr   r6   r6   r9   r   O  s   zcls2module.__init__c                 C   s   | t jd| j| jf < d S r  )rK  rb  r  r   r   r6   r6   r9   registerY  s   zcls2module.registerN)r   r   r   r   r  r6   r6   r6   r9   r3   N  s    
r3   r<   )NF)NNNF)F)
__future__r   rG  	_constantr   _tupler   collectionsr   rn   r  rK  r  r
   r[   r*   ImportErrorremover  	NameErrorr  r:   rF   r   r_  r   r  r!   r  r"   r  r  r  StdlibStrEnumStdlibReprEnumr%   r$   r#   r(   r   r   r   r   r   r2   r   rS   r5   typesrf   r  r`  rv   r   _RouteClassAttributeToGetattrr   r   r   r   r   r   r   r	   r   r   globalsr   r.   r/   r=  r   r   rH  rP  r   r    r   r   	_Addendumr  r  r  r  r   rJ  r  r   r  r  r  r  r   r	  PY3rI  r  r   r  r  r  r  r  r   r   r   rQ   rC  
_enum_baseresolver  r4   r  r~  _repr_basesr  r   r&   r'   r  r   r   r   r   r   r   r)   r   r  r   r  r   r+   _flag_bases	flag_dictr,   r  r  r  r  r  rA  rE  rF  rF  r  r9  r  r  r   r  r  r   r  r  r  re  _weakrefsetr  r  r  r0   r1   r3   r6   r6   r6   r9   <module>   s6   
$
(
 %i
$- ) i m  1       

(












	


 
-"


		t













	

.