
    n9ex                         d dl mZmZmZmZ d dlmZmZmZm	Z	m
Z
mZ d dlmZmZ  G d de      Z G d deee      Z G d	 d
ej$                        Zy)    )CheckedType_restore_pickleInvariantExceptionstore_invariants)
set_fields
check_typeis_field_ignore_extra_complaintPFIELD_NO_INITIAL	serializecheck_global_invariants)PMappmapc                        e Zd Z fdZ xZS )_PRecordMetac                 
   t        ||d       t        ||dd       t        d |d   j                         D              |d<   t	        d |d   j                         D              |d<   d	|d
<   t
        t        |   | |||      S )N_precord_fields)name_precord_invariants__invariant__c              3   @   K   | ]  \  }}|j                   s|  y wN)	mandatory).0r   fields      5/usr/lib/python3/dist-packages/pyrsistent/_precord.py	<genexpr>z'_PRecordMeta.__new__.<locals>.<genexpr>   s     Zu%//Zs   _precord_mandatory_fieldsc              3   d   K   | ](  \  }}|j                   t        us||j                   f * y wr   )initialr
   )r   kr   s      r   r   z'_PRecordMeta.__new__.<locals>.<genexpr>   s,     }5V[VcVck|V|!U]]#}s   00_precord_initial_values 	__slots__)r   r   setitemsdictsuperr   __new__)mcsr   basesdct	__class__s       r   r(   z_PRecordMeta.__new__	   s    3$56e%:OL Z,=(>(D(D(FZZ 	'( }C8I4J4P4P4R}} 	%& K\3/T5#FF    )__name__
__module____qualname__r(   __classcell__r,   s   @r   r   r      s    G Gr-   r   c                   X     e Zd ZdZ fdZ fdZd Zd Zed	d       Z	d Z
d
dZ x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                    d|v rd|v rt         t        |   | |d   |d         S |j                  dd       }|j                  dd      }|}| j                  r;t        d | j                  j                         D              }|j                  |       t        | t        t        | j                              ||      }|j                         D ]
  \  }}|||<    |j                         S )	N_precord_size_precord_buckets_factory_fields_ignore_extraFc              3   N   K   | ]  \  }}|t        |      r |       n|f  y wr   )callabler   r    vs      r   r   z"PRecord.__new__.<locals>.<genexpr>-   s-      "S&*a $%Xa[aca"@ "Ss   #%)pre_sizer8   r9   )r'   r4   r(   popr!   r&   r%   update_PRecordEvolverr   lenr   
persistent)	clskwargsfactory_fieldsignore_extrainitial_valueser    r=   r,   s	           r   r(   zPRecord.__new__!   s     f$);v)E#.sF?4KVTfMghh$5t<zz/59&&! "S.1.I.I.O.O.Q"S SN!!&)Cs33F3F/G!HZh  yE  F"((* 	DAqAaD	 ||~r-   c                 ^    |rt         t        |   |d   |d         S | j                  |      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'   r4   r$   rA   )selfargsrF   r,   s      r   r$   zPRecord.set7   s3     $+DGT!W=={{6""r-   c                 .    t        | j                  |       S )z4
        Returns an evolver of this object.
        )rB   r,   rM   s    r   evolverzPRecord.evolverE   s     t~~t44r-   c                     dj                  | j                  j                  dj                  d | j	                         D                    S )Nz{0}({1})z, c              3   X   K   | ]"  \  }}d j                  |t        |             $ yw)z{0}={1}N)formatreprr<   s      r   r   z#PRecord.__repr__.<locals>.<genexpr>M   s%     *aDAq9+;+;AtAw+G*as   (*)rT   r,   r.   joinr%   rP   s    r   __repr__zPRecord.__repr__K   s?      !8!8!%*aTXT^T^T`*a!ac 	cr-   c                     t        ||       r|S |r"| j                  D ci c]  }||v s|||    }} | d||d|S c c}w )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.
        r?   r"   )
