B +[4*@sRddlZddlmZmZmZmZmZmZmZm Z m Z ddlm Z ddlm Z ddlmZddZdd Zd d Zd d ZGdddeZdZddZddZeZddZddZeeedeefddZddZGdddeZedediZiZ dd Z!d!d"Z"d#d$Z#d%d&Z$d2d'd(Z%d3d)d*Z&d+dZ'iZ(d,d-Z)d.d/Z*defd0d1Z+dS)4N) CheckedPMap CheckedPSetCheckedPVector CheckedTypeInvariantException_restore_pickleget_typemaybe_parse_user_typemaybe_parse_many_user_types)optional)wrap_invariant)EnumcsZttfdd|Dg|<x4t|D]$\}}t|tr.|||<||=q.WdS)Ncs"g|]}t|jiqS)list__dict__getitems).0b)namerK/opt/alt/python37/lib64/python3.7/site-packages/pyrsistent/_field_common.py szset_fields..)dictsumrr isinstance_PField)Zdctbasesrkvr)rr set_fieldss    rcs4tddfdd|DD}|r0t|dddS)Ncss|]\}}|s|VqdS)Nr)rZis_okZ error_coderrr sz*check_global_invariants..c3s|]}|VqdS)Nr)r invariant)subjectrrr srzGlobal invariant failed)tupler)r"Z invariantsZ error_codesr)r"rcheck_global_invariantssr$cCs&t|tr|tkr||S|||S)N)rrPFIELD_NO_SERIALIZER serialize) serializerformatvaluerrrr&#s r&csN|jrJtfdd|jDsJt}d|j||j}t|||j||dS)Nc3s|]}tt|VqdS)N)rr)rt)r)rrr +szcheck_type..z'Invalid type for field {0}.{1}, was {2})typeanyr(__name__ PTypeError)Zdestination_clsfieldrr) actual_typemessager)r)r check_type*sr2c@s$eZdZdZddZeddZdS)r)r+r!initial mandatory_factoryr'cCs(||_||_||_||_||_||_dS)N)r+r!r3r4r5r')selfr+r!r3r4factoryr'rrr__init__4s z_PField.__init__cCs@|jtkr:t|jdkr:tt|jd}t|tr:|jS|jS)Nr) r5PFIELD_NO_FACTORYlenr+rr# issubclassrcreate)r6typrrrr7<s  z_PField.factoryN)r- __module__ __qualname__ __slots__r8propertyr7rrrrr1srrcCsdS)N)TNr)_rrrGrDcCs|S)Nr)xrrrrDHrEcCs|S)Nr)rCr)rrrrDJrEcCs|S)Nr)rCr)rrrrDKrEFc 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 )r+r!r3r4r7r') rrsetr#r r PFIELD_NO_INVARIANTcallabler r_check_field_parameters) r+r!r3r4r7r'typesZinvariant_functionr/rrrr/Ms  r/csx6jD],}t|tst|tjstdt|qWjtk r~tjs~jr~t fddjDs~tdtjtj stdtj stdtj stddS)Nz Type parameter expected, not {0}c3s|]}tj|VqdS)N)rr3)rr*)r/rrr xsz*_check_field_parameters..zInitial has invalid type {0}zInvariant must be callablezFactory must be callablezSerializer must be callable) r+rsixZ string_types TypeErrorr(r3PFIELD_NO_INITIALrIr,r!r7r')r/r*r)r/rrJqs      rJcs eZdZdZfddZZS)r.a 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 cs.tt|j||||_||_||_||_dS)N)superr.r8 source_classr/expected_typesr0)r6rPr/rQr0argskwargs) __class__rrr8s zPTypeError.__init__)r-r?r@__doc__r8 __classcell__rr)rTrr.s r.ZPVectorZPSetcCst||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 r\cCsddd|DS)z4Convert a tuple of types to a human-readable string.css|]}t|jVqdS)N)rr- capitalize)rr>rrrr sz"_types_to_names..)join)rKrrr_types_to_namessr`csXtf}|dk r|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|ffS)N)r\r)r6)rXrYrr __reduce__sz0_make_seq_field_type..TheType.__reduce__N)r-r?r@Z__type__rar)rXrYrrTheTypesrb)rWrSEQ_FIELD_TYPE_SUFFIXESr`Z_checked_typesr-)rXrYr[rbsuffixr)rXrYr_make_seq_field_types recsBt|||rfdd}nj}t|r0tn|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. cs|dkr dS|SdS)N)r=)argument)rbrrr7sz _sequence_field..factoryT)r+r7r4r3)rer=r/ optional_type)rXrYr r3r7r)rbr_sequence_fields rhcCstt|||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. )rhr)rYr r3rrr pset_fields ricCstt|||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. )rhr)rYr r3rrr pvector_fields rjcCsdS)N)Tr]r)itemrrrrDrEcCst||f}t||S)z8Unpickling function for auto-generated PMap field types.)_pmap_field_typesr)key_type value_typerZr[rrr_restore_pmap_field_pickles rocsZtf}|dk r|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|ffS)N)ro __key_type____value_type__r)r6rrrra sz0_make_pmap_field_type..TheMap.__reduce__N)r-r?r@rprqrar)rmrnrrTheMapsrrz {0}To{1}PMap)rlrrr(r`Z_checked_key_typesZ_checked_value_typesr-)rmrnr[rrr)rmrnr_make_pmap_field_types rscsBt|||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|dkr dS|SdS)N)r=)rf)rrrrr7%szpmap_field..factoryT)r4r3r+r7r!)rsr=r/rg)rmrnr r!r7r)rrr pmap_fields rt)Fr)Fr),rLZpyrsistent._checked_typesrrrrrrrr r r rgr Zpyrsistent._compatr rr$r&r2objectrZPFIELD_NO_TYPErHr:rNr%r/rJrMr.rcrWr\r`rerhrirjZ_validrlrorsrtrrrrsB,    #