o
    `^h                     @   s   d dl T ddgZdZG dd deZG dd deZeede	fd	e
 d
ZedddZedd Zedd Zede	fe ZeZ[dS )   )*NamedConstantConstantNc                       s,   e Zd ZdZ fddZ fddZ  ZS )NamedConstantDictzTrack constant order and ensure names are not reused.

    NamedConstantMeta will use the names found in self._names as the
    Constant names.
    c                    s   t t|   g | _d S N)superr   __init___namesself	__class__ M/home/air/shanriGPT/back/venv/lib/python3.10/site-packages/aenum/_constant.pyr      s   
zNamedConstantDict.__init__c                    s   t |rtd|f t|rn)|| jv rtd|f t|ts%t|s9|| v r3td|| | f | j| t	t
| || dS )zChanges anything not dundered or not a constant descriptor.

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

        Single underscore (sunder) names are reserved.
        zE_sunder_ names, such as %r, are reserved for future NamedConstant usezattempt to reuse name: %rz%s already defined as: %rN)	is_sunder
ValueError	is_dunderr	   	TypeError
isinstanceconstantis_descriptorappendr   r   __setitem__)r   keyvaluer   r   r   r      s   
zNamedConstantDict.__setitem__)__name__
__module____qualname____doc__r   r   __classcell__r   r   r   r   r      s    r   c                       sh   e Zd ZdZedd Z fddZdd Z fdd	Zd
d Z	dd Z
dd ZeZ fddZ  ZS )NamedConstantMetaz>
    Block attempts to reassign NamedConstant attributes.
    c                 K   s   t  S r   )r   )metaclsclsbaseskwdsr   r   r   __prepare__4   s   zNamedConstantMeta.__prepare__c                    s   t |tu r|}t }| D ]\}}|||< qi }i }| D ]\}	}
|	|jv r.|
||	< q t|
tr6|
j}
|
||	< q tt	| 
| |||}i |_i |_| D ]\}	}
|
||	|
}||j|	< qP|S r   )typedictr   itemsr	   r   	nonmemberr   r   r    __new___named_constant_cache_	_members_)r!   r"   r#   clsdictoriginal_dictkvnewdict	constantsnameobjnewclsnew_kr   r   r   r*   8   s*   



zNamedConstantMeta.__new__c                 C   s   dS )NTr   r"   r   r   r   __bool__O   s   zNamedConstantMeta.__bool__c                    sH   | j |}td urt|trtd|jj|jf tt	| 
| d S )Nzcannot delete constant <%s.%s>)__dict__getr   r   AttributeErrorr   r   _name_r   r    __delattr__)r"   attrcur_objr   r   r   r=   R   s   zNamedConstantMeta.__delattr__c                 C   s   dd | j  D S )Nc                 s       | ]}|V  qd S r   r   .0r/   r   r   r   	<genexpr>Y       z-NamedConstantMeta.__iter__.<locals>.<genexpr>)r,   valuesr7   r   r   r   __iter__X   s   zNamedConstantMeta.__iter__c                 C   s   dd t | j D S )Nc                 s   r@   r   r   rA   r   r   r   rC   \   rD   z1NamedConstantMeta.__reversed__.<locals>.<genexpr>)reversedr,   rE   r7   r   r   r   __reversed__[   s   zNamedConstantMeta.__reversed__c                 C   s
   t | jS r   )lenr,   r7   r   r   r   __len__^   s   
zNamedConstantMeta.__len__c                    sJ   | j |}tdurt|trtd|jj|jf tt	| 
|| dS )z3Block attempts to reassign NamedConstants.
        Ncannot rebind constant <%s.%s>)r9   r:   r   r   r;   r   r   r<   r   r    __setattr__)r"   r3   r   r?   r   r   r   rL   c   s   zNamedConstantMeta.__setattr__)r   r   r   r   classmethodr%   r*   r8   r=   rF   rH   rJ   __nonzero__rL   r   r   r   r   r   r    /   s    
r    zPNamedConstants protection.

    Derive from this class to lock NamedConstants.

)r'   docnsc           	      C   s$  |d u r'|}| j  D ]\}}t|| r|j|kr|  S qtd|| jf | j |}t|tr=td|j	j|j
f t|trJ|pF|j}|j}| j	}t|trU|j}t|}| j|}|d u rut| j| t|fi }|| jt|< |||}||_
||_||_|| j|< || || |S )Nz%r does not exist in %rrK   )r9   r(   r   _value_r   r   r:   r   r;   r   r<   r   r   r   r&   r+   r*   r,   rL   )	r"   r3   r   rO   r4   r?   r!   actual_type
value_typer   r   r   r*   q   s8   




r*   c                 C   s   d| j j| j| jf S )Nz<%s.%s: %r>)r   r   r<   rQ   r
   r   r   r   __repr__   s   rT   c                 C   s   t | j| jffS r   )getattrr   r<   )r   protor   r   r   __reduce_ex__   s   rW   )NN)_common__all__r   r'   r   r&   r    	_Addendumr%   objectglobalsconstant_dictr*   rT   rW   resolver   r   r   r   r   <module>   s(    $< 

