name : _pclass.cpython-39.pyc
a

`�]_�%�@s�ddlmZmZmZmZddlmZmZmZm	Z	m
Z
mZddlm
Z
dd�ZGdd�de�Ze�Zdd	�ZGd
d�deed�ZGd
d�de�ZdS)�)�InvariantException�CheckedType�_restore_pickle�store_invariants)�
set_fields�
check_type�is_field_ignore_extra_complaint�PFIELD_NO_INITIAL�	serialize�check_global_invariants��	transformcCst|�dko|dtkS)N�r)�lenr)�bases�r�8/usr/lib64/python3.9/site-packages/pyrsistent/_pclass.py�
_is_pclasssrcseZdZ�fdd�Z�ZS)�
PClassMetacsht||dd�t||dd�dtdd�|dD��|d<t|�rR|dd	7<tt|��||||�S)
N�_pclass_fields)�name�_pclass_invariantsZ
__invariant__)�_pclass_frozencss|]
}|VqdS�Nr��.0�keyrrr�	<genexpr>�z%PClassMeta.__new__.<locals>.<genexpr>�	__slots__)�__weakref__)rr�tupler�superr�__new__)ZmcsrrZdct��	__class__rrr#
szPClassMeta.__new__)�__name__�
__module__�__qualname__r#�
__classcell__rrr$rrsrcCs<t||||�|�|�\}}|s,|�|�nt|||�dSr)rZ	invariant�append�setattr)�cls�fieldr�value�result�invariant_errorsZis_okZ
error_coderrr�_check_and_set_attrs
r1cs�eZdZdZ�fdd�Zdd�Zed"dd	��Zd#d
d�Zdd
�Z	dd�Z
dd�Zdd�Z�fdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Z�ZS)$�PClassa�
    A PClass is a python class with a fixed set of specified fields. PClasses are declared as python classes inheriting
    from PClass. It is defined the same way that PRecords are and behaves like a PRecord in all aspects except that it
    is not a PMap and hence not a collection but rather a plain Python object.


    More documentation and examples of PClass usage is available at https://github.com/tobgu/pyrsistent
    csRtt|��|�}|�dd�}|�dd�}g}g}|j��D]�\}}||vr�|dusZ||vr�tt||�rz|j|||d�}	q�|�||�}	n||}	t||||	||�||=q:|j	t
ur�t|j	�r�|�	�n|j	}
t||||
||�q:|jr:|�
d�|j|��q:|�s
|�rtt|�t|�d��|�r<td�d�|�|j���t||j�d|_|S)	N�_factory_fields�ignore_extra)r4z{0}.{1}zField invariant failedz0'{0}' are not among the specified fields for {1}�, T)r"r2r#�popr�itemsr�factoryr1�initialr	�callableZ	mandatoryr*�formatr&rr!�AttributeError�joinrrr)r,�kwargsr/�factory_fieldsr4Zmissing_fieldsr0rr-r.r9r$rrr#.s<
��zPClass.__new__cOs`|r|d||d<t|�}|jD](}||vr"t||t�}|tur"|||<q"|jfd|i|��S)a
        Set a field in the instance. Returns a new instance with the updated value. The original instance remains
        unmodified. Accepts key-value pairs or single string representing the field name and a value.

        >>> from pyrsistent import PClass, field
        >>> class AClass(PClass):
        ...     x = field()
        ...
        >>> a = AClass(x=1)
        >>> a2 = a.set(x=2)
        >>> a3 = a.set('x', 3)
        >>> a
        AClass(x=1)
        >>> a2
        AClass(x=2)
        >>> a3
        AClass(x=3)
        rrr3)�setr�getattr�_MISSING_VALUEr%)�self�argsr>r?rr.rrrr@Rs

z
PClass.setNFcs:t�|�r�S|r&�fdd�|jD��|f||d����S)a:
        Factory method. Will create a new PClass 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 PClass.
        csi|]}|�vr|�|�qSrr)r�k�r>rr�
<dictcomp>rz!PClass.create.<locals>.<dictcomp>)r3r4)�
isinstancer)r,r>r3r4rrFr�creaters
	
z
PClass.createcCs@i}|jD]0}t||t�}|tur
t|j|j||�||<q
|S)z�
        Serialize the current PClass using custom serializer functions for fields where
        such have been supplied.
        )rrArBr
