ÿØÿàJFIFÿþ ÿÛC       ÿÛC ÿÀÿÄÿÄ"#QrÿÄÿÄ&1!A"2qQaáÿÚ ?Øy,æ/3JæÝ¹È߲؋5êXw²±ÉyˆR”¾I0ó2—PI¾IÌÚiMö¯–þrìN&"KgX:Šíµ•nTJnLK„…@!‰-ý ùúmë;ºgµŒ&ó±hw’¯Õ@”Ü— 9ñ-ë.²1<yà‚¹ïQÐU„ہ?.’¦èûbß±©Ö«Âw*VŒ) `$‰bØÔŸ’ëXÖ-ËTÜíGÚ3ð«g Ÿ§¯—Jx„–’U/ÂÅv_s(Hÿ@TñJÑãõçn­‚!ÈgfbÓc­:él[ðQe 9ÀPLbÃãCµm[5¿ç'ªjglå‡Ûí_§Úõl-;"PkÞÞÁQâ¼_Ñ^¢SŸx?"¸¦ùY騐ÒOÈ q’`~~ÚtËU¹CڒêV  I1Áß_ÿÙ 4]c@@sdZddlmZddlZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZdZZZd)Zd e e ejfd$YZd!ejfd%YZd#efd&YZ de!fd'YZ"de!fd(YZ#dS(*sI Contains various base classes used throughout the ORM. Defines some key base classes prominent within the internals, as well as the now-deprecated ORM extension classes. Other than the deprecated extensions, this module and the classes within are mostly private, though some attributes are exposed when inspecting mappings. i(tabsolute_importNi(texc(t path_registry(t_MappedAttribute(t EXT_CONTINUE(tEXT_SKIP(tEXT_STOP(tInspectionAttr(tInspectionAttrInfo(t MANYTOMANY(t MANYTOONE(t NOT_EXTENSION(t ONETOMANYi(tinspect(tutil(t operatorstAttributeExtensionRRRR R R R tLoaderStrategytMapperExtensiont MapperOptiontMapperPropertytPropComparatortSessionExtensiontStrategizedPropertycB@seZdZdZeZeZdZdZ dZ ddd Z d Z d Zd Zd ZedZdZdZdZdZRS(sRepresent a particular class attribute mapped by :class:`.Mapper`. The most common occurrences of :class:`.MapperProperty` are the mapped :class:`.Column`, which is represented in a mapping as an instance of :class:`.ColumnProperty`, and a reference to another class produced by :func:`.relationship`, represented in the mapping as an instance of :class:`.RelationshipProperty`. t_configure_startedt_configure_finishedtparenttkeytinfocC@siS(sInfo dictionary associated with the object, allowing user-defined data to be associated with this :class:`.InspectionAttr`. The dictionary is generated when first accessed. Alternatively, it can be specified as a constructor argument to the :func:`.column_property`, :func:`.relationship`, or :func:`.composite` functions. .. versionchanged:: 1.0.0 :attr:`.MapperProperty.info` is also available on extension types via the :attr:`.InspectionAttrInfo.info` attribute, so that it can apply to a wider variety of ORM and extension constructs. .. seealso:: :attr:`.QueryableAttribute.info` :attr:`.SchemaItem.info` ((tself((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt_memoized_attr_infocscK@sdS(sCalled by Query for the purposes of constructing a SQL statement. Each MapperProperty associated with the target mapper processes the statement referenced by the query context, adding columns and/or criterion as appropriate. N((Rtcontextt query_entitytpathtadaptertkwargs((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pytsetupztcC@sdS(scProduce row processing functions and append to the given set of populators lists. N((RRR!tmappertresultR"t populators((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pytcreate_row_processorR%cC@s tdS(sIterate through instances related to the given instance for a particular 'cascade', starting with this MapperProperty. Return an iterator3-tuples (instance, mapper, state). Note that the 'cascade' collection on this MapperProperty is checked first for the given type before cascade_iterator is called. This method typically only applies to RelationshipProperty. ((titer(Rttype_tstatetvisited_instancesthalt_on((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pytcascade_iteratorscC@s ||_dS(sSet the parent mapper that references this MapperProperty. This method is overridden by some subclasses to perform extra setup when the mapper is first known. N(R(RRtinit((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt set_parentscC@sdS(sIHook called by the Mapper to the property to initiate instrumentation of the class attribute managed by this MapperProperty. The MapperProperty here will typically call out to the attributes module to set up an InstrumentedAttribute. This step is the first of two steps to set up an InstrumentedAttribute, and is called early in the mapper setup process. The second step is typically the init_class_attribute step, called from StrategizedProperty via the post_instrument_class() hook. This step assigns additional state to the InstrumentedAttribute (specifically the "impl") which has been determined after the MapperProperty has determined what kind of persistence management it needs to do (e.g. scalar, object, collection, etc). N((RR&((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pytinstrument_classR%cC@st|_t|_dS(N(tFalseRR(R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt__init__s cC@s t|_|jt|_dS(sCalled after all mappers are created to assemble relationships between mappers and perform other post-mapper-creation initialization steps. N(tTrueRtdo_initR(R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR0s  cC@st|jj|jS(sReturn the class-bound descriptor corresponding to this :class:`.MapperProperty`. This is basically a ``getattr()`` call:: return getattr(self.parent.class_, self.key) I.e. if this :class:`.MapperProperty` were named ``addresses``, and the class to which it is mapped is ``User``, this sequence is possible:: >>> from sqlalchemy import inspect >>> mapper = inspect(User) >>> addresses_property = mapper.attrs.addresses >>> addresses_property.class_attribute is User.addresses True >>> User.addresses.property is addresses_property True (tgetattrRtclass_R(R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pytclass_attributescC@sdS(sPerform subclass-specific initialization post-mapper-creation steps. This is a template method called by the ``MapperProperty`` object's init() method. N((R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR6R%cC@sdS(sPerform instrumentation adjustments that need to occur after init() has completed. The given Mapper is the Mapper invoking the operation, which may not be the same Mapper as self.parent in an inheritance scenario; however, Mapper will always at least be a sub-mapper of self.parent. This method is typically used by StrategizedProperty, which delegates it to LoaderStrategy.init_class_attribute() to perform final setup on the class-bound InstrumentedAttribute. N((RR&((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pytpost_instrument_classR%c C@sdS(soMerge the attribute represented by this ``MapperProperty`` from source to destination object. N(( Rtsessiont source_statet source_dictt dest_statet dest_dicttloadt _recursivet_resolve_conflict_map((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pytmergeR%cC@s)d|jjt|t|ddfS(Ns<%s at 0x%x; %s>Rsno key(t __class__t__name__tidR7(R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt__repr__ s  (RRRRRN(REt __module__t__doc__t __slots__t frozensettcascadeR5t is_propertyRR$R)tNoneR/R1R2R4R0tpropertyR9R6R:RCRG(((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR@s*         cB@seZdZdZddZdZdZdZd Z e d Z e d Z e d Z ed ZedZedZdZddZddZRS(sU Defines SQL operators for :class:`.MapperProperty` objects. SQLAlchemy allows for operators to be redefined at both the Core and ORM level. :class:`.PropComparator` is the base class of operator redefinition for ORM-level operations, including those of :class:`.ColumnProperty`, :class:`.RelationshipProperty`, and :class:`.CompositeProperty`. .. note:: With the advent of Hybrid properties introduced in SQLAlchemy 0.7, as well as Core-level operator redefinition in SQLAlchemy 0.8, the use case for user-defined :class:`.PropComparator` instances is extremely rare. See :ref:`hybrids_toplevel` as well as :ref:`types_operators`. User-defined subclasses of :class:`.PropComparator` may be created. The built-in Python comparison and math operator methods, such as :meth:`.operators.ColumnOperators.__eq__`, :meth:`.operators.ColumnOperators.__lt__`, and :meth:`.operators.ColumnOperators.__add__`, can be overridden to provide new operator behavior. The custom :class:`.PropComparator` is passed to the :class:`.MapperProperty` instance via the ``comparator_factory`` argument. In each case, the appropriate subclass of :class:`.PropComparator` should be used:: # definition of custom PropComparator subclasses from sqlalchemy.orm.properties import \ ColumnProperty,\ CompositeProperty,\ RelationshipProperty class MyColumnComparator(ColumnProperty.Comparator): def __eq__(self, other): return self.__clause_element__() == other class MyRelationshipComparator(RelationshipProperty.Comparator): def any(self, expression): "define the 'any' operation" # ... class MyCompositeComparator(CompositeProperty.Comparator): def __gt__(self, other): "redefine the 'greater than' operation" return sql.and_(*[a>b for a, b in zip(self.__clause_element__().clauses, other.__composite_values__())]) # application of custom PropComparator subclasses from sqlalchemy.orm import column_property, relationship, composite from sqlalchemy import Column, String class SomeMappedClass(Base): some_column = column_property(Column("some_column", String), comparator_factory=MyColumnComparator) some_relationship = relationship(SomeOtherClass, comparator_factory=MyRelationshipComparator) some_composite = composite( Column("a", String), Column("b", String), comparator_factory=MyCompositeComparator ) Note that for column-level operator redefinition, it's usually simpler to define the operators at the Core level, using the :attr:`.TypeEngine.comparator_factory` attribute. See :ref:`types_operators` for more detail. .. seealso:: :class:`.ColumnProperty.Comparator` :class:`.RelationshipProperty.Comparator` :class:`.CompositeProperty.Comparator` :class:`.ColumnOperators` :ref:`types_operators` :attr:`.TypeEngine.comparator_factory` tpropROt _parententityt_adapt_to_entitycC@s,||_|_|p||_||_dS(N(RPRORQRR(RRPt parentmappertadapt_to_entity((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR4kscC@std|dS(Ns%r(tNotImplementedError(R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt__clause_element__pscC@s |jS(N(RV(R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt_query_clause_elementsscC@s|j|fgS(N(RV(Rtvalue((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt_bulk_update_tuplesvscC@s|j|j|j|S(sReturn a copy of this PropComparator which will use the given :class:`.AliasedInsp` to produce corresponding expressions. (RDRPRQ(RRT((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRTyscC@st|jjS(sZlegacy; this is renamed to _parententity to be compatible with QueryableAttribute.(R RQR&(R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt _parentmapperscC@s!|jdkrdS|jjSdS(srProduce a callable that adapts column expressions to suit an aliased version of this comparator. N(RRRNt_adapt_element(R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR"scC@s |jjS(N(ROR(R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRscK@s|j||S(N(tany(tatbR#((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pytany_opscK@s|j||S(N(thas(R]R^R#((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pythas_opscC@s |j|S(N(tof_type(R]R8((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt of_type_opscC@s|jtj|S(sRedefine this object in terms of a polymorphic subclass. Returns a new PropComparator from which further criterion can be evaluated. e.g.:: query.join(Company.employees.of_type(Engineer)).\ filter(Engineer.name=='foo') :param \class_: a class or mapper indicating that criterion will be against this specific subclass. .. seealso:: :ref:`inheritance_of_type` (toperateRRc(RR8((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRbscK@s|jtj||S(sReturn true if this collection contains any member that meets the given criterion. The usual implementation of ``any()`` is :meth:`.RelationshipProperty.Comparator.any`. :param criterion: an optional ClauseElement formulated against the member class' table or attributes. :param \**kwargs: key/value pairs corresponding to member class attribute names which will be compared via equality to the corresponding values. (RdRR_(Rt criterionR#((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR\scK@s|jtj||S(sReturn true if this element references a member which meets the given criterion. The usual implementation of ``has()`` is :meth:`.RelationshipProperty.Comparator.has`. :param criterion: an optional ClauseElement formulated against the member class' table or attributes. :param \**kwargs: key/value pairs corresponding to member class attribute names which will be compared via equality to the corresponding values. (RdRRa(RReR#((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR`s(RPRORQRRN(RERHRIRJRNR4RVRWRYRTRORZR"Rt staticmethodR_RaRcRbR\R`(((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRs V        cB@seZdZdZdZdZdZdZdZ d Z d Z d Z d Z ejeZed ZedZRS(sA MapperProperty which uses selectable strategies to affect loading behavior. There is a single strategy selected by default. Alternate strategies can be selected at Query time through the usage of ``StrategizedOption`` objects via the Query.options() method. The mechanics of StrategizedProperty are used for every Query invocation for every mapped attribute participating in that Query, to determine first how the attribute will be rendered in SQL and secondly how the attribute will retrieve a value from a result row and apply it to a mapped object. The routines here are very performance-critical. t _strategieststrategyt_wildcard_tokent_default_path_loader_keycC@sd|jtjffS(Ns%s:%s(tstrategy_wildcard_keyRt_WILDCARD_TOKEN(R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt_memoized_attr__wildcard_tokenscC@sdd|jtjfffS(Ntloaders%s:%s(RkRt_DEFAULT_TOKEN(R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt'_memoized_attr__default_path_loader_keyscC@s_d}tj||}x@|j|j|jfD]&}||jkr1|j|}Pq1q1W|S(N(RNtdictt __getitem__t _loader_keyt_wildcard_path_loader_keyRjt attributes(RRR!R@t search_pathtpath_key((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt_get_context_loaders cC@s_y|j|SWnItk rZ|j||}||||j|<|j|<}|SXdS(N(RgtKeyErrort_strategy_lookup(RRtclsRh((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt _get_strategys "cK@s_|j||}|r6|jr6|j|j}n |j}|j||||||dS(N(RxRhR|t setup_query(RRR R!R"R#Rntstrat((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR$"s  c C@sb|j||}|r6|jr6|j|j}n |j}|j|||||||dS(N(RxRhR|R)( RRR!R&R'R"R(RnR~((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR),s  cC@s"i|_|j|j|_dS(N(RgR|t strategy_keyRh(R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR68s cC@s:|jj r6|jj|j r6|jj|ndS(N(Rt non_primaryt class_managert_attr_has_implRRhtinit_class_attribute(RR&((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR:<s c @sfd}|S(Nc@sXd|jkrg|_nttj}|j|<|jj||S(Nt_strategy_keys(t__dict__Rttupletsortedtitemst_all_strategiestappend(tdec_clsR(R{tkw(sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pytdecorateGs  ((R{RR((R{RsL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt strategy_forEs c G@sxP|jD]E}||jkr |j|}y ||SWqOtk rKqOXq q WxI|jjD],\}}||krc|}||}PqcqcWd}d}tj|||||dS(N(t__mro__RRyRRNtorm_exctLoaderStrategyException( R{trequesting_propertyRtprop_clst strategiest property_typetstratstintended_property_typetactual_strategy((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRzSs(      (RgRhRiRjN(RERHRIRJRNRkRmRpRxR|R$R)R6R:t collectionst defaultdictRqRt classmethodRRz(((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRs"    cB@s/eZdZeZdZdZdZRS(s#Describe a modification to a Query.cC@sdS(s2Apply a modification to the given :class:`.Query`.N((Rtquery((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt process_queryyR%cC@s|j|dS(slsame as process_query(), except that this option may not apply to the given query. This is typically used during a lazy load or scalar refresh operation to propagate options stated in the original Query to the new Query being used for the load. It occurs for those options that specify propagate_to_loaders=True. N(R(RR((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pytprocess_query_conditionally|s cC@stS(sg Used by the "baked lazy loader" to see if this option can be cached. The "baked lazy loader" refers to the :class:`.Query` that is produced during a lazy load operation for a mapped relationship. It does not yet apply to the "lazy" load operation for deferred or expired column attributes, however this may change in the future. This loader generates SQL for a query only once and attempts to cache it; from that point on, if the SQL has been cached it will no longer run the :meth:`.Query.options` method of the :class:`.Query`. The :class:`.MapperOption` object that wishes to participate within a lazy load operation therefore needs to tell the baked loader that it either needs to forego this caching, or that it needs to include the state of the :class:`.MapperOption` itself as part of its cache key, otherwise SQL or other query state that has been affected by the :class:`.MapperOption` may be cached in place of a query that does not include these modifications, or the option may not be invoked at all. By default, this method returns the value ``False``, which means the :class:`.BakedQuery` generated by the lazy loader will not cache the SQL when this :class:`.MapperOption` is present. This is the safest option and ensures both that the option is invoked every time, and also that the cache isn't filled up with an unlimited number of :class:`.Query` objects for an unlimited number of :class:`.MapperOption` objects. .. versionchanged:: 1.2.8 the default return value of :meth:`.MapperOption._generate_cache_key` is False; previously it was ``None`` indicating "safe to cache, don't include as part of the cache key" To enable caching of :class:`.Query` objects within lazy loaders, a given :class:`.MapperOption` that returns a cache key must return a key that uniquely identifies the complete state of this option, which will match any other :class:`.MapperOption` that itself retains the identical state. This includes path options, flags, etc. It should be a state that is repeatable and part of a limited set of possible options. If the :class:`.MapperOption` does not apply to the given path and would not affect query results on such a path, it should return None, indicating the :class:`.Query` is safe to cache for this given loader path and that this :class:`.MapperOption` need not be part of the cache key. (R3(RR!((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt_generate_cache_keys0(RERHRIR3tpropagate_to_loadersRRR(((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRos   cB@sAeZdZd ZdZdZd Zd Zd ZRS( sDescribe the loading behavior of a StrategizedProperty object. The ``LoaderStrategy`` interacts with the querying process in three ways: * it controls the configuration of the ``InstrumentedAttribute`` placed on a class to handle the behavior of the attribute. this may involve setting up class-level callable functions to fire off a select operation when the attribute is first accessed (i.e. a lazy load) * it processes the ``QueryContext`` at statement construction time, where it can modify the SQL statement that is being produced. For example, simple column attributes will add their represented column to the list of selected columns, a joined eager loader may establish join clauses to add to the statement. * It produces "row processor" functions at result fetching time. These "row processor" functions populate a particular attribute on a particular mapped instance. tparent_propertytis_class_levelRRRt strategy_optscC@sL||_t|_|jj|_|jj|_||_t||_dS(N(RR3RRRRRqR(RRR((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR4s    cC@sdS(N((RR&((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRscK@sdS(sEstablish column and other state for a given QueryContext. This method fulfills the contract specified by MapperProperty.setup(). StrategizedProperty delegates its setup() method directly to this method. N((RRR R!tloadoptR"R#((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR}R%cC@sdS(sEstablish row processing functions for a given QueryContext. This method fulfills the contract specified by MapperProperty.create_row_processor(). StrategizedProperty delegates its create_row_processor() method directly to this method. N((RRR!RR&R'R"R(((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR)R%cC@s t|jS(N(tstrR(R((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt__str__s(RRRRRR( RERHRIRJR4RR}R)R(((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRs   (RRRRR R R R RRRRRRR($RIt __future__RRR%RRRtbaseRRRRRRR R R R R RtsqlRRNRRRt__all__t MemoizedSlotsRtColumnOperatorsRRtobjectRR(((sL/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/interfaces.pytsL M