ó ÃÌ4]c@s dZddlmZddlmZddlmZddlmZddlmZddlmZejƒZ d e fd „ƒYZ d e 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(t collections(texc(t interfaces(tstatei(tutilt ClassManagercBs6eZdZejZejZee j eƒƒZ d,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 |ƒqW|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_initt local_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_initR tinstall_member(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/instrumentation.pyR¹scCs&|jr"|jdƒd|_ndS(NR!(R tuninstall_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.pyt dict_getteræscCs|r||jkr9dSn||j|<|j||ƒtj|ƒ|||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(BRt __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€RR„RˆR‰RRŽ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|j j ||ƒ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  (RR‘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    (RR‘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ûsc Bsö|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.pyts& ÿf")