isinstancer   )rE   rF   r8   rH   r    s        r   createzPRecord.createO   sY     fc"M,/,?,?Oq1;alOFOY?,YRXYY Ps   	>>c                 <    t         | j                  t        |       ffS r   )r   r,   r&   rP   s    r   
__reduce__zPRecord.__reduce__`   s    d ===r-   c                 L     t         fd j                         D              S )z
        Serialize the current PRecord using custom serializer functions for fields where
        such have been supplied.
        c              3   p   K   | ]-  \  }}|t        j                  |   j                  |      f / y wr   )r   r   
serializer)r   r    r=   rT   rM   s      r   r   z$PRecord.serialize.<locals>.<genexpr>i   s7     kVZVWYZQ	$"6"6q"9"D"DfaPQks   36)r&   r%   )rM   rT   s   ``r   r   zPRecord.serialized   s     
 k^b^h^h^jkkkr-   NFr   )r.   r/   r0   __doc__r(   r$   rQ   rW   classmethodrZ   r\   r   r1   r2   s   @r   r4   r4      s>    ,#5c Z Z >lr-   r4   )	metaclassc                   >     e Zd ZdZd fd	Zd Z fdZ fdZ xZS )rB   )_destination_cls_invariant_error_codes_missing_fieldsr8   r9   c                 r    t         t        |   |       || _        g | _        g | _        || _        || _        y r   )r'   rB   __init__re   rf   rg   r8   r9   )rM   rE   original_pmapr8   r9   r,   s        r   ri   z_PRecordEvolver.__init__o   s:    ot-m< #&(#!.*r-   c                 (    | j                  ||       y r   )r$   )rM   keyoriginal_values      r   __setitem__z_PRecordEvolver.__setitem__w   s    n%r-   c                    | j                   j                  j                  |      }|r| j                  || j                  v rL	 t	        t
        || j                        r|j                  || j                        }n|j                  |      }n|}t        | j                   |||       |j                  |      \  }}|s| j                  j                  |       t         t"        | K  ||      S t'        dj)                  || j                   j*                              # t        $ rJ}| xj                  |j                  z  c_	        | xj                  |j                  z  c_        | cY d }~S d }~ww xY w)N)rH   z/'{0}' is not among the specified fields for {1})re   r   getr8   r	   r4   r9   factoryr   rf   invariant_errorsrg   missing_fieldsr   	invariantappendr'   rB   r$   AttributeErrorrT   r.   )	rM   rl   rm   r   valuerJ   is_ok
error_coder,   s	           r   r$   z_PRecordEvolver.setz   s>   %%5599#>##+u8L8L/L 6wtGYGYZ %n4K]K] ^ %n = 't,,eS%@ % 6E:++22:>$3C?? !R!Y!YZ]_c_t_t_}_}!~ *  //13E3EE/((A,<,<<(K s   A
D 	E0&?E+%E0+E0c           
      4   | j                   | j                         }t        t        |          }|st        |      s |j                  |j                        }n|}j                  rK| xj                  t        fdj                  t        |j                               z
  D              z  c_	        | j                  s| j                  r3t        t        | j                        t        | j                        d      t        |j                          |S )N)r7   r6   c              3   V   K   | ]   }d j                  j                  |       " yw)z{0}.{1}N)rT   r.   )r   frE   s     r   r   z-_PRecordEvolver.persistent.<locals>.<genexpr>   s)      *cPQ)*:*:3<<*K *cs   &)zField invariant failed)re   is_dirtyr'   rB   rD   rY   _buckets_sizer   rg   tupler$   keysrf   r   r   r   )rM   r}   pmresultrE   r,   s       @r   rD   z_PRecordEvolver.persistent   s    ##==??D46:b#."++RXXNFF((  E *c.1.K.KcRXR]R]R_N`.`*c %c c  &&$*>*>$U4+F+F%GtOcOcId%=? ? 	 (?(?@r-   r`   )	r.   r/   r0   r#   ri   rn   r$   rD   r1   r2   s   @r   rB   rB   l   s"    uI+&@4 r-   rB   N)pyrsistent._checked_typesr   r   r   r   pyrsistent._field_commonr   r   r	   r
   r   r   pyrsistent._pmapr   r   typer   r4   _EvolverrB   r"   r-   r   <module>r      sM    h h  (G4 G"PldK< Plf;dmm ;r-   