o
    `^hJ                     @   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__ J/home/air/shanriGPT/back/venv/lib/python3.10/site-packages/aenum/_tuple.pyr      s   zNamedTupleDict.__init__c                    s   t |r|dvrtd|f n/t|r|dkrd}n$|| jv r'td|f t|s?|| v r9t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)
	is_sunder
ValueError	is_dunderr	   	TypeError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rt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   r0   r2   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      dS )Nr)   r   r1   r   r   r   r2   F      zundefined.__repr__c                 C   r3   )NFr   r1   r   r   r   __bool__H   r4   zundefined.__bool__N)r!   r"   r#   r2   r5   __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#   constantr7   r8   r9   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
   r;   r   )r=   r   r   r   r   r   r   Z   s   zNamedTupleMeta.__init__c              	      s  |t fkr
tt f}n"t|vr,t |v r'|t }|d | tf ||d   }n|tf }t }g }|D ]}	t|	tr?||	 q3d}
|r\| j| D ]\}}}}|||f||< t|
|}
qI|	 D ]\}}|||< q`|}|t
urwd|v rwtdt|t}t }|d|ptj t }t }|dg }|r|dd }d}|	 D ]\}}||jvr|||< qt|tr|t
t
f}|d d }
|}nt|tr|r|
|t
f}|
d7 }
|}nt
|t
f}|}nxt|trt|d	v rt|d trt|d ttfrt|d
kr|t
f }|}|d d }
|}nBt|trPt|dv rPt|d ttfrPt|dkr9|t
f }|rH|
f| }|
d7 }
|}nt
f| }|}ntd||f |||< qg }g }t }d}|s|rutd| f t|	 dd dD ]%\}\}}}||v r|| q|| || t||d }q|}nt|t| }|rtd| t }d}
|D ]Q}z||d p||\}}}W n ty   td||f w |t
ur|}
|
|v r|| n
|| ||
 |
||f||< |
d7 }
t||
}qt|	 dd dD ]+\}\}}}||v r.|| n
|| || |||f||< t||d }qt|t| t|ksYJ dt|t|@ t|ksrJ dt| t|@ t|t|@ t|ksJ dt| t|@ |	 D ]1\}\}}}t|tsJ d|t||f t|ttfs|t
u sJ d|t||f q|	 D ]\}\}}}t||||||< qd|d< t t| !| |||}||_"||_#||_$|S )Nr   r   z2_size_ cannot be set if "size" is passed in headerr   , Fr   )      rC   )r   rC   zEnot sure what to do with %s=%r (should be OFFSET [, DOC [, DEFAULT]])z5_order_ not specified and OFFSETs not declared for %rc                 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   rE   rF   r   rG   r   r   r   rI      rJ   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   
isinstancer;   r   _convert_fieldsmaxitemsr)   r   
setdefaultr   r7   OrderedDictpopreplacesplitr	   baseinteger
basestringr,   NoneTyper   setkeyssortedadd
IndexErrortyper&   r
   __new__r   	_aliases__defined_len_)r<   r=   r>   clsdictr?   r   r(   	base_dictnamedtuple_basesbaseir'   r+   r*   kvoriginal_dict	add_order
unnumberednumberedr   targetfieldsaliasesseenmax_lenoffsetsmissingnamedtuple_classr   r   r   r`   ]   s   


 











>
.



"


"



"


"22"0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*   )namedtuples
all_fieldsr=   rf   fielddescr   r   r   rO      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)rN   r;   NotImplementedr!   )r=   otherr   r   r   __add__   s   
zNamedTupleMeta.__add__c              
   O   s  | t u s
| jdkrj|}| }z`d|v r|d}n|d |dd }}d|v r0|d}n|d |dd }}d|v rE|d}n|rS|d |dd }}nd}d|v r_|d}n|rm|d |dd }}nd}W n ty   td||f w |s|rtd	||f trt|trz|	d
}W n t
y   td|f w t|tr||_|dur||jvr|f|j |_|S | j}	| f}
|	||
}t|tr|dd }t|ttfrt|d trdd t|D }d}|D ]+}t|tr||| }}nt|dkr|\}}n|d |dd }}|||< q|dur5t|ts1|f}||
 }
