• File: _pclass.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib64/python3.7/site-packages/pyrsistent/__pycache__/_pclass.cpython-37.pyc
  • Date Modified: 04/24/2023 7:32 PM
  • File size: 9.52 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

[$@sddlZddlmZmZmZmZddlmZmZm	Z	m
Z
mZddlm
Z
ddZGdddeZeZd	d
ZeeGdddeZGd
ddeZdS)N)InvariantExceptionCheckedType_restore_picklestore_invariants)
set_fields
check_typePFIELD_NO_INITIAL	serializecheck_global_invariants)	transformcCst|dko|dtkS)Nr)lenr)basesrE/opt/alt/python37/lib64/python3.7/site-packages/pyrsistent/_pclass.py
_is_pclasssrcseZdZfddZZS)
PClassMetacsht||ddt||dddtdd|dD|d<t|rR|dd	7<tt|||||S)
N_pclass_fields)name_pclass_invariantsZ
__invariant__)_pclass_frozencss|]
}|VqdS)Nr).0keyrrr	<genexpr>sz%PClassMeta.__new__.<locals>.<genexpr>	__slots__)__weakref__)rrtuplersuperr__new__)ZmcsrrZdct)	__class__rrrszPClassMeta.__new__)__name__
__module____qualname__r
__classcell__rr)rrrsrcCs<t||||||\}}|s,||nt|||dS)N)rZ	invariantappendsetattr)clsfieldrvalueresultinvariant_errorsZis_okZ
error_coderrr_check_and_set_attrs
r+cseZdZdZfddZddZed"dd	Zd#d
dZdd
Z	ddZ
ddZddZfddZ
ddZddZddZddZddZd d!ZZS)$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|jD]\}}||kr|dksP||kr`|||}n||}t||||||||=q0|jt	k	rt
|jr|n|j}	t||||	||q0|jr0|d
|j|q0W|s|rtt|t|d|rtd
d||jt||jd|_|S)N_factory_fieldsz{0}.{1}zField invariant failedz0'{0}' are not among the specified fields for {1}z, T)rr,rpopritemsfactoryr+initialrcallableZ	mandatoryr$formatr rrAttributeErrorjoinr
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-)setrgetattr_MISSING_VALUEr)selfargsr6r7rr(rrrr8Nsz
PClass.setNFcs8t|rS|r&fdd|jD|fd|iS)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)rk)r6rr
<dictcomp>{sz!PClass.create.<locals>.<dictcomp>r-)
isinstancer)r&r6r-Zignore_extrar)r6rcreatens
	
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;ZtransformationsrrrrszPClass.transformcCs@t||jr<x*|jD] }t||tt||tkrdSqWdStS)NFT)r?rrr9r:NotImplemented)r;otherrrrr__eq__sz
PClass.__eq__cCs
||kS)Nr)r;rBrrr__ne__sz
PClass.__ne__csttfddjDS)Nc3s|]}|t|tfVqdS)N)r9r:)rr)r;rrrsz"PClass.__hash__.<locals>.<genexpr>)hashrr)r;r)r;r__hash__szPClass.__hash__cs2t|ddrtd||tt|||dS)NrFz'Can't set attribute, key={0}, value={1})r9r4r3rr,__setattr__)r;rr()rrrrGs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_dictszPClass._to_dictcCs(d|jjddd|DS)Nz{0}({1})z, css"|]\}}d|t|VqdS)z{0}={1}N)r3repr)rr=vrrrrsz"PClass.__repr__.<locals>.<genexpr>)r3rr r5rIr/)r;rrr__repr__s
zPClass.__repr__cs&tfddjD}tj|ffS)Nc3s&|]}t|r|t|fVqdS)N)hasattrr9)rr)r;rrrsz$PClass.__reduce__.<locals>.<genexpr>)dictrrr)r;datar)r;r
__reduce__szPClass.__reduce__cCst||S)z5
        Returns an evolver for this object.
        )_PClassEvolverrI)r;rrrevolverszPClass.evolvercCs|}||=|S)z
        Remove attribute given by name from the current instance. Raises AttributeError if the
        attribute doesn't exist.
        )rR
persistent)r;rrRrrrremovesz
PClass.remove)NF)N)r r!r"__doc__rr8classmethodr@r	rrCrDrFrGrHrIrLrPrRrTr#rr)rrr,$s"	  

	
	r,cs`eZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
fddZddZ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)rXgetr:r-addrY)r;rr(rrrr8s

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[rrrrTs
z_PClassEvolver.removecCs||dS)N)rT)r;r[rrr__delitem__sz_PClassEvolver.__delitem__cCs&|jr |jjfd|ji|jS|jS)Nr-)rYrWrr-rX)r;rrrrSs
z_PClassEvolver.persistentcs.||jkr|||ntt|||dS)N)rr8rrQrG)r;rr()rrrrGs
z_PClassEvolver.__setattr__cCs||S)Nr)r;r[rrr__getattr__sz_PClassEvolver.__getattr__)r r!r"rrZr\r8r_rTrarSrGrbr#rr)rrrQs	rQ)ZsixZpyrsistent._checked_typesrrrrZpyrsistent._field_commonrrrr	r
Zpyrsistent._transformationsrrtyperobjectr:r+Z
add_metaclassr,rQrrrr<module>s
	-