U
    [ex                     @   s   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 deZG dd deeedZG d	d
 d
ejZdS )    )CheckedType_restore_pickleInvariantExceptionstore_invariants)
set_fields
check_typeis_field_ignore_extra_complaintPFIELD_NO_INITIAL	serializecheck_global_invariants)PMappmapc                       s   e Zd Z fddZ  ZS )_PRecordMetac                    sv   t ||dd t||dd tdd |d  D |d< tdd |d  D |d	< d
|d< tt| | |||S )N_precord_fields)name_precord_invariantsZ__invariant__c                 s   s   | ]\}}|j r|V  qd S N)	mandatory).0r   field r   U/var/www/html/services/stratfitenv/lib/python3.8/site-packages/pyrsistent/_precord.py	<genexpr>   s      z'_PRecordMeta.__new__.<locals>.<genexpr>_precord_mandatory_fieldsc                 s   s&   | ]\}}|j tk	r||j fV  qd S r   )initialr	   )r   kr   r   r   r   r      s     
 _precord_initial_valuesr   	__slots__)r   r   setitemsdictsuperr   __new__)mcsr   basesdct	__class__r   r   r"   	   s    z_PRecordMeta.__new__)__name__
__module____qualname__r"   __classcell__r   r   r&   r   r      s   r   c                       s\   e Zd ZdZ fddZ fddZdd Zdd	 ZedddZ	dd Z
ddd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|kr,d|kr,t t| | |d |d S |dd }|dd}|}| jrptdd | j D }|| t| t	t
| jd||d	}| D ]\}}|||< q| S )
N_precord_size_precord_buckets_factory_fields_ignore_extraFc                 s   s(   | ] \}}|t |r| n|fV  qd S r   )callabler   r   vr   r   r   r   -   s   z"PRecord.__new__.<locals>.<genexpr>)Zpre_sizer/   r0   )r!   r,   r"   popr   r    r   update_PRecordEvolverr   lenr   
persistent)clskwargsZfactory_fieldsignore_extraZinitial_valueser   r3   r&   r   r   r"   !   s    

zPRecord.__new__c                    s(   |rt t| |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,   r   r6   )selfargsr;   r&   r   r   r   7   s    	zPRecord.setc                 C   s   t | j| S )z4
        Returns an evolver of this object.
        )r7   r'   r?   r   r   r   evolverE   s    zPRecord.evolverc                 C   s$   d | jjddd |  D S )Nz{0}({1})z, c                 s   s"   | ]\}}d  |t|V  qdS )z{0}={1}N)formatreprr2   r   r   r   r   M   s     z#PRecord.__repr__.<locals>.<genexpr>)rC   r'   r(   joinr   rA   r   r   r   __repr__K   s    
zPRecord.__repr__NFc                    s:   t  | r S |r& fdd| jD  | 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.
        c                    s   i | ]}| kr| | qS r   r   )r   r   r;   r   r   
<dictcomp>\   s       z"PRecord.create.<locals>.<dictcomp>r4   )
isinstancer   )r:   r;   r/   r<   r   rG   r   createO   s
    	
zPRecord.createc                 C   s   t | jt| ffS r   )r   r'   r    rA   r   r   r   
__reduce__`   s    zPRecord.__reduce__c                    s   t  fdd D S )z
        Serialize the current PRecord using custom serializer functions for fields where
        such have been supplied.
        c                 3   s*   | ]"\}}|t j| j |fV  qd S r   )r
   r   
serializerr2   rC   r?   r   r   r   i   s     z$PRecord.serialize.<locals>.<genexpr>)r    r   )r?   rC   r   rM   r   r
   d   s    zPRecord.serialize)NF)N)r(   r)   r*   __doc__r"   r   rB   rF   classmethodrJ   rK   r
   r+   r   r   r&   r   r,      s   r,   )	metaclassc                       sB   e Zd ZdZd fdd	Zdd Z fdd	Z fd
dZ  ZS )r7   )_destination_cls_invariant_error_codes_missing_fieldsr/   r0   NFc                    s2   t t| | || _g | _g | _|| _|| _d S r   )r!   r7   __init__rQ   rR   rS   r/   r0   )r?   r:   Zoriginal_pmapr/   r0   r&   r   r   rT   o   s    z_PRecordEvolver.__init__c                 C   s   |  || d S r   )r   )r?   keyoriginal_valuer   r   r   __setitem__w   s    z_PRecordEvolver.__setitem__c              
      s   | j j|}|r| jd ks&|| jkrz.tt|| jrH|j|| jd}n
||}W q tk
r } z,|  j	|j
7  _	|  j|j7  _|  W Y S d }~X Y qX n|}t| j ||| ||\}}|s| j	| tt| ||S td|| j jd S )N)r<   z/'{0}' is not among the specified fields for {1})rQ   r   getr/   r   r,   r0   factoryr   rR   Zinvariant_errorsrS   Zmissing_fieldsr   Z	invariantappendr!   r7   r   AttributeErrorrC   r(   )r?   rU   rV   r   valuer=   Zis_okZ
error_coder&   r   r   r   z   s$    z_PRecordEvolver.setc                    s   | j  |  }tt|  }|s*t| s< |j|jd}n|} jrt|  j	t
 fdd jt|  D 7  _	| js| j	rtt
| jt
| j	dt| j |S )N)r.   r-   c                 3   s   | ]}d   j|V  qdS )z{0}.{1}N)rC   r(   )r   fr:   r   r   r      s     z-_PRecordEvolver.persistent.<locals>.<genexpr>zField invariant failed)rQ   is_dirtyr!   r7   r9   rI   Z_buckets_sizer   rS   tupler   keysrR   r   r   r   )r?   r_   pmresultr&   r^   r   r9      s     z_PRecordEvolver.persistent)NF)	r(   r)   r*   r   rT   rW   r   r9   r+   r   r   r&   r   r7   l   s
   r7   N)Zpyrsistent._checked_typesr   r   r   r   Zpyrsistent._field_commonr   r   r   r	   r
   r   Zpyrsistent._pmapr   r   typer   r,   Z_Evolverr7   r   r   r   r   <module>   s
    S