Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/site-packages/pyrsistent/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/site-packages/pyrsistent/__pycache__/_pclass.cpython-35.pyc



���[�$�@s�ddlZddlmZmZmZmZddlmZmZm	Z	m
Z
mZddlm
Z
dd�ZGdd�de�Ze�Zd	d
�Zeje�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)�	transformcCs t|�dko|dtkS)N�r)�lenr)�bases�r�E/opt/alt/python35/lib64/python3.5/site-packages/pyrsistent/_pclass.py�
_is_pclasssrcs"eZdZ�fdd�Z�S)�
PClassMetacs�t||dd�t||dd�d
tdd�|dD��|d<t|�re|dd7<tt|�j||||�S)N�name�_pclass_fields�_pclass_invariantsZ
__invariant__�_pclass_frozencss|]}|VqdS)Nr)�.0�keyrrr�	<genexpr>sz%PClassMeta.__new__.<locals>.<genexpr>�	__slots__�__weakref__)r)r)rr�tupler�superr�__new__)Zmcsrr�dct)�	__class__rrrs%zPClassMeta.__new__)�__name__�
__module__�__qualname__rrr)r rrsrcCsRt||||�|j|�\}}|s>|j|�nt|||�dS)N)rZ	invariant�append�setattr)�cls�fieldr�value�result�invariant_errorsZis_okZ
error_coderrr�_check_and_set_attrs
r+cs�eZdZdZ�fdd�Zdd�Zedddd	��Zdd
d�Zdd
�Z	dd�Z
dd�Zdd�Z�fdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Z�S)"�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|�j|�}|jdd�}g}g}x�|jj�D]�\}}||kr�|dksv||kr�|j||�}n
||}t||||||�||=qF|jt	k	rt
|j�r�|j�n|j}	t||||	||�qF|jrF|jdj
|j|��qFW|s=|r[tt|�t|�d��|r�tdj
dj|�|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�callable�	mandatoryr$�formatr!rr�AttributeError�joinr
rr)
r&�kwargsr)�factory_fieldsZmissing_fieldsr*rr'r(r1)r rrr.s2

$	 		zPClass.__new__cOs|r|d||d<t|�}xE|jD]:}||kr.t||t�}|tk	r.|||<q.W|jd||�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�argsr7r8rr(rrrr9Nsz
PClass.setNFcsEt�|�r�S|r5�fdd�|jD��|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.
        cs)i|]}|�kr�||�qSrr)r�k)r7rr�
<dictcomp>{s	z!PClass.create.<locals>.<dictcomp>r-)�
isinstancer)r&r7r-Zignore_extrar)r7r�createns
	z
PClass.createcCs\i}xO|jD]D}t||t�}|tk	rt|j|j||�||<qW|S)z�
        Serialize the current PClass using custom serializer functions for fields where
        such have been supplied.
        )rr:r;r	Z
serializer)r<r4r)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.transformcCsVt||j�rRx9|jD].}t||t�t||t�krdSqWdStS)NFT)r@r rr:r;�NotImplemented)r<�otherrrrr�__eq__�s$z
PClass.__eq__cCs||kS)Nr)r<rCrrr�__ne__�sz
PClass.__ne__cs&tt�fdd��jD���S)Nc3s'|]}|t�|t�fVqdS)N)r:r;)rr)r<rrr�sz"PClass.__hash__.<locals>.<genexpr>)�hashrr)r<r)r<r�__hash__�szPClass.__hash__csGt|dd�r*tdj||���tt|�j||�dS)NrFz'Can't set attribute, key={0}, value={1})r:r5r4rr,�__setattr__)r<rr()r rrrH�szPClass.__setattr__cCstdj|���dS)Nz-Can't delete attribute, key={0}, use remove())r5r4)r<rrrr�__delattr__�szPClass.__delattr__cCsFi}x9|jD].}t||t�}|tk	r|||<qW|S)N)rr:r;)r<r)rr(rrr�_to_dict�szPClass._to_dictcCs8dj|jjdjdd�|j�j�D���S)Nz{0}({1})z, css-|]#\}}dj|t|��VqdS)z{0}={1}N)r4�repr)rr>�vrrrr�sz"PClass.__repr__.<locals>.<genexpr>)r4r r!r6rJr/)r<rrr�__repr__�szPClass.__repr__cs5t�fdd��jD��}t�j|ffS)Nc3s3|])}t�|�r|t�|�fVqdS)N)�hasattrr:)rr)r<rrr�sz$PClass.__reduce__.<locals>.<genexpr>)�dictrrr )r<�datar)r<r�
__reduce__�s"zPClass.__reduce__cCst||j��S)z5
        Returns an evolver for this object.
        )�_PClassEvolverrJ)r<rrr�evolver�szPClass.evolvercCs|j�}||=|j�S)z�
        Remove attribute given by name from the current instance. Raises AttributeError if the
        attribute doesn't exist.
        )rS�
persistent)r<rrSrrr�remove�sz
PClass.remove)r!r"r#�__doc__rr9�classmethodrAr	rrDrErGrHrIrJrMrQrSrUrr)r rr,$s"	  
	
	r,cs�eZdZdZdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
�fdd�Zdd�Z�S)rR�_pclass_evolver_original�_pclass_evolver_data�_pclass_evolver_data_is_dirtyr-cCs+||_||_d|_t�|_dS)NF)rXrYrZr9r-)r<�originalZinitial_dictrrr�__init__�s			z_PClassEvolver.__init__cCs|j|S)N)rY)r<�itemrrr�__getitem__�sz_PClassEvolver.__getitem__cCsE|jj|t�|k	rA||j|<|jj|�d|_|S)NT)rY�getr;r-�addrZ)r<rr(rrrr9�s

	z_PClassEvolver.setcCs|j||�dS)N)r9)r<rr(rrr�__setitem__�sz_PClassEvolver.__setitem__cCsF||jkr6|j|=|jj|�d|_|St|��dS)NT)rYr-�discardrZr5)r<r]rrrrU�s
	z_PClassEvolver.removecCs|j|�dS)N)rU)r<r]rrr�__delitem__�sz_PClassEvolver.__delitem__cCs,|jr%|jjd|j|j�S|jS)Nr-)rZrXr r-rY)r<rrrrT�s	
z_PClassEvolver.persistentcs?||jkr"|j||�ntt|�j||�dS)N)rr9rrRrH)r<rr()r rrrH�sz_PClassEvolver.__setattr__cCs||S)Nr)r<r]rrr�__getattr__sz_PClassEvolver.__getattr__)rXrYrZr-)
r!r"r#rr\r^r9rarUrcrTrHrdrr)r rrR�s	rR)�sixZpyrsistent._checked_typesrrrrZpyrsistent._field_commonrrrr	r
Zpyrsistent._transformationsrr�typer�objectr;r+�
add_metaclassr,rRrrrr�<module>s"(
		