%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/
Upload File :
Create Path :
Current File : //opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyc

�
��4]c@sdZddlmZddlmZddlmZddlmZddlmZddlmZej�Z	d	e
fd
��YZdefd��YZ
d
efd��YZe�ZejZZejZZejZZd�Zd�Zd�Zd�ZdS(s�Defines SQLAlchemy's system of class instrumentation.

This module is usually not directly visible to user applications, but
defines a large part of the ORM's interactivity.

instrumentation.py deals with registration of end-user classes
for state tracking.   It interacts closely with state.py
and attributes.py which establish per-instance and per-class-attribute
instrumentation, respectively.

The class instrumentation system can be customized on a per-class
or global basis using the :mod:`sqlalchemy.ext.instrumentation`
module, which provides the means to build and specify
alternate instrumentation forms.

.. versionchanged: 0.8
   The instrumentation extension system was moved out of the
   ORM and into the external :mod:`sqlalchemy.ext.instrumentation`
   package.  When that package is imported, it installs
   itself within sqlalchemy.orm so that its more comprehensive
   resolution mechanics take effect.

i(tbase(tcollections(texc(t
interfaces(tstatei(tutiltClassManagercBs6eZdZejZejZee	j
e��Zd,Z
ejZd,Zd�Zd�Zd�Zed��Zed��Zed��Zed��Ze	jd��Zd,d	�Zd,d
�Zd�Zd�Zd
�Z d�Z!e	jd��Z"d�Z#d�Z$e	j%d��Z&e	j%d��Z'e	j%d��Z(e)d�Z*d�Z+d�Z,e)d�Z-d�Z.d�Z/d�Z0d�Z1d�Z2d�Z3d�Z4e)d �Z5d!�Z6ed"��Z7d,d#�Z8d,d$�Z9d%�Z:d&�Z;d'�Z<d(�Z=e)d)�Z>d*�Z?e?Z@d+�ZARS(-s,tracks state information at the class level.cCs7||_i|_d|_i|_i|_gg|jjD]!}t|t�r=t	|�^q=D]}|dk	rb|^qb|_
x|j
D]}|j|�q�W|jj
j||�x?|jD]4}t	|�}|dk	r�|jj|j�q�q�W|j�|j�d|jkr3tjd|�ndS(Nt__del__s�__del__() method on class %s will cause unreachable cycles and memory leaks, as SQLAlchemy instrumentation often creates reference cycles.  Please remove this method.(tclass_tinfotNonetnew_inittlocal_attrst	originalst	__bases__t
isinstancettypetmanager_of_classt_basestupdatetdispatcht_eventst_new_classmanager_instancet__mro__t_updatetmanaget_instrument_initt__dict__Rtwarn(tselfRRtmgrtbase_tbasecls((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt__init__:s.					%

cCs
t|�S(N(tid(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt__hash__`scCs
||kS(N((Rtother((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt__eq__cscCs
d|jkS(Ntmapper(R(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt	is_mappedfscCs
t|�S(N(t	frozenset(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt_all_key_setjscCs2tg|j�D]}|jjr|j^q�S(N(R(tvaluestimplt
collectiontkey(Rtattr((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt_collection_impl_keysnscCs2tg|j�D]}|jjr|j^q�S(N(R(R*R+taccepts_scalar_loader(RR.((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt_scalar_loader_implstscCstj|j��dS(N(RtUnmappedClassErrorR(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyR&~sccs�|dkrt�}nxz|jjD]l}xct|j�j|�D]I}|j|�|j|}t|tj	�rD|j
rD||fVqDqDWq%WdS(sreturn an iterator of all classbound attributes that are
        implement :class:`.InspectionAttr`.

        This includes :class:`.QueryableAttribute` as well as extension
        types such as :class:`.hybrid_property` and
        :class:`.AssociationProxy`.

        N(R
tsetRRRt
differencetaddRRtInspectionAttrtis_attribute(RtexcludetsuperclsR-tval((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt_all_sqla_attributes�s	

	cCs9x2|jjD] }||jkr
|j|Sq
W|SdS(s5return an attribute on the class without tripping it.N(RRR(RR-tdefaultR9((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt_get_class_attr_mro�scCs||ko||jdk	S(s\Return True if the given attribute is fully initialized.

        i.e. has an impl.
        N(R+R
(RR-((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt_attr_has_impl�scCs.t|�}|dkr*tj|�}n|S(s�Create a new ClassManager for a subclass of this ClassManager's
        class.

        This is called automatically when attributes are instrumented so that
        the attributes can be propagated to subclasses against their own
        class-local manager, without the need for mappers etc. to have already
        pre-configured managers for the full class hierarchy.   Mappers
        can post-configure the auto-generated ClassManager when needed.

        N(RR
t_instrumentation_factorytcreate_manager_for_cls(Rtclstmanager((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt_subclass_manager�scCs;|jj|_t|j|�|_|jd|j�dS(NR!(RR!t
original_initt_generate_initRtinstall_member(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyR�scCs&|jr"|jd�d|_ndS(NR!(Rtuninstall_memberR
(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt_uninstrument_init�s	
cCs|jj||j�tjS(N(Rt
first_initRRt
InstanceState(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt_state_constructor�scCst|j|j|�dS(s0Mark this instance as the manager for its class.N(tsetattrRtMANAGER_ATTR(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyR�scCst|j|j�dS(s)Dissasociate this manager from its class.N(tdelattrRRM(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pytdispose�scCstS(N(t_default_manager_getter(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pytmanager_getter�scCstS(s�Return a (instance) -> InstanceState callable.

        "state getter" callables should raise either KeyError or
        AttributeError if no InstanceState could be found for the
        instance.
        (t_default_state_getter(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pytstate_getter�s	cCstS(N(t_default_dict_getter(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pytdict_getter�scCs�|r||jkr9dSn||j|<|j||�tj|�|||<x9|jj�D](}|j|�}|j||t�q`WdS(N(	Rtinstall_descriptort_memoized_key_collectiontexpire_instanceRt__subclasses__RCtinstrument_attributetTrue(RR-tinstt
propagatedRARB((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyRZ�s


ccsrxk|jj�D]Z}t|�}|dk	r||k	r|V|rjx|jt�D]}|VqUWqjqqWdS(N(RRYRR
tsubclass_managersR[(Rt	recursiveRARtm((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyR^�scCs!tjj|j|||�dS(N(R?Rtattribute_instrumentR(RR-((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pytpost_configure_attributes	cCs�||krdS|r,||jkrCdSn|j|=|j|�tj|�||=x<|jj�D]+}t|�}|rg|j|t�qgqgWdS(N(	Rtuninstall_descriptorRWRXRRYRtuninstrument_attributeR[(RR-R]RARB((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyRds


cCsa|j�d|_|_|jj�x3t|�D]%}||jkr4|j|�q4q4WdS(s<remove all instrumentation established by this ClassManager.N(	RHR
R&RR	tcleartlistRRd(RR-((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt
unregisters

cCsB||j|jfkr+td|��nt|j||�dS(NsW%r: requested attribute name conflicts with instrumentation attribute of the same name.(t
STATE_ATTRRMtKeyErrorRLR(RR-R\((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyRV"s

cCst|j|�dS(N(RNR(RR-((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyRc*scCsd||j|jfkr+td|��n|jj|t|j|d��t|j||�dS(NsW%r: requested attribute name conflicts with instrumentation attribute of the same name.(	RhRMRiR
t
setdefaulttgetattrRR
RL(RR-timplementation((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyRF-s
"cCs;|jj|d�}|dk	r7t|j||�ndS(N(R
tpopR
RLR(RR-toriginal((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyRG6scCs
tj|�S(N(Rtprepare_instrumentation(RR-tcollection_class((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pytinstrument_collection_class;scCs1|�}tj|j|�||�}||fS(N(RtCollectionAdaptertget_impl(RR-Rtfactoryt	user_datatadapter((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pytinitialize_collection>s	cCs!|r||kS||jkSdS(N(R(RR-tsearch((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pytis_instrumentedEs
cCs||jS(N(R+(RR-((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyRsKscCst|j��S(N(titerR*(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt
attributesNscCsJ|jj|j�}|dkr6|j||�}n|j||�|S(N(Rt__new__R
RKt
_state_setter(RRtinstance((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pytnew_instanceTs
cCs5|dkr!|j||�}n|j||�dS(N(R
RKR}(RR~R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pytsetup_instance[scCst||j�dS(N(RNRh(RR~((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pytteardown_instance`scCs
t||�S(N(t_SerializeManager(RRt
state_dict((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt
_serializecscCstt||j�rtS|j|jk	rJ|jrJ|j|j�j|�S|j||�}|j	||�|SdS(s�Install a default InstanceState if none is present.

        A private convenience method used by the __init__ decorator.

        N(
thasattrRhtFalseRt	__class__R'RCt_new_state_if_noneRKR}(RR~R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyR�fscCst||j�S(N(R�Rh(RR~((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt	has_state|scCs|j|�j|d|�S(tTODOt
optimistic(Rst	hasparent(RRR-R�((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt
has_parentscCstS(s=All ClassManagers are non-zero regardless of attribute state.(R[(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt__bool__�scCs d|jj|jt|�fS(Ns<%s of %r at %x>(R�t__name__RR"(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt__repr__�s	N(BR�t
__module__t__doc__RtDEFAULT_MANAGER_ATTRRMtDEFAULT_STATE_ATTRRhtstaticmethodRt
attrsetterR}R
tdeferred_scalar_loadertobjectR!RDRtR#R%tpropertyR'RWR)R/R1tmemoized_propertyR&R;R=R>RCRRHRKRROthybridmethodRQRSRUR�RZR^RbRdRgRVRcRFRGRqRwRyRsR{RR�R�R�R�R�R�R�t__nonzero__R�(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyR,sf				&		
				
																				R�cBs eZdZd�Zd�ZRS(s�Provide serialization of a :class:`.ClassManager`.

    The :class:`.InstanceState` uses ``__init__()`` on serialize
    and ``__call__()`` on deserialize.

    cCs,|j|_|j}|jj||�dS(N(RRBRtpickle(RRtdRB((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyR!�s	cCs�t|j�|_}|dkr>tj|d|j��n&|jrd|jjrd|jj	�n|dk	r�|j
||�n|jj||�dS(NsxCannot deserialize object of type %r - no mapper() has been configured for this class within the current Python process!(
RRRBR
RtUnmappedInstanceErrorR'R&t
configuredt_configure_allR�Rtunpickle(RRR\R�RB((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt__call__�s(R�R�R�R!R�(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyR��s	tInstrumentationFactorycBs2eZdZd�Zd�Zd�Zd�ZRS(s'Factory for new ClassManager instances.cCs�|dk	st�t|�dks*t�|j|�\}}|dkr`t}||�}n|j||�||_|jj|�|S(N(	R
tAssertionErrorRt_locate_extended_factoryRt_check_conflictsRtRtclass_instrument(RRRBRt((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyR@�s	cCsdS(s2Overridden by a subclass to do an extended lookup.N(NN(R
(RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyR��scCsdS(s;Overridden by a subclass to test for conflicting factories.N((RRRt((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyR��scCsYt|�}|j�|j�|jj|�tj|jkrUt|tj�ndS(N(	RRgRORtclass_uninstrumentRRMRRN(RRRB((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyRg�s

(R�R�R�R@R�R�Rg(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyR��s
			cCs.t|�}|dkr*tj|�}n|S(s_Register class instrumentation.

    Returns the existing or newly created class manager.

    N(RR
R?R@(RRB((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pytregister_class�scCstj|�dS(s!Unregister class instrumentation.N(R?Rg(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pytunregister_class�scCst|j�j|dt�S(s�Return True if the given attribute on the given instance is
    instrumented by the attributes package.

    This function may be used regardless of instrumentation
    applied directly to the class, i.e. no descriptors are required.

    Rx(RR�RyR[(R~R-((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyRy�scBs�|j}|st�d}ej|de�}||}ejrje|d|�}e|dd�}n$e|dd�}e|dd�}e�j	�}	||	U|	d}
|j
|
_
||
_|r�||
_nejr�|r�||
_
n|
S(	s>Build an __init__ decorator that triggers ClassManager events.s�def __init__(%(apply_pos)s):
    new_state = class_manager._new_state_if_none(%(self_arg)s)
    if new_state:
        return new_state._initialize_instance(%(apply_kw)s)
    else:
        return original__init__(%(apply_kw)s)
tgroupedtim_funct
func_defaultst__defaults__t__kwdefaults__R!N(R!R�Rtformat_argspec_initR�tpy2kRkR
tlocalstcopyR�t_sa_original_initR�R�(Rt
class_managertoriginal__init__t	func_bodyt	func_varst	func_texttfuncR�tfunc_kw_defaultstenvR!((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyREs(	
	
	N(R�tRRRRRRt!group_expirable_memoized_propertyRWtdictRR�R�R�R?tinstance_stateRRt
instance_dictRTRRPR�R�RyRE(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyt<module>s&�f")	


	
		

Zerion Mini Shell 1.0