a
    dJ                     @   sF  d dl T d dlmZ ddlZddgZG dd deZG d	d
 d
eZ	G dd deZ
e
 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 Zedd Zedd Zedd Zeedd Zeedd Zeedd Zeed(d d!Zed"d# Zed$d% Zeed&d' Zedefe Z [dS ))   )*)NamedConstant    N	TupleSize
NamedTuplec                       s,   e Zd ZdZ fddZ fddZ  ZS )NamedTupleDictzTrack field order and ensure field names are not reused.

    NamedTupleMeta will use the names found in self._field_names to translate
    to indices.
    c                    s    g | _ tt| j|i | d S N)_field_namessuperr   __init__)selfargskwds	__class__ U/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/aenum/_tuple.pyr      s    zNamedTupleDict.__init__c                    s   t |r |dvrtd|f n`t|r6|dkrd}nJ|| jv rPtd|f n0t|s|| v rttd|| | f | j| tt| 	|| dS )zRecords anything not dundered or not a descriptor.

        If a field name is used twice, an error is raised.

        Single underscore (sunder) names are reserved.
        )_size__order__fields__review_zB_sunder_ names, such as %r, are reserved for future NamedTuple use	__order__r   zattempt to reuse field name: %rz%s already defined as: %rN)
Z	is_sunder
ValueErrorZ	is_dunderr	   	TypeErrorZis_descriptorappendr
   r   __setitem__)r   keyvaluer   r   r   r      s"    
zNamedTupleDict.__setitem__)__name__
__module____qualname____doc__r   r   __classcell__r   r   r   r   r      s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )_TupleAttributeAtIndexc                 C   s(   || _ || _|tu rd }|| _|| _d S r   )nameindex	undefinedr!   default)r   r$   r%   docr'   r   r   r   r   2   s    z_TupleAttributeAtIndex.__init__c                 C   s:   |d u r| S t || jkr0td|jj| jf || j S )Nz%s instance has no value for %s)lenr%   AttributeErrorr   r   r$   )r   instanceownerr   r   r   __get__:   s
    z_TupleAttributeAtIndex.__get__c                 C   s   d| j j| jf S )Nz%s(%d))r   r   r%   r   r   r   r   __repr__A   s    z_TupleAttributeAtIndex.__repr__N)r   r   r    r   r-   r/   r   r   r   r   r#   0   s   r#   c                   @   s    e Zd Zdd Zdd ZeZdS )r&   c                 C   s   dS )Nr&   r   r.   r   r   r   r/   F   s    zundefined.__repr__c                 C   s   dS )NFr   r.   r   r   r   __bool__H   s    zundefined.__bool__N)r   r   r    r/   r0   __nonzero__r   r   r   r   r&   E   s   r&   c                   @   s*   e Zd ZeddZeddZeddZdS )r   fixedztuple length is staticminimumz>tuple must be at least x long (x is calculated during creationvariableztuple length can be anythingN)r   r   r    Zconstantr2   r3   r4   r   r   r   r   r   N   s   

c                       s   e Zd ZdZeefddZ fddZef fdd	Ze	dd	 Z
d
d Zdd Zedd ZeZedd Zdd Z  ZS )NamedTupleMetazMetaclass for NamedTuplec                 K   s   t  S r   )r   )metaclsclsbasessizer   r   r   r   __prepare__V   s    zNamedTupleMeta.__prepare__c                    s   t t| j|  d S r   )r
   r5   r   )r7   r   r   r   r   r   r   Z   s    zNamedTupleMeta.__init__c              	      s  |t fkrtt f}nDt|vrXt |v rN|t }|d | tf ||d   }n
|tf }t }g }|D ]}	t|	trf||	 qfd}
|r| j| D ]$\}}}}|||f||< t|
|}
q|	 D ]\}}|||< q|}|t
urd|v rtdt|t}t }|d|ptj t }t }|dg }|rD|dd }d}|	 D ]~\}}||jvrn|||< qLt|tr|t
t
f}|d d }
|}n*t|tr|r|
|t
f}|
d7 }
|}nt
|t
f}|}nt|tr>t|d	v r>t|d tr>t|d ttfr>t|d
kr(|t
f }|}|d d }
|}nt|trt|dv rt|d ttfrt|dkr|t
f }|r|
f| }|
d7 }
|}nt
f| }|}ntd||f |||< qLg }g }t }d}|sd|rtd| f t|	 dd dD ]H\}\}}}||v r6|| n"|| || t||d }q|}nDt|t| }|rtd| t }d}
|D ]}z"||d p||\}}}W n$ ty   td||f Y n0 |t
ur|}
|
|v r|| n|| ||
 |
||f||< |
d7 }
t||
}qt|	 dd dD ]V\}\}}}||v rt|| n|| || |||f||< t||d }qPt|t| t|ksJ dt|t|@ t|ksJ dt| t|@ t|t|@ t|ks.J dt| t|@ |	 D ]b\}\}}}t|tsfJ d|t||f t|ttfs6|t
u s6J d|t||f q6|	 D ]"\}\}}}t||||||< qd|d< t t| !| |||}||_"||_#||_$|S )Nr   r   z2_size_ cannot be set if "size" is passed in headerr   , Fr   )      r=   )r   r=   zEnot sure what to do with %s=%r (should be OFFSET [, DOC [, DEFAULT]])z5_order_ not specified and OFFSETs not declared for %rc                 S   s   | d d | d fS Nr   r   r   nvr   r   r   <lambda>       z(NamedTupleMeta.__new__.<locals>.<lambda>)r   z9unable to order fields: %s (use _order_ or specify OFFSETz!%s (from _order_) not found in %sc                 S   s   | d d | d fS r?   r   r@   r   r   r   rB      rC   z/number of fields + aliases != number of offsetsz"some fields are not in offsets: %sz#some aliases are not in offsets: %sz"index for %s is not an int (%s:%r)z-doc is not a str, None, nor undefined (%s:%r)r   	__slots__)%objecttupler%   r   
isinstancer5   r   _convert_fieldsmaxitemsr&   r   
setdefaultr   r2   OrderedDictpopreplacesplitr	   Zbaseinteger
basestringr)   ZNoneTyper   setkeyssortedadd
IndexErrortyper#   r
   __new__r   	_aliases__defined_len_)r6   r7   r8   clsdictr9   r   r%   Z	base_dictZnamedtuple_basesbaseir$   r(   r'   kvZoriginal_dictZ	add_orderZ
unnumberedZnumberedr   targetfieldsaliasesseenmax_lenoffsetsmissingnamedtuple_classr   r   r   rW   ]   s    


 






>
.


"


"



"


"22"4zNamedTupleMeta.__new__c                  G   sL   g }| D ]>}t |}|jD ]*}t||}||||j |j|jf qq|S )zBcreate list of index, doc, default triplets for cls in namedtuples)r)   r   getattrr   r%   r!   r'   )ZnamedtuplesZ
all_fieldsr7   r[   fielddescr   r   r   rH      s    

 zNamedTupleMeta._convert_fieldsc                 C   s*   t |tstS td| j|jf | |fi S )zWA new NamedTuple is created by concatenating the _fields_ and adjusting the descriptorsz%s%s)rG   r5   NotImplementedr   )r7   otherr   r   r   __add__   s    
zNamedTupleMeta.__add__c              
   O   s0  | t u s| jdkr|}| }zd|v r6|d}n|d |dd  }}d|v r`|d}n|d |dd  }}d|v r|d}n |r|d |dd  }}nd}d|v r|d}n |r|d |dd  }}nd}W n$ ty   td||f Y n0 |s|r"td	||f trft|trfz|	d
}W n" t
yd   td|f Y n0 t|tr||_|dur||jvr|f|j |_|S | j}	| f}
|	||
}t|tr|dd }t|ttfrt|d trdd t|D }d}|D ]X}t|tr.|||  }}n.t|dkrF|\}}n|d |dd  }}|||< q|durt|ts|f}||
 }
