U eJ@sFddlTddlmZddlZddgZGdddeZGd d d eZ Gd d d eZ e Z Gd ddeZ Gddde Z ee defdedZeddZeddZeddZeddZeeddZeeddZeeddZeed(d d!Zed"d#Zed$d%Zeed&d'Ze defeZ [dS)))*) NamedConstantN TupleSize NamedTuplecs,eZdZdZfddZfddZZS)NamedTupleDictzTrack field order and ensure field names are not reused. NamedTupleMeta will use the names found in self._field_names to translate to indices. csg|_tt|j||dSN) _field_namessuperr__init__)selfargskwds __class__:/opt/hc_python/lib/python3.8/site-packages/aenum/_tuple.pyr szNamedTupleDict.__init__cst|r |dkrtd|fn`t|r6|dkrd}nJ||jkrPtd|fn0t|s||krttd|||f|j|tt| ||dS)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__rzattempt to reuse field name: %rz%s already defined as: %rN) Z is_sunder ValueErrorZ is_dunderr TypeErrorZ is_descriptorappendr r __setitem__)r keyvaluerrrrs"  zNamedTupleDict.__setitem__)__name__ __module__ __qualname____doc__r r __classcell__rrrrr s rc@s$eZdZddZddZddZdS)_TupleAttributeAtIndexcCs(||_||_|tkrd}||_||_dSr)nameindex undefinedr!default)r r$r%docr'rrrr 2s z_TupleAttributeAtIndex.__init__cCs:|dkr |St||jkr0td|jj|jf||jS)Nz%s instance has no value for %s)lenr%AttributeErrorrrr$)r instanceownerrrr__get__:s z_TupleAttributeAtIndex.__get__cCsd|jj|jfS)Nz%s(%d))rrr%r rrr__repr__Asz_TupleAttributeAtIndex.__repr__N)rrr r r-r/rrrrr#0sr#c@s eZdZddZddZeZdS)r&cCsdS)Nr&rr.rrrr/Fszundefined.__repr__cCsdS)NFrr.rrr__bool__Hszundefined.__bool__N)rrr r/r0 __nonzero__rrrrr&Esr&c@s*eZdZeddZeddZeddZdS)rfixedztuple length is staticminimumz>tuple must be at least x long (x is calculated during creationvariableztuple length can be anythingN)rrr Zconstantr2r3r4rrrrrNs  cseZdZdZeefddZfddZeffdd Ze dd Z d d Z d d Z e ddZeZe ddZddZZS)NamedTupleMetazMetaclass for NamedTuplecKstSr)r)metaclsclsbasessizerrrr __prepare__VszNamedTupleMeta.__prepare__cstt|j|dSr)r r5r )r7r rrrrr ZszNamedTupleMeta.__init__c s|tfkrttf}nDt|krXt|krN|t}|d|tf||d}n |tf}t}g}|D]} t| trf|| qfd} |r|j|D]$\} }} } || | f|| <t| |} q| D]\}}|||<q|}|t k rd|krt dt|t}t}| d|pt jt}t}|dg}|rD|dd}d}| D]~\}}||jkrn|||<qLt|tr|t t f}|dd} |}n*t|tr|r| |t f}| d7} |}nt |t f}|}nt|tr>t|d kr>t|dtr>t|dttfr>t|d kr(|t f}|}|dd} |}nt|trt|d krt|dttfrt|dkr|t f}|r| f|}| d7} |}nt f|}|}ntd ||f|||<qLg}g}t}d}|sd|rtd |ft| dddD]H\} \}} } ||kr6|| n"|| ||t||d}q|}nFt|t|}|rtd|t}d} |D]}z"||dp||\}} } Wn&tk rtd||fYnX|t k r|} | |kr||n|||| | | | f||<| d7} t|| }qt| dddD]V\}\}} } ||krv||n|||||| | f||<t||d}qRt|t|t|kstdt|t|@t|kstdt|t|@t|t|@t|ks0tdt|t|@| D]b\} \}} } t|tshtd| t||ft| ttfs8| t ks8td| t| | fq8| D]"\} \}} } t | || | || <qd|d<t!t|"||||}||_#||_$||_%|S)Nrrz2_size_ cannot be set if "size" is passed in headerr, Fr)r=)rr=zEnot sure what to do with %s=%r (should be OFFSET [, DOC [, DEFAULT]])z5_order_ not specified and OFFSETs not declared for %rcSs|dd|dfSNrrrnvrrrz(NamedTupleMeta.__new__..)rz9unable to order fields: %s (use _order_ or specify OFFSETz!%s (from _order_) not found in %scSs|dd|dfSr?rr@rrrrBrCz/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__)&objecttupler%r isinstancer5r_convert_fieldsmaxitemsr&r setdefaultrr2 OrderedDictpopreplacesplitr Z baseinteger basestringr)ZNoneTypersetkeyssortedadd IndexErrorAssertionErrortyper#r __new__r _aliases_ _defined_len_)r6r7r8clsdictr9rr%Z base_dictZnamedtuple_basesbaseir$r(r'kvZ original_dictZ add_orderZ unnumberedZnumberedrtargetfieldsaliasesseenmax_lenoffsetsmissingnamedtuple_classrrrrX]s                   >  .    "     "     "    "22"4zNamedTupleMeta.__new__cGsLg}|D]>}t|}|jD]*}t||}||||j|j|jfqq|S)zBcreate list of index, doc, default triplets for cls in namedtuples)r)rgetattrrr%r!r')Z namedtuplesZ all_fieldsr7r\fielddescrrrrHs   zNamedTupleMeta._convert_fieldscCs*t|tstStd|j|jf||fiS)zWA new NamedTuple is created by concatenating the _fields_ and adjusting the descriptorsz%s%s)rGr5NotImplementedr)r7otherrrr__add__s zNamedTupleMeta.__add__c Os,|tks|jdkr|}|}zd|kr6|d}n|d|dd}}d|kr`|d}n|d|dd}}d|kr|d}n |r|d|dd}}nd}d|kr|d}n |r|d|dd}}nd}Wn&tk rtd||fYnX|s|r$td ||ftrjt|trjz| d }Wn$t k rhtd |fYnXt|t r||_ |dk r||j kr|f|j |_ |S|j} |f} | || } t|tr|d d }t|ttfr t|dtr ddt|D}d} |D]X} t| tr2| || } }n.t| dkrJ| \} }n| d| dd} }|| | <q|dk rt|ts|f}|| } | | || | }|dkrztdjd}Wntttfk rYnX|dkrt|n||_|S|j|f||}t||r$|j |||SdS)aCreates 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_namerNnamesmodulerWz'too few arguments to NamedTuple: %s, %sz(too many arguments to NamedTuple: %s, %sasciiz %r is not representable in ASCIIr;r<cSsg|]\}}||fqSrr).0r]errr Lsz+NamedTupleMeta.__call__..r=r)!rrZcopyrMrUrPY2rGunicodeencodeUnicodeEncodeErrorr5r __bases__rr:rPrNrOrFlist enumerater)rX_sys _getframe f_globalsr*rKeyErrorZmake_class_unpicklablerr )r7r rZ original_argsZ original_kwdsrnrorprWr6r8r[item field_nameZ field_indexrgZnamedtuple_instancerrr__call__s                    zNamedTupleMeta.__call__cCs t|jSr)r{rr7rrr __fields__tszNamedTupleMeta.__fields__cCs t|jSr)r{rYrrrr __aliases__zszNamedTupleMeta.__aliases__cCs d|jfS)Nz)rrrrrr/~szNamedTupleMeta.__repr__)rrr r! classmethodr&r:r rX staticmethodrHrmrbltin_propertyr_fieldsrr/r"rrrrr5Ss   r  r5zONamedTuple base class. Derive from this class to define new NamedTuples. )dictr(nsc Os|jtjkr0t||jkr0td|jt|ft|t|jt|j}|r^td|ft |t gt|j t|}| D]4\}}t ||j}||t krtd||||<q||g}t|D]D\}}|t kr|j |} t || j} | t kr|| q| ||<q|r|jtjtjfkrDtdd||rl|dt krl||qD|jtjk st |krtdd|t|t|S)Nz%d fields expected, %d receivedzunknown fields: %rz!field %s specified more than oncez$values not provided for field(s): %s, )rrr2r)rZrrQrrYr{r&rrJrhr%rr|r'rr3joinrMr4rFrX) r7r runknown final_argsrirr%rfr$r'rrrrXs:            rXcsjtfddjDfS)Nc3s|]}t|VqdSrrhrrfr.rr sz __reduce_ex__..)rrFr)r protorr.r __reduce_ex__srcCs^t|t|jkr:d|jjdddt|j|DfSd|jjddd|DfSdS)N%s(%s)rcSsg|]\}}d||fqS)z%s=%rr)rrrorrrrtsz__repr__..cSsg|] }t|qSr)repr)rrrrrrrts)r)rrrrzipr.rrrr/s r/cs&djjdfddjDfS)Nrrcsg|]}dt|fqS)z%rrrr.rrrtsz__str__..)rrrrr.rr.r__str__srcCs t|jjSrr{rrr.rrrrsrcCs t|jjSr)r{rrYr.rrrrsrcCs t|jjSrrr.rrrrsrcCs|j|f|Sr)rX)r7iterablenewr)rrr_makesrcCstt|j|Sr)rLrrr.rrr_asdictsrcKs|}|||jf|Sr)rupdater)r rcurrentrrr_replaces rcCsdSrr)r7rrrrrsr)NN)!Z_commonZ _constantrsysr}__all__rLrrEr#r&rrWr5Z _Addendumr:globalsZnamedtuple_dictrXrr/rrrrrrrrrrresolverrrrrs^ %0  !