B +�[4*�@sRddlZddlmZmZmZmZmZmZmZm Z m Z ddlm Z ddlm Z ddlmZdd�Zdd �Zd d �Zd d �ZGdd�de�ZdZdd�Zdd�Ze�Zdd�Zdd�Zeeedeefdd�Zdd�ZGdd�de�ZedediZiZ dd �Z!d!d"�Z"d#d$�Z#d%d&�Z$d2d'd(�Z%d3d)d*�Z&d+d�Z'iZ(d,d-�Z)d.d/�Z*defd0d1�Z+dS)4�N) � CheckedPMap� CheckedPSet�CheckedPVector� CheckedType�InvariantException�_restore_pickle�get_type�maybe_parse_user_type�maybe_parse_many_user_types)�optional)�wrap_invariant)�EnumcsZtt�fdd�|D�g��|�<x4t|���D]$\}}t|t�r.||�|<||=q.WdS)Ncs"g|]}t|j��i�����qS�)�list�__dict__�get�items)�.0�b)�namer�K/opt/alt/python37/lib64/python3.7/site-packages/pyrsistent/_field_common.py� szset_fields..)�dict�sumrr� isinstance�_PField)�dct�basesr�k�vr)rr� set_fieldss    r cs4tdd��fdd�|D�D��}|r0t|dd��dS)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#r�check_global_invariantssr%cCs&t|t�r|tkr|�|�S|||�S)N)rr�PFIELD_NO_SERIALIZER� serialize)� serializer�format�valuerrrr'#s r'csN|jrJt�fdd�|jD��sJt��}d�|j||j�}t|||j||��dS)Nc3s|]}t�t|��VqdS)N)rr)r�t)r*rrr!+szcheck_type..z'Invalid type for field {0}.{1}, was {2})�type�anyr)�__name__� PTypeError)Zdestination_cls�fieldrr*� actual_type�messager)r*r� check_type*sr3c@s$eZdZdZdd�Zedd��ZdS)r)r,r"�initial� mandatory�_factoryr(cCs(||_||_||_||_||_||_dS)N)r,r"r4r5r6r()�selfr,r"r4r5�factoryr(rrr�__init__4s z_PField.__init__cCs@|jtkr:t|j�dkr:tt|j�d�}t|t�r:|jS|jS)N�r) r6�PFIELD_NO_FACTORY�lenr,rr$� issubclassr�create)r7�typrrrr8<s  z_PField.factoryN)r.� __module__� __qualname__� __slots__r9�propertyr8rrrrr1srrcCsdS)N)TNr)�_rrr�G�rEcCs|S)Nr)�xrrrrEHrFcCs|S)Nr)rDr*rrrrEJrFcCs|S)Nr)rDr*rrrrEKrFFc Csft|tttf�rtt|��}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"r4r5r8r() rr�setr$r r �PFIELD_NO_INVARIANT�callabler r�_check_field_parameters) r,r"r4r5r8r(�typesZinvariant_functionr0rrrr0Ms  r0cs�x6�jD],}t|t�st|tj�std�t|����qW�jtk r~t�j�s~�jr~t �fdd��jD��s~td�t�j����t�j �s�td��t�j �s�td��t�j �s�td��dS)Nz Type parameter expected, not {0}c3s|]}t�j|�VqdS)N)rr4)rr+)r0rrr!xsz*_check_field_parameters..zInitial has invalid type {0}zInvariant must be callablezFactory must be callablezSerializer must be callable) r,r�six� string_types� TypeErrorr)r4�PFIELD_NO_INITIALrJr-r"r8r()r0r+r)r0rrKqs      rKcs eZdZdZ�fdd�Z�ZS)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/r9� source_classr0�expected_typesr1)r7rRr0rSr1�args�kwargs)� __class__rrr9�s zPTypeError.__init__)r.r@rA�__doc__r9� __classcell__rr)rVrr/�s r/ZPVectorZPSetcCst||f}t||�S)z=Unpickling function for auto-generated PVec/PSet field types.)�_seq_field_typesr)� checked_class� item_type�data�type_rrr�_restore_seq_field_pickle�s r^cCsd�dd�|D��S)z4Convert a tuple of types to a human-readable string.�css|]}t|�j��VqdS)N)rr.� capitalize)rr?rrrr!�sz"_types_to_names..)�join)rLrrr�_types_to_names�srbcsXt���f�}|dk r|SG��fdd�d��}t�}t|j�||_|t��f<|S)zFCreate a subclass of the given checked class with the given item type.NcseZdZ�Z��fdd�ZdS)z%_make_seq_field_type..TheTypecst��t|�ffS)N)r^r)r7)rZr[rr� __reduce__�sz0_make_seq_field_type..TheType.__reduce__N)r.r@rAZ__type__rcr)rZr[rr�TheType�srd)rYr�SEQ_FIELD_TYPE_SUFFIXESrbZ_checked_typesr.)rZr[r]rd�suffixr)rZr[r�_make_seq_field_type�s rgcsBt||��|r�fdd�}n�j}t|r0t��n�|d||�d�S)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)rdrrr8�sz _sequence_field..factoryT)r,r8r5r4)rgr>r0� optional_type)rZr[r r4r8r)rdr�_sequence_field�s rjcCstt|||�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. )rjr)r[r r4rrr� pset_field�s rkcCstt|||�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. )rjr)r[r r4rrr� pvector_field�s rlcCsdS)N)Tr_r)�itemrrrrE�rFcCst||f}t||�S)z8Unpickling function for auto-generated PMap field types.)�_pmap_field_typesr)�key_type� value_typer\r]rrr�_restore_pmap_field_pickle�s rqcsZt���f�}|dk r|SG��fdd�dt�}d�t|j�t|j��|_|t��f<|S)zDCreate a subclass of CheckedPMap with the given key and value types.NcseZdZ�Z�Zdd�ZdS)z%_make_pmap_field_type..TheMapcSst|j|jt|�ffS)N)rq� __key_type__�__value_type__r)r7rrrrc sz0_make_pmap_field_type..TheMap.__reduce__N)r.r@rArrrsrcr)rorprr�TheMapsrtz {0}To{1}PMap)rnrrr)rbZ_checked_key_typesZ_checked_value_typesr.)rorpr]rtr)rorpr�_make_pmap_field_types rucsBt||��|r�fdd�}n�j}td��|r6t��n�||d�S)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>)rh)rtrrr8%szpmap_field..factoryT)r5r4r,r8r")rur>r0ri)rorpr r"r8r)rtr� pmap_fields rv)Fr)Fr),rMZpyrsistent._checked_typesrrrrrrrr r r rir Zpyrsistent._compatr r r%r'r3�objectrZPFIELD_NO_TYPErIr;rPr&r0rKrOr/rerYr^rbrgrjrkrlZ_validrnrqrurvrrrr�sB,    #