HEX
Server: LiteSpeed
System: Linux standart9.isimtescil.net 3.10.0-962.3.2.lve1.5.26.7.el7.x86_64 #1 SMP Wed Oct 2 07:53:12 EDT 2019 x86_64
User: karalev (5310)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //opt/alt/python37/lib64/python3.7/site-packages/pyrsistent/__pycache__/_pclass.cpython-37.pyc
B

���[�$�@s�ddlZddlmZmZmZmZddlmZmZm	Z	m
Z
mZddlm
Z
dd�ZGdd�de�Ze�Zd	d
�Ze�e�Gdd�de��ZGd
d�de�ZdS)�N)�InvariantException�CheckedType�_restore_pickle�store_invariants)�
set_fields�
check_type�PFIELD_NO_INITIAL�	serialize�check_global_invariants)�	transformcCst|�dko|dtkS)N�r)�lenr)�bases�r�E/opt/alt/python37/lib64/python3.7/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>sz%PClassMeta.__new__.<locals>.<genexpr>�	__slots__)�__weakref__)rr�tupler�superr�__new__)ZmcsrrZdct)�	__class__rrrszPClassMeta.__new__)�__name__�
__module__�__qualname__r�
__classcell__rr)rrrsrcCs<t||||�|�|�\}}|s,|�|�nt|||�dS)N)rZ	invariant�append�setattr)�cls�fieldr�value�result�invariant_errorsZis_okZ
error_coderrr�_check_and_set_attrs
r+cs�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
    c
s&tt|��|�}|�dd�}g}g}x�|j��D]�\}}||kr�|dksP||kr`|�||�}n||}t||||||�||=q0|jt	k	r�t
|j�r�|��n|j}	t||||	||�q0|jr0|�d�
|j|��q0W|s�|r�tt|�t|�d��|�rtd�
d�|�|j���t||j�d|_|S)N�_factory_fieldsz{0}.{1}zField invariant failedz0'{0}' are not among the specified fields for {1}z, T)rr,r�popr�items�factoryr+�initialr�callableZ	mandatoryr$�formatr rr�AttributeError�joinr
rr)
r&�kwargsr)�factory_fieldsZmissing_fieldsr*rr'r(r1)rrrr.s2
zPClass.__new__cOsd|r|d||d<t|�}x2|jD](}||kr$t||t�}|tk	r$|||<q$W|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)
        rrr-)�setr�getattr�_MISSING_VALUEr)�self�argsr6r7rr(rrrr8Nsz
PClass.setNFcs8t�|�r�S|r&�fdd�|jD��|fd|i���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|]}|�kr�||�qSrr)r�k)r6rr�
<dictcomp>{sz!PClass.create.<locals>.<dictcomp>r-)�
isinstancer)r&r6r-Zignore_extrar)r6r�createns
	
z
PClass.createcCsDi}x:|jD]0}t||t�}|tk	rt|j|j||�||<qW|S)z�
        Serialize the current PClass using custom serializer functions for fields where
        such have been supplied.
        )rr9r:r	Z
serializer)r;r3r)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)r;Ztransformationsrrrr�szPClass.transformcCs@t||j�r<x*|jD] }t||t�t||t�krdSqWdStS)NFT)r?rrr9r:�NotImplemented)r;�otherrrrr�__eq__�sz
PClass.__eq__cCs
||kS)Nr)r;rBrrr�__ne__�sz
PClass.__ne__cstt�fdd��jD���S)Nc3s|]}|t�|t�fVqdS)N)r9r:)rr)r;rrr�sz"PClass.__hash__.<locals>.<genexpr>)�hashrr)r;r)r;r�__hash__�szPClass.__hash__cs2t|dd�rtd�||���tt|��||�dS)NrFz'Can't set attribute, key={0}, value={1})r9r4r3rr,�__setattr__)r;rr()rrrrG�szPClass.__setattr__cCstd�|���dS)Nz-Can't delete attribute, key={0}, use remove())r4r3)r;rrrr�__delattr__�szPClass.__delattr__cCs4i}x*|jD] }t||t�}|tk	r|||<qW|S)N)rr9r:)r;r)rr(rrr�_to_dict�szPClass._to_dictcCs(d�|jjd�dd�|����D���S)Nz{0}({1})z, css"|]\}}d�|t|��VqdS)z{0}={1}N)r3�repr)rr=�vrrrr�sz"PClass.__repr__.<locals>.<genexpr>)r3rr r5rIr/)r;rrr�__repr__�s
zPClass.__repr__cs&t�fdd��jD��}t�j|ffS)Nc3s&|]}t�|�r|t�|�fVqdS)N)�hasattrr9)rr)r;rrr�sz$PClass.__reduce__.<locals>.<genexpr>)�dictrrr)r;�datar)r;r�
__reduce__�szPClass.__reduce__cCst||���S)z5
        Returns an evolver for this object.
        )�_PClassEvolverrI)r;rrr�evolver�szPClass.evolvercCs|��}||=|��S)z�
        Remove attribute given by name from the current instance. Raises AttributeError if the
        attribute doesn't exist.
        )rR�
persistent)r;rrRrrr�remove�sz
PClass.remove)NF)N)r r!r"�__doc__rr8�classmethodr@r	rrCrDrFrGrHrIrLrPrRrTr#rr)rrr,$s"	  

	
	r,cs`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
�fdd�Zdd�Z�Z
S)rQ)�_pclass_evolver_original�_pclass_evolver_data�_pclass_evolver_data_is_dirtyr-cCs||_||_d|_t�|_dS)NF)rWrXrYr8r-)r;ZoriginalZinitial_dictrrr�__init__�sz_PClassEvolver.__init__cCs
|j|S)N)rX)r;�itemrrr�__getitem__�sz_PClassEvolver.__getitem__cCs2|j�|t�|k	r.||j|<|j�|�d|_|S)NT)rX�getr:r-�addrY)r;rr(rrrr8�s

z_PClassEvolver.setcCs|�||�dS)N)r8)r;rr(rrr�__setitem__�sz_PClassEvolver.__setitem__cCs4||jkr(|j|=|j�|�d|_|St|��dS)NT)rXr-�discardrYr4)r;r[rrrrT�s
z_PClassEvolver.removecCs|�|�dS)N)rT)r;r[rrr�__delitem__�sz_PClassEvolver.__delitem__cCs&|jr |jjfd|ji|j��S|jS)Nr-)rYrWrr-rX)r;rrrrS�s
z_PClassEvolver.persistentcs.||jkr|�||�ntt|��||�dS)N)rr8rrQrG)r;rr()rrrrG�s
z_PClassEvolver.__setattr__cCs||S)Nr)r;r[rrr�__getattr__sz_PClassEvolver.__getattr__)r r!r"rrZr\r8r_rTrarSrGrbr#rr)rrrQ�s	rQ)ZsixZpyrsistent._checked_typesrrrrZpyrsistent._field_commonrrrr	r
Zpyrsistent._transformationsrr�typer�objectr:r+Z
add_metaclassr,rQrrrr�<module>s
	-