|	|	||
|}|du rZz
tdjd }W n tttfyY   Y nw |du ret| |S ||_|S | j| g|R i |}t|| r|j |i | |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moduler_   z'too few arguments to NamedTuple: %s, %sz(too many arguments to NamedTuple: %s, %sasciiz %r is not representable in ASCIIrA   rB   c                 S   s   g | ]\}}||fqS r   r   ).0rg   er   r   r   
<listcomp>L  s    z+NamedTupleMeta.__call__.<locals>.<listcomp>rC   r!   )!r   rb   copyrT   r^   r   PY2rN   unicodeencodeUnicodeEncodeErrorr;   r!   	__bases__r   r@   rX   rU   rV   rM   list	enumerater,   r`   _sys	_getframe	f_globalsr-   r   KeyErrormake_class_unpicklabler"   r   )r=   r   r   original_argsoriginal_kwdsr~   r   r   r_   r<   r>   rc   item
field_namefield_indexru   namedtuple_instancer   r   r   __call__  s   







zNamedTupleMeta.__call__c                 C   
   t | jS r   )r   r   r=   r   r   r   
__fields__t     
zNamedTupleMeta.__fields__c                 C   r   r   )r   ra   r   r   r   r   __aliases__z  r   zNamedTupleMeta.__aliases__c                 C   s   d| j f S )Nz<NamedTuple %r>)r!   r   r   r   r   r2   ~  s   zNamedTupleMeta.__repr__)r!   r"   r#   r$   classmethodr)   r@   r   r`   staticmethodrO   r}   r   bltin_propertyr   _fieldsr   r2   r%   r   r   r   r   r;   S   s"     

r

r;   zONamedTuple base class.

    Derive from this class to define new NamedTuples.

)dictr+   nsc                 O   s  | j tju rt|| jkrtd| jt|f t|t| j t| j }|r/td|f t	|t
gt| jt|   }| D ]\}}t| |j}|| t
krYtd| |||< qC| | g }t|D ]!\}}|t
u r| j| }	t| |	j}
|
t
u r||	 qi|
||< qi|r| j tjtjfv rtdd| |r|d t
u r|  |  |r|d t
u s| 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   r7   r,   rb   r   rZ   r   ra   r   r)   r   rQ   rv   r(   r   r   r*   r   r8   joinrT   r9   rM   r`   )r=   r   r   unknown
final_argsry   r    r(   rt   r'   r*   r   r   r   r`     s>    


r`   c                    s    j t fdd jD fS )Nc                 3   s    | ]}t  |V  qd S r   rv   r   fr1   r   r   	<genexpr>  s    z __reduce_ex__.<locals>.<genexpr>)r   rM   r   )r   protor   r1   r   __reduce_ex__  s   r   c                 C   sZ   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 )N%s(%s)r   c                 S   s   g | ]
\}}d ||f qS )z%s=%rr   )r   r   or   r   r   r         z__repr__.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   )repr)r   r   r   r   r   r     rJ   )r,   r   r   r!   r   zipr1   r   r   r   r2     s
     r2   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   r1   r   r   r     r   z__str__.<locals>.<listcomp>)r   r!   r   r   r1   r   r1   r   __str__  s   r   c                 C      t | jjS r   r   r   r   r1   r   r   r   r        r   c                 C   r   r   )r   r   ra   r1   r   r   r   r     r   r   c                 C   r   r   r   r1   r   r   r   r     r   r   c                 C   s   | j | g|R  S r   )r`   )r=   iterablenewr,   r   r   r   _make  s   r   c                 C   s   t t| j| S r   )rS   r   r   r1   r   r   r   _asdict  s   r   c                 K   s"   |   }|| | jdi |S )Nr   )r   updater   )r   r   currentr   r   r   _replace  s   
r   c                 C   s   d S r   r   )r=   r   r   r   r   r     s   r   )NN)!_common	_constantr   sysr   __all__rS   r   rL   r&   r)   r   r_   r;   	_Addendumr@   globalsnamedtuple_dictr`   r   r2   r   r   r   r   r   r   r   r   r   r   resolver   r   r   r   r   <module>   s^    %  0
!