Z
serializer)rCr;r/rr.rrrr
�s
zPClass.serializecGs
t||�S)aT
        Apply transformations to the currency PClass. For more details on transformations see
        the documentation for PMap. Transformations on PClasses do not support key matching
        since the PClass is not a collection. Apart from that the transformations available
        for other persistent types work as expected.
        r)rCZtransformationsrrrr
�szPClass.transformcCs>t||j�r:|jD]"}t||t�t||t�krdSqdStS)NFT)rHr%rrArB�NotImplemented)rC�otherrrrr�__eq__�s
z
PClass.__eq__cCs
||kSrr)rCrKrrr�__ne__�sz
PClass.__ne__cstt�fdd��jD���S)Nc3s|]}|t�|t�fVqdSr)rArBr�rCrrr�rz"PClass.__hash__.<locals>.<genexpr>)�hashr!rrNrrNr�__hash__�szPClass.__hash__cs2t|dd�rtd�||���tt|��||�dS)NrFz'Can't set attribute, key={0}, value={1})rAr<r;r"r2�__setattr__�rCrr.r$rrrQ�szPClass.__setattr__cCstd�|���dS)Nz-Can't delete attribute, key={0}, use remove())r<r;)rCrrrr�__delattr__�szPClass.__delattr__cCs0i}|jD] }t||t�}|tur
|||<q
|Sr)rrArB)rCr/rr.rrr�_to_dict�s

zPClass._to_dictcCs(d�|jjd�dd�|����D���S)Nz{0}({1})r5css"|]\}}d�|t|��VqdS)z{0}={1}N)r;�repr)rrE�vrrrr�rz"PClass.__repr__.<locals>.<genexpr>)r;r%r&r=rTr7rNrrr�__repr__�s
�zPClass.__repr__cs&t�fdd��jD��}t�j|ffS)Nc3s&|]}t�|�r|t�|�fVqdSr)�hasattrrArrNrrr�rz$PClass.__reduce__.<locals>.<genexpr>)�dictrrr%)rC�datarrNr�
__reduce__�szPClass.__reduce__cCst||���S)z5
        Returns an evolver for this object.
        )�_PClassEvolverrTrNrrr�evolver�szPClass.evolvercCs|��}||=|��S)z�
        Remove attribute given by name from the current instance. Raises AttributeError if the
        attribute doesn't exist.
        )r]�
persistent)rCrr]rrr�remove�sz
PClass.remove)NF)N)r&r'r(�__doc__r#r@�classmethodrIr
r
rLrMrPrQrSrTrWr[r]r_r)rrr$rr2%s"$ 

	
	r2)�	metaclasscs`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
�fdd�Zdd�Z�Z
S)r\)�_pclass_evolver_original�_pclass_evolver_data�_pclass_evolver_data_is_dirtyr3cCs||_||_d|_t�|_dS)NF)rcrdrer@r3)rC�originalZinitial_dictrrr�__init__�sz_PClassEvolver.__init__cCs
|j|Sr)rd�rC�itemrrr�__getitem__�sz_PClassEvolver.__getitem__cCs2|j�|t�|ur.||j|<|j�|�d|_|S�NT)rd�getrBr3�addrerRrrrr@�s

z_PClassEvolver.setcCs|�||�dSr)r@rRrrr�__setitem__�sz_PClassEvolver.__setitem__cCs4||jvr(|j|=|j�|�d|_|St|��dSrk)rdr3�discardrer<rhrrrr_�s
z_PClassEvolver.removecCs|�|�dSr)r_rhrrr�__delitem__�sz_PClassEvolver.__delitem__cCs&|jr |jjfd|ji|j��S|jS)Nr3)rercr%r3rdrNrrrr^�s
�z_PClassEvolver.persistentcs.||jvr|�||�ntt|��||�dSr)rr@r"r\rQrRr$rrrQ�s
z_PClassEvolver.__setattr__cCs||Srrrhrrr�__getattr__sz_PClassEvolver.__getattr__)r&r'r(rrgrjr@rnr_rpr^rQrqr)rrr$rr\�s	r\N)Zpyrsistent._checked_typesrrrrZpyrsistent._field_commonrrrr	r
rZpyrsistent._transformationsr
r�typer�objectrBr1r2r\rrrr�<module>s 
	1

© 2025 Cubjrnet7