a
    d                     @   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__ X/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/aenum/_constant.pyr      s    zNamedConstantDict.__init__c                    s   t |rtd|f n^t|r"nT|| jv r<td|f n:t|tsNt|sv|| v rjt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)Z	is_sunder
ValueErrorZ	is_dunderr	   	TypeError
isinstanceconstantZ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 r0|}t }| D ]\}}|||< qi }i }| D ]6\}	}
|	|jv r^|
||	< q@nt|
trn|
j}
|
||	< q@tt	| 
| |||}i |_i |_| D ] \}	}
|
||	|
}||j|	< q|S r   )typedictr   itemsr	   r   Z	nonmemberr   r   r   __new___named_constant_cache_	_members_)r   r   r    ZclsdictZoriginal_dictkvZnewdict	constantsnameobjZnewclsZ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r4t|tr4t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   r4   R   s    zNamedConstantMeta.__delattr__c                 C   s   dd | j  D S )Nc                 s   s   | ]
}|V  qd S r   r   .0r)   r   r   r   	<genexpr>Y       z-NamedConstantMeta.__iter__.<locals>.<genexpr>)r(   valuesr.   r   r   r   __iter__X   s    zNamedConstantMeta.__iter__c                 C   s   dd t | j D S )Nc                 s   s   | ]
}|V  qd S r   r   r7   r   r   r   r9   \   r:   z1NamedConstantMeta.__reversed__.<locals>.<genexpr>)reversedr(   r;   r.   r   r   r   __reversed__[   s    zNamedConstantMeta.__reversed__c                 C   s
   t | jS r   )lenr(   r.   r   r   r   __len__^   s    zNamedConstantMeta.__len__c                    sJ   | j |}tdur4t|tr4td|jj|jf tt	| 
|| dS )z3Block attempts to reassign NamedConstants.
        Ncannot rebind constant <%s.%s>)r0   r1   r   r   r2   r   r   r3   r   r   __setattr__)r   r,   r   r6   r   r   r   rB   c   s    zNamedConstantMeta.__setattr__)r   r   r   r   classmethodr"   r&   r/   r4   r<   r>   r@   __nonzero__rB   r   r   r   r   r   r   /   s   
r   zPNamedConstants protection.

    Derive from this class to lock NamedConstants.

)r$   docnsc           	      C   s&  |d u rN|}| j  D ]$\}}t|| r|j|kr|  S qtd|| jf | j |}t|tr|td|j	j|j
f nt|tr|p|j}|j}| j	}t|tr|j}t|}| j|}|d u rt| j| t|fi }|| jt|< |||}||_
||_||_|| j|< || || |S )Nz%r does not exist in %rrA   )r0   r%   r   _value_r   r   r1   r   r2   r   r3   r   r   r   r#   r'   r&   r(   rB   )	r   r,   r   rE   r-   r6   r   Zactual_typeZ
value_typer   r   r   r&   q   s6    





r&   c                 C   s   d| j j| j| jf S )Nz<%s.%s: %r>)r   r   r3   rG   r
   r   r   r   __repr__   s    rH   c                 C   s   t | j| jffS r   )getattrr   r3   )r   protor   r   r   __reduce_ex__   s    rK   )NN)_common__all__r   r$   r   r#   r   Z	_Addendumr"   objectglobalsZconstant_dictr&   rH   rK   resolver   r   r   r   r   <module>   s&   $< 

