a `Å]_Wã@s„ddlmZmZmZmZddlmZmZmZm Z m Z m Z ddl m Z mZGdd„deƒZGdd„de eed�ZGd d „d e jƒZd S) é)Ú CheckedTypeÚ_restore_pickleÚInvariantExceptionÚstore_invariants)Ú set_fieldsÚ check_typeÚis_field_ignore_extra_complaintÚPFIELD_NO_INITIALÚ serializeÚcheck_global_invariants)ÚPMapÚpmapcseZdZ‡fdd„Z‡ZS)Ú _PRecordMetacsvt||dd�t||ddƒtdd„|d ¡Dƒƒ|d<tdd„|d ¡Dƒƒ|d <d |d <tt|ƒ ||||¡S) NÚ_precord_fields)ÚnameÚ_precord_invariantsZ __invariant__css|]\}}|jr|VqdS©N)Z mandatory)Ú.0rÚfield©rú9/usr/lib64/python3.9/site-packages/pyrsistent/_precord.pyÚ óz'_PRecordMeta.__new__..Ú_precord_mandatory_fieldscss&|]\}}|jtur||jfVqdSr)Úinitialr )rÚkrrrrrrÚ_precord_initial_valuesrÚ __slots__)rrÚsetÚitemsÚdictÚsuperrÚ__new__)ZmcsrÚbasesZdct©Ú __class__rrr" sÿÿz_PRecordMeta.__new__)Ú__name__Ú __module__Ú __qualname__r"Ú __classcell__rrr$rrsrcs\eZdZdZ‡fdd„Z‡fdd„Zdd„Zdd „Zedd d „ƒZ dd„Z ddd„Z ‡Z S)ÚPRecordau A PRecord is a PMap with a fixed set of specified fields. Records are declared as python classes inheriting from PRecord. Because it is a PMap it has full support for all Mapping methods such as iteration and element access using subscript notation. More documentation and examples of PRecord usage is available at https://github.com/tobgu/pyrsistent c s¤d|vr,d|vr,tt|ƒ ||d|d¡S| dd¡}| dd¡}|}|jrptdd„|j ¡Dƒƒ}| |¡t|t ƒ||d�}| ¡D]\}}|||<qŠ|  ¡S) NÚ _precord_sizeÚ_precord_bucketsÚ_factory_fieldsÚ _ignore_extraFcss(|] \}}|t|ƒr|ƒn|fVqdSr)Úcallable©rrÚvrrrr-sÿz"PRecord.__new__..©r-r.) r!r*r"Úpoprr rÚupdateÚ_PRecordEvolverr Ú persistent)ÚclsÚkwargsZfactory_fieldsÚ ignore_extraZinitial_valuesÚerr1r$rrr"!s  ÿ  zPRecord.__new__cs(|rtt|ƒ |d|d¡S| |¡S)a Set a field in the record. This set function differs slightly from that in the PMap class. First of all it accepts key-value pairs. Second it accepts multiple key-value pairs to perform one, atomic, update of multiple fields. ré)r!r*rr4)ÚselfÚargsr8r$rrr7s z PRecord.setcCs t|j|ƒS)z4 Returns an evolver of this object. )r5r%©r<rrrÚevolverEszPRecord.evolvercCs$d |jjd dd„| ¡Dƒ¡¡S)Nz{0}({1})z, css"|]\}}d |t|ƒ¡VqdS)z{0}={1}N)ÚformatÚreprr0rrrrMrz#PRecord.__repr__..)r@r%r&Újoinrr>rrrÚ__repr__Ks ÿzPRecord.__repr__NFcs:tˆ|ƒrˆS|r&‡fdd„|jDƒ‰|f||dœˆ¤ŽS)a< Factory method. Will create a new PRecord of the current type and assign the values specified in kwargs. :param ignore_extra: A boolean which when set to True will ignore any keys which appear in kwargs that are not in the set of fields on the PRecord. csi|]}|ˆvr|ˆ|“qSrr)rr©r8rrÚ \rz"PRecord.create..r2)Ú isinstancer)r7r8r-r9rrDrÚcreateOs zPRecord.createcCst|jt|ƒffSr)rr%r r>rrrÚ __reduce__`szPRecord.__reduce__cst‡‡fdd„ˆ ¡DƒƒS)zƒ Serialize the current PRecord using custom serializer functions for fields where such have been supplied. c3s*|]"\}}|tˆj|jˆ|ƒfVqdSr)r rZ serializerr0©r@r<rrrirz$PRecord.serialize..)r r)r<r@rrIrr dszPRecord.serialize)NF)N) r&r'r(Ú__doc__r"rr?rCÚ classmethodrGrHr r)rrr$rr*s   r*)Ú metaclasscsBeZdZdZd ‡fdd„ Zdd„Z‡fdd „Z‡fd d „Z‡ZS) r5)Ú_destination_clsÚ_invariant_error_codesÚ_missing_fieldsr-r.NFcs2tt|ƒ |¡||_g|_g|_||_||_dSr)r!r5Ú__init__rMrNrOr-r.)r<r7Z original_pmapr-r.r$rrrPos z_PRecordEvolver.__init__cCs| ||¡dSr)r)r<ÚkeyÚoriginal_valuerrrÚ __setitem__wsz_PRecordEvolver.__setitem__c sü|jj |¡}|rä|jdus&||jvr z.tt||jƒrH|j||jd�}n | |¡}Wq¤tyœ}z0|j |j 7_ |j |j 7_ |WYd}~Sd}~00n|}t |j|||ƒ| |¡\}}|sÒ|j  |¡tt|ƒ ||¡Std ||jj¡ƒ‚dS)N)r9z/'{0}' is not among the specified fields for {1})rMrÚgetr-rr*r.ÚfactoryrrNZinvariant_errorsrOZmissing_fieldsrZ invariantÚappendr!r5rÚAttributeErrorr@r&)r<rQrRrÚvaluer:Zis_okZ error_coder$rrrzs$ z_PRecordEvolver.setcs¨|j‰| ¡}tt|ƒ ¡}|s*t|ˆƒs<ˆ|j|jd�}n|}ˆjrt|j t ‡fdd„ˆjt |  ¡ƒDƒƒ7_ |j s€|j r˜tt |j ƒt |j ƒdƒ‚t|ˆjƒ|S)N)r,r+c3s|]}d ˆj|¡VqdS)z{0}.{1}N)r@r&)rÚf©r7rrržrz-_PRecordEvolver.persistent..zField invariant failed)rMÚis_dirtyr!r5r6rFZ_bucketsÚ_sizerrOÚtuplerÚkeysrNrr r)r<r[ZpmÚresultr$rZrr6”s ÿ  ÿ z_PRecordEvolver.persistent)NF) r&r'r(rrPrSrr6r)rrr$rr5ls  r5N)Zpyrsistent._checked_typesrrrrZpyrsistent._field_commonrrrr r r Zpyrsistent._pmapr r Útyperr*Z_Evolverr5rrrrÚs  S