📄 _precord.cpython-39.pyc

Size: 7,014 bytes
Path: //usr/lib64/python3.9/site-packages/pyrsistent/__pycache__/_precord.cpython-39.pyc
Modified: 2022-02-11 23:38:07
a

`�]_W�@s�ddlmZmZmZmZddlmZmZmZm	Z	m
Z
mZddlm
Z
mZGdd�de�ZGdd�de
eed�ZGd	d
�d
e
j�ZdS)�)�CheckedType�_restore_pickle�InvariantException�store_invariants)�
set_fields�
check_type�is_field_ignore_extra_complaint�PFIELD_NO_INITIAL�	serialize�check_global_invariants)�PMap�pmapcseZdZ�fdd�Z�ZS)�_PRecordMetacsvt||dd�t||dd�tdd�|d��D��|d<tdd�|d��D��|d	<d
|d<tt|��||||�S)N�_precord_fields)�name�_precord_invariantsZ
__invariant__css|]\}}|jr|VqdS�N)Z	mandatory)�.0r�field�r�9/usr/lib64/python3.9/site-packages/pyrsistent/_precord.py�	<genexpr>�z'_PRecordMeta.__new__.<locals>.<genexpr>�_precord_mandatory_fieldscss&|]\}}|jtur||jfVqdSr)�initialr	)r�krrrrrr�_precord_initial_valuesr�	__slots__)rr�set�items�dict�superr�__new__)Zmcsr�basesZdct��	__class__rrr"	s��z_PRecordMeta.__new__)�__name__�
__module__�__qualname__r"�
__classcell__rrr$rrsrcs\eZdZdZ�fdd�Z�fdd�Zdd�Zdd	�Zeddd
��Z	dd�Z
ddd�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
    cs�d|vr,d|vr,tt|��||d|d�S|�dd�}|�dd�}|}|jrptdd�|j��D��}|�|�t|t	�||d�}|��D]\}}|||<q�|�
�S)	N�
_precord_size�_precord_buckets�_factory_fields�
_ignore_extraFcss(|] \}}|t|�r|�n|fVqdSr)�callable�rr�vrrrr-s�z"PRecord.__new__.<locals>.<genexpr>�r-r.)r!r*r"�poprr r�update�_PRecordEvolverr
�
persistent)�cls�kwargsZfactory_fields�ignore_extraZinitial_values�err1r$rrr"!s�

zPRecord.__new__cs(|rtt|��|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*rr4)�self�argsr8r$rrr7s	zPRecord.setcCst|j|�S)z4
        Returns an evolver of this object.
        )r5r%�r<rrr�evolverEszPRecord.evolvercCs$d�|jjd�dd�|��D���S)Nz{0}({1})z, css"|]\}}d�|t|��VqdS)z{0}={1}N)�format�reprr0rrrrMrz#PRecord.__repr__.<locals>.<genexpr>)r@r%r&�joinrr>rrr�__repr__Ks
�zPRecord.__repr__NFcs:t�|�r�S|r&�fdd�|jD��|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.
        csi|]}|�vr|�|�qSrr)rr�r8rr�
<dictcomp>\rz"PRecord.create.<locals>.<dictcomp>r2)�
isinstancer)r7r8r-r9rrDr�createOs
	
zPRecord.createcCst|jt|�ffSr)rr%r r>rrr�
__reduce__`szPRecord.__reduce__cst��fdd����D��S)z�
        Serialize the current PRecord using custom serializer functions for fields where
        such have been supplied.
        c3s*|]"\}}|t�j|j�|�fVqdSr)r
rZ
serializerr0�r@r<rrrirz$PRecord.serialize.<locals>.<genexpr>)r r)r<r@rrIrr
dszPRecord.serialize)NF)N)
r&r'r(�__doc__r"rr?rC�classmethodrGrHr
r)rrr$rr*sr*)�	metaclasscsBeZdZdZd�fdd�	Zdd�Z�fdd	�Z�fd
d�Z�ZS)
r5)�_destination_cls�_invariant_error_codes�_missing_fieldsr-r.NFcs2tt|��|�||_g|_g|_||_||_dSr)r!r5�__init__rMrNrOr-r.)r<r7Z
original_pmapr-r.r$rrrPosz_PRecordEvolver.__init__cCs|�||�dSr)r)r<�key�original_valuerrr�__setitem__wsz_PRecordEvolver.__setitem__c
s�|jj�|�}|r�|jdus&||jvr�z.tt||j�rH|j||jd�}n
|�|�}Wq�ty�}z0|j	|j
7_	|j|j7_|WYd}~Sd}~00n|}t
|j|||�|�|�\}}|s�|j	�|�tt|��||�Std�||jj���dS)N)r9z/'{0}' is not among the specified fields for {1})rMr�getr-rr*r.�factoryrrNZinvariant_errorsrOZmissing_fieldsrZ	invariant�appendr!r5r�AttributeErrorr@r&)r<rQrRr�valuer:Zis_okZ
error_coder$rrrzs$z_PRecordEvolver.setcs�|j�|��}tt|���}|s*t|��s<�|j|jd�}n|}�jrt|j	t
�fdd��jt|���D��7_	|j
s�|j	r�tt
|j
�t
|j	�d��t|�j�|S)N)r,r+c3s|]}d��j|�VqdS)z{0}.{1}N)r@r&)r�f�r7rrr�rz-_PRecordEvolver.persistent.<locals>.<genexpr>zField invariant failed)rM�is_dirtyr!r5r6rFZ_buckets�_sizerrO�tupler�keysrNrrr)r<r[Zpm�resultr$rZrr6�s ��z_PRecordEvolver.persistent)NF)	r&r'r(rrPrSrr6r)rrr$rr5ls
r5N)Zpyrsistent._checked_typesrrrrZpyrsistent._field_commonrrrr	r
rZpyrsistent._pmaprr
�typerr*Z_Evolverr5rrrr�<module>s
 S