|	|	||
|}|du rztdjd }W n tttfy   Y n0 |du rt| n||_|S | j| g|R i |}t|| r(|j |i | |S dS )a  Creates a new NamedTuple class or an instance of a NamedTuple subclass.

        NamedTuple should have args of (class_name, names, module)

            `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.

                `module`, if set, will be stored in the new class' __module__ attribute;

                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.

        subclass should have whatever arguments and/or keywords will be used to create an
        instance of the subclass
        r   
class_namer   NnamesmodulerV   z'too few arguments to NamedTuple: %s, %sz(too many arguments to NamedTuple: %s, %sasciiz %r is not representable in ASCIIr;   r<   c                 S   s   g | ]\}}||fqS r   r   ).0r\   er   r   r   
<listcomp>L  rC   z+NamedTupleMeta.__call__.<locals>.<listcomp>r=   r   )!r   rY   copyrM   rU   r   PY2rG   unicodeencodeUnicodeEncodeErrorr5   r   	__bases__r   r:   rP   rN   rO   rF   list	enumerater)   rW   _sys	_getframe	f_globalsr*   r   KeyErrorZmake_class_unpicklabler   r   )r7   r   r   Zoriginal_argsZoriginal_kwdsrm   rn   ro   rV   r6   r8   rZ   item
field_nameZfield_indexrf   Znamedtuple_instancer   r   r   __call__  s     




zNamedTupleMeta.__call__c                 C   s
   t | jS r   )rz   r   r7   r   r   r   
__fields__t  s    zNamedTupleMeta.__fields__c                 C   s
   t | jS r   )rz   rX   r   r   r   r   __aliases__z  s    zNamedTupleMeta.__aliases__c                 C   s   d| j f S )Nz<NamedTuple %r>)r   r   r   r   r   r/   ~  s    zNamedTupleMeta.__repr__)r   r   r    r!   classmethodr&   r:   r   rW   staticmethodrH   rl   r   bltin_propertyr   _fieldsr   r/   r"   r   r   r   r   r5   S   s     

r

r5   zONamedTuple base class.

    Derive from this class to define new NamedTuples.

)dictr(   nsc                 O   s  | j tju r0t|| jkr0td| jt|f t|t| j t| j }|r^td|f t	|t
gt| jt|   }| D ]4\}}t| |j}|| t
krtd| |||< q| | g }t|D ]D\}}|t
u r| j| }	t| |	j}
|
t
u r||	 q|
||< q|r| j tjtjfv rDtdd| |rl|d t
u rl|  |  qD| j tjust
|v rtdd| t| t|S )Nz%d fields expected, %d receivedzunknown fields: %rz!field %s specified more than oncez$values not provided for field(s): %s, )r   r   r2   r)   rY   r   rQ   r   rX   rz   r&   r   rJ   rg   r%   r   r{   r'   r   r3   joinrM   r4   rF   rW   )r7   r   r   unknown
final_argsrh   r   r%   re   r$   r'   r   r   r   rW     s:     




rW   c                    s    j t fdd jD fS )Nc                 3   s   | ]}t  |V  qd S r   rg   rq   fr.   r   r   	<genexpr>  rC   z __reduce_ex__.<locals>.<genexpr>)r   rF   r   )r   protor   r.   r   __reduce_ex__  s    r   c                 C   s^   t | t | jkr:d| jjddd t| j| D f S d| jjddd | D f S d S )N%s(%s)r   c                 S   s   g | ]\}}d ||f qS )z%s=%rr   )rq   r   or   r   r   rs     rC   z__repr__.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   )repr)rq   r   r   r   r   rs     rC   )r)   r   r   r   r   zipr.   r   r   r   r/     s
     r/   c                    s&   d j jd fdd jD f S )Nr   r   c                    s   g | ]}d t  |f qS )z%rr   r   r.   r   r   rs     rC   z__str__.<locals>.<listcomp>)r   r   r   r   r.   r   r.   r   __str__  s    r   c                 C   s   t | jjS r   rz   r   r   r.   r   r   r   r     s    r   c                 C   s   t | jjS r   )rz   r   rX   r.   r   r   r   r     s    r   c                 C   s   t | jjS r   r   r.   r   r   r   r     s    r   c                 C   s   | j | g|R  S r   )rW   )r7   iterablenewr)   r   r   r   _make  s    r   c                 C   s   t t| j| S r   )rL   r   r   r.   r   r   r   _asdict  s    r   c                 K   s"   |   }|| | jf i |S r   )r   updater   )r   r   currentr   r   r   _replace  s    
r   c                 C   s   d S r   r   )r7   r   r   r   r   r     s    r   )NN)!_commonZ	_constantr   sysr|   __all__rL   r   rE   r#   r&   r   rV   r5   Z	_Addendumr:   globalsZnamedtuple_dictrW   r   r/   r   r   r   r   r   r   r   r   r   r   resolver   r   r   r   r   <module>   s\   %  0
!




