o
    ix                     @   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_invariants__invariant__c                 s   s    | ]
\}}|j r|V  qd S N)	mandatory).0r   field r   N/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/pyrsistent/_precord.py	<genexpr>       z'_PRecordMeta.__new__.<locals>.<genexpr>_precord_mandatory_fieldsc                 s   s(    | ]\}}|j tu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|v rd|v rt t| | |d |d S |dd }|dd}|}| jr8tdd | j D }|| t| t	t
| jd||d	}| D ]\}}|||< qJ| 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>)pre_sizer1   r2   )r#   r.   r$   popr   r"   r!   update_PRecordEvolverr   lenr   
persistent)clskwargsfactory_fieldsignore_extrainitial_valueser   r5   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    r9   )selfargsr>   r(   r   r   r    7   s   	
zPRecord.setc                 C   s   t | j| S )z4
        Returns an evolver of this object.
        )r:   r)   rD   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reprr4   r   r   r   r   M   s   " z#PRecord.__repr__.<locals>.<genexpr>)rH   r)   r*   joinr!   rF   r   r   r   __repr__K   s   
zPRecord.__repr__NFc                    s:   t  | r S |r fdd| jD  | d||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 | ]}| v r| | qS r   r   )r   r   r>   r   r   
<dictcomp>\   s    z"PRecord.create.<locals>.<dictcomp>r7   Nr   )
isinstancer   )r=   r>   r1   r@   r   rL   r   createO   s
   
	zPRecord.createc                 C   s   t | jt| ffS r   )r   r)   r"   rF   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   
serializerr4   rH   rD   r   r   r   i   s   * z$PRecord.serialize.<locals>.<genexpr>)r"   r!   )rD   rH   r   rR   r   r
   d   s   zPRecord.serializeNFr   )r*   r+   r,   __doc__r$   r    rG   rK   classmethodrO   rP   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 )r:   )_destination_cls_invariant_error_codes_missing_fieldsr1   r2   NFc                    s2   t t| | || _g | _g | _|| _|| _d S r   )r#   r:   __init__rW   rX   rY   r1   r2   )rD   r=   original_pmapr1   r2   r(   r   r   rZ   o   s   
z_PRecordEvolver.__init__c                 C   s   |  || d S r   )r    )rD   keyoriginal_valuer   r   r   __setitem__w   s   z_PRecordEvolver.__setitem__c              
      s   | j j|}|rq| jd u s|| jv rOztt|| jr$|j|| jd}n||}W n& tyN } z|  j	|j
7  _	|  j|j7  _| W  Y d }~S d }~ww |}t| j ||| ||\}}|sh| j	| tt| ||S td|| j j)N)r@   z/'{0}' is not among the specified fields for {1})rW   r   getr1   r   r.   r2   factoryr   rX   invariant_errorsrY   missing_fieldsr   	invariantappendr#   r:   r    AttributeErrorrH   r*   )rD   r\   r]   r   valuerB   is_ok
error_coder(   r   r   r    z   s*   
z_PRecordEvolver.setc                    s   | j  |  }tt|  }|st| s |j|jd}n|} jr:|  j	t
 fdd jt|  D 7  _	| js@| j	rLtt
| jt
| j	dt| j |S )N)r0   r/   c                 3   s    | ]
}d   j|V  qdS )z{0}.{1}N)rH   r*   )r   fr=   r   r   r      r   z-_PRecordEvolver.persistent.<locals>.<genexpr>zField invariant failed)rW   is_dirtyr#   r:   r<   rN   _buckets_sizer   rY   tupler    keysrX   r   r   r   )rD   rk   pmresultr(   rj   r   r<      s    z_PRecordEvolver.persistentrS   )	r*   r+   r,   r   rZ   r^   r    r<   r-   r   r   r(   r   r:   l   s    r:   N)pyrsistent._checked_typesr   r   r   r   pyrsistent._field_commonr   r   r   r	   r
   r   pyrsistent._pmapr   r   typer   r.   _Evolverr:   r   r   r   r   <module>   s     S