a `]_ -@sdddlZddlmZmZmZmZmZmZmZm Z m Z ddlm Z ddlm Z ddlZejddkZddZdd Zd d Zd d ZddZddZGdddeZdZddZddZeZddZeeedeefddZddZGddde Z!ed ed!iZ"iZ#d"d#Z$d$d%Z%d&d'Z&d(d)Z'd5d*d+Z(d6d,d-Z)d.dZ*iZ+d/d0Z,d1d2Z-defd3d4Z.dS)7N) CheckedPMap CheckedPSetCheckedPVector CheckedTypeInvariantException_restore_pickleget_typemaybe_parse_user_typemaybe_parse_many_user_types)optional)wrap_invariantcsVttfdd|Dg|<t|D]$\}}t|tr,|||<||=q,dS)Ncs"g|]}t|jiqS)list__dict__getitems).0bnamer>/usr/lib64/python3.9/site-packages/pyrsistent/_field_common.py zset_fields..)dictsumrr isinstance_PField)Zdctbasesrkvrrr set_fieldss    r!cs4tddfdd|DD}|r0t|dddS)Ncss|]\}}|s|VqdSNr)rZis_okZ error_coderrr s z*check_global_invariants..c3s|]}|VqdSr"r)r invariantsubjectrrr# rrzGlobal invariant failed)tupler)r&Z invariantsZ error_codesrr%rcheck_global_invariantss r(cCs&t|tr|tur||S|||Sr")rrPFIELD_NO_SERIALIZER serialize) serializerformatvaluerrrr*%s r*csN|jrJtfdd|jDsJt}d|j||j}t|||j||dS)Nc3s|]}tt|VqdSr")rrrtr-rrr#-rzcheck_type..z'Invalid type for field {0}.{1}, was {2})typeanyr,__name__ PTypeError)Zdestination_clsfieldrr- actual_typemessagerr0r check_type,sr8cCs:t|turdSt|}t|dkr(dStt|d|S)NTrF)r1setr'len issubclassr)type_clsZ field_typetypesrrr is_type_cls3s   r>cCsD|sdSt||jsdStr.dt|jjvSdt|jjvSdS)NF ignore_extra) r>r1PY2inspectZ getargspecfactoryargsZ signature parameters)r<r5r?rrris_field_ignore_extra_complaint<s rEc@s$eZdZdZddZeddZdS)rr1r$initial mandatory_factoryr+cCs(||_||_||_||_||_||_dSr"rF)selfr1r$rGrHrBr+rrr__init__Ns z_PField.__init__cCs@|jtur:t|jdkr:tt|jd}t|tr:|jS|jS)Nr) rIPFIELD_NO_FACTORYr:r1rr'r;rcreate)rJtyprrrrBVs  z_PField.factoryN)r3 __module__ __qualname__ __slots__rKpropertyrBrrrrrKsrrcCsdS)N)TNr)_rrrarrUcCs|Sr"r)xrrrrUbrcCs|Sr"r)rTr-rrrrUdrFc Csft|tttfrtt|}n tt|}|tkrBt|rBt|n|}t ||||||d}t ||S)a Field specification factory for :py:class:`PRecord`. :param type: a type or iterable with types that are allowed for this field :param invariant: a function specifying an invariant that must hold for the field :param initial: value of field if not specified when instantiating the record :param mandatory: boolean specifying if the field is mandatory or not :param factory: function called when field is set. :param serializer: function that returns a serialized version of the field )r1r$rGrHrBr+) rrr9r'r r PFIELD_NO_INVARIANTcallabler r_check_field_parameters) r1r$rGrHrBr+r=Zinvariant_functionr5rrrr5gs r5csjD]*}t|tst|tstdt|qjturxtjsxjrxtfddjDsxtdtjtj stdtj stdtj stddS)Nz Type parameter expected, not {0}c3s|]}tj|VqdSr")rrGr.r5rrr#rz*_check_field_parameters..zInitial has invalid type {0}zInvariant must be callablezFactory must be callablezSerializer must be callable) r1rstr TypeErrorr,rGPFIELD_NO_INITIALrXr2r$rBr+)r5r/rrZrrYs"     rYcs eZdZdZfddZZS)r4a Raised when trying to assign a value with a type that doesn't match the declared type. Attributes: source_class -- The class of the record field -- Field name expected_types -- Types allowed for the field actual_type -- The non matching type cs2tt|j|i|||_||_||_||_dSr")superr4rK source_classr5expected_typesr6)rJr_r5r`r6rCkwargs __class__rrrKs zPTypeError.__init__)r3rPrQ__doc__rK __classcell__rrrbrr4s r4ZPVectorZPSetcCst||f}t||S)z=Unpickling function for auto-generated PVec/PSet field types.)_seq_field_typesr) checked_class item_typedatatype_rrr_restore_seq_field_pickles rkcCsddd|DS)z4Convert a tuple of types to a human-readable string.css|]}t|jVqdSr")rr3 capitalize)rrOrrrr#rz"_types_to_names..)join)r=rrr_types_to_namessrocsXtf}|dur|SGfddd}t}t|j||_|tf<|S)zFCreate a subclass of the given checked class with the given item type.NcseZdZZfddZdS)z%_make_seq_field_type..TheTypecstt|ffSr")rkrrJrgrhrr __reduce__s z0_make_seq_field_type..TheType.__reduce__N)r3rPrQZ__type__rrrrqrrTheTypesrs)rfrSEQ_FIELD_TYPE_SUFFIXESroZ_checked_typesr3)rgrhrjrssuffixrrqr_make_seq_field_types rvcsDt|||rdfdd }nj}t|r2tn|d||dS)a Create checked field for either ``PSet`` or ``PVector``. :param checked_class: ``CheckedPSet`` or ``CheckedPVector``. :param item_type: The required type for the items in the set. :param optional: If true, ``None`` can be used as a value for this field. :param initial: Initial value to pass to factory. :return: A ``field`` containing a checked class. NFcs |dur dSj|||dSdS)N)_factory_fieldsr?rN)argumentrwr?rsrrrBsz _sequence_field..factoryT)r1rBrHrG)NF)rvrNr5 optional_type)rgrhr rGrBrrzr_sequence_fields r|cCstt|||S)al Create checked ``PSet`` field. :param item_type: The required type for the items in the set. :param optional: If true, ``None`` can be used as a value for this field. :param initial: Initial value to pass to factory if no value is given for the field. :return: A ``field`` containing a ``CheckedPSet`` of the given type. )r|rrhr rGrrr pset_fields r~cCstt|||S)au Create checked ``PVector`` field. :param item_type: The required type for the items in the vector. :param optional: If true, ``None`` can be used as a value for this field. :param initial: Initial value to pass to factory if no value is given for the field. :return: A ``field`` containing a ``CheckedPVector`` of the given type. )r|rr}rrr pvector_fields rcCsdS)N)Trlr)itemrrrrUrcCst||f}t||S)z8Unpickling function for auto-generated PMap field types.)_pmap_field_typesr)key_type value_typerirjrrr_restore_pmap_field_pickles rcsZtf}|dur|SGfdddt}dt|jt|j|_|tf<|S)zDCreate a subclass of CheckedPMap with the given key and value types.NcseZdZZZddZdS)z%_make_pmap_field_type..TheMapcSst|j|jt|ffSr")r __key_type____value_type__rrprrrrr%sz0_make_pmap_field_type..TheMap.__reduce__N)r3rPrQrrrrrrrrrTheMap!srz {0}To{1}PMap)rrrr,roZ_checked_key_typesZ_checked_value_typesr3)rrrjrrrr_make_pmap_field_types rcsBt|||rfdd}nj}td|r6tn||dS)ad Create a checked ``PMap`` field. :param key: The required type for the keys of the map. :param value: The required type for the values of the map. :param optional: If true, ``None`` can be used as a value for this field. :param invariant: Pass-through to ``field``. :return: A ``field`` containing a ``CheckedPMap``. cs|dur dS|SdSr"rx)ryrrrrB?szpmap_field..factoryT)rHrGr1rBr$)rrNr5r{)rrr r$rBrrr pmap_field0s r)Fr)Fr)/sysZpyrsistent._checked_typesrrrrrrrr r r r{r rA version_infor@r!r(r*r8r>rEobjectrZPFIELD_NO_TYPErWrMr]r)r5rYr\r4rtrfrkrorvr|r~rZ_validrrrrrrrrsJ,     $