
H`Tc           @@  s0  d  Z  d d l m Z d d l m Z m Z m Z d d l m	 Z	 d d l
 m Z d d l m Z m Z m Z m Z m Z m Z d d	 l m Z m Z d d
 l m Z d d l
 Z
 d Z d e e f d     YZ d e	 j f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d S(    s   

Contains various base classes used throughout the ORM.

Defines the now deprecated ORM extension classes as well
as ORM internals.

Other than the deprecated extensions, this module and the
classes within should be considered mostly private.

i    (   t   absolute_importi   (   t   exct   utilt   inspect(   t	   operators(   t   dequei   (   t	   ONETOMANYt	   MANYTOONEt
   MANYTOMANYt   EXT_CONTINUEt   EXT_STOPt   NOT_EXTENSION(   t   _InspectionAttrt   _MappedAttribute(   t   PathRegistryNt   AttributeExtensionR	   R
   R   R   R   R   t   LoaderStrategyt   MapperExtensiont   MapperOptiont   MapperPropertyt   PropComparatort   SessionExtensiont   StrategizedPropertyc           B@  s   e  Z d  Z e   Z e Z d   Z d   Z d d d  Z
 d   Z d   Z e j d    Z e Z e Z d   Z e d    Z d	   Z d
   Z d   Z d   Z d   Z d   Z RS(   s[  Manage the relationship of a ``Mapper`` to a single class
    attribute, as well as that attribute as it appears on individual
    instances of the class, including attribute instrumentation,
    attribute access, loading behavior, and dependency calculations.

    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`.

    c         K@  s   d S(   s  Called 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(    (   t   selft   contextt   entityt   patht   adaptert   kwargs(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   setupJ   s    c         C@  s   d S(   sH   Return a 3-tuple consisting of three row processing functions.

        N(   NNN(   t   None(   R   R   R   t   mappert   rowR   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   create_row_processorT   s    c         C@  s
   t  d  S(   s  Iterate 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.

        See PropertyLoader for the related instance implementation.
        (    (   t   iter(   R   t   type_t   statet   visited_instancest   halt_on(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   cascade_iterator[   s    c         C@  s   | |  _  d  S(   N(   t   parent(   R   R(   t   init(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt
   set_parentj   s    c         C@  s   t     d  S(   N(   t   NotImplementedError(   R   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   instrument_classm   s    c         C@  s   i  S(   sO  Info dictionary associated with the object, allowing user-defined
        data to be associated with this :class:`.MapperProperty`.

        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.

        .. versionadded:: 0.8  Added support for .info to all
           :class:`.MapperProperty` subclasses.

        .. seealso::

            :attr:`.QueryableAttribute.info`

            :attr:`.SchemaItem.info`

        (    (   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   infop   s    c         C@  s    t  |  _ |  j   t  |  _ d S(   s   Called after all mappers are created to assemble
        relationships between mappers and perform other post-mapper-creation
        initialization steps.

        N(   t   Truet   _configure_startedt   do_initt   _configure_finished(   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR)      s    	
c         C@  s   t  |  j j |  j  S(   s  Return 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


        (   t   getattrR(   t   class_t   key(   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   class_attribute   s    c         C@  s   d S(   s   Perform subclass-specific initialization post-mapper-creation
        steps.

        This is a template method called by the ``MapperProperty``
        object's init() method.

        N(    (   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR0      s    	c         C@  s   d S(   sd   Perform instrumentation adjustments that need to occur
        after init() has completed.

        N(    (   R   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   post_instrument_class   s    c         C@  s   |  j  j S(   s-  Return True if this ``MapperProperty``'s mapper is the
        primary mapper for its class.

        This flag is used to indicate that the ``MapperProperty`` can
        define attribute instrumentation for the class at the class
        level (as opposed to the individual instance level).
        (   R(   t   non_primary(   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt
   is_primary   s    	c         C@  s   d S(   sd   Merge the attribute represented by this ``MapperProperty``
        from source to destination objectN(    (   R   t   sessiont   source_statet   source_dictt
   dest_statet	   dest_dictt   loadt
   _recursive(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   merge   s    c         K@  s   | |  j  |  S(   s{  Return a compare operation for the columns represented by
        this ``MapperProperty`` to the given value, which may be a
        column value or an instance.  'operator' is an operator from
        the operators module, or from sql.Comparator.

        By default uses the PropComparator attached to this MapperProperty
        under the attribute name "comparator".
        (   t
   comparator(   R   t   operatort   valuet   kw(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   compare   s    
c         C@  s)   d |  j  j t |   t |  d d  f S(   Ns   <%s at 0x%x; %s>R4   s   no key(   t	   __class__t   __name__t   idR2   (   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   __repr__   s    	N(   RG   t
   __module__t   __doc__t	   frozensett   cascadeR.   t   is_propertyR   R!   R   R'   R*   R,   R   t   memoized_propertyR-   t   FalseR/   R1   R)   t   propertyR5   R0   R6   R8   R@   RE   RI   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR   2   s(   		
				
					c           B@  s   e  Z d  Z d d  Z d   Z d   Z d   Z e d    Z	 e
 j d    Z e d    Z e d    Z e d	    Z d
   Z d d  Z d d  Z RS(   sY  Defines boolean, comparison, and other 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.

    See also:

    :class:`.ColumnProperty.Comparator`

    :class:`.RelationshipProperty.Comparator`

    :class:`.CompositeProperty.Comparator`

    :class:`.ColumnOperators`

    :ref:`types_operators`

    :attr:`.TypeEngine.comparator_factory`

    c         C@  s&   | |  _  |  _ | |  _ | |  _ d  S(   N(   t   propRQ   t   _parentmappert   _adapt_to_entity(   R   RR   t   parentmappert   adapt_to_entity(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   __init__<  s    	c         C@  s   t  d |    d  S(   Ns   %r(   R+   (   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   __clause_element__A  s    c         C@  s
   |  j    S(   N(   RX   (   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   _query_clause_elementD  s    c         C@  s   |  j  |  j |  j |  S(   s   Return a copy of this PropComparator which will use the given
        :class:`.AliasedInsp` to produce corresponding expressions.
        (   RF   RR   RS   (   R   RV   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRV   G  s    c         C@  s!   |  j  d k r d S|  j  j Sd S(   sr   Produce a callable that adapts column expressions
        to suit an aliased version of this comparator.

        N(   RT   R   t   _adapt_element(   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR   M  s    c         C@  s
   |  j  j S(   N(   RQ   R-   (   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR-   X  s    c         K@  s   |  j  | |  S(   N(   t   any(   t   at   bR   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   any_op\  s    c         K@  s   |  j  | |  S(   N(   t   has(   R\   R]   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   has_op`  s    c         C@  s   |  j  |  S(   N(   t   of_type(   R\   R3   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt
   of_type_opd  s    c         C@  s   |  j  t j |  S(   s  Redefine 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.


        (   t   operateR   Rb   (   R   R3   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRa   h  s    c         K@  s   |  j  t j | |  S(   s  Return 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.

        (   Rc   R   R^   (   R   t	   criterionR   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR[   {  s    c         K@  s   |  j  t j | |  S(   s  Return 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.

        (   Rc   R   R`   (   R   Rd   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR_     s    N(   RG   RJ   RK   R   RW   RX   RY   RV   RQ   R   R   RO   R-   t   staticmethodR^   R`   Rb   Ra   R[   R_   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR      s   W				c           B@  s   e  Z d  Z d
 Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z e j e  Z e d    Z e d	    Z RS(   s  A 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.

    c         C@  s_   d  } t j | |   } x@ | j | j | j f D]& } | | j k r1 | j | } Pq1 q1 W| S(   N(   R   t   dictt   __getitem__t   _loader_keyt   _wildcard_path_loader_keyt   _default_path_loader_keyt
   attributes(   R   R   R   R>   t   search_patht   path_key(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   _get_context_loader  s    c         C@  sY   y |  j  | SWnC t k
 rT |  j |   } | |   |  j  | <|  j  | <} | SXd  S(   N(   t   _strategiest   KeyErrort   _strategy_lookup(   R   R4   t   clst   strategy(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   _get_strategy  s    "c         C@  s   |  j  | j d  S(   Ni    (   Rt   t   _strategy_keys(   R   Rr   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   _get_strategy_by_cls  s    c         K@  s_   |  j  | |  } | r6 | j r6 |  j | j  } n	 |  j } | j | | | | | |  d  S(   N(   Rn   Rs   Rt   t   setup_query(   R   R   R   R   R   R   t   loadert   strat(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR     s
    	c         C@  s[   |  j  | |  } | r6 | j r6 |  j | j  } n	 |  j } | j | | | | | |  S(   N(   Rn   Rs   Rt   R!   (   R   R   R   R   R    R   Rx   Ry   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR!     s    	c         C@  s"   i  |  _  |  j |  j  |  _ d  S(   N(   Ro   Rv   t   strategy_classRs   (   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR0     s    	c         C@  s9   |  j    r5 | j j |  j  r5 |  j j |  n  d  S(   N(   R8   t   class_managert   _attr_has_implR4   Rs   t   init_class_attribute(   R   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR6     s    c         @  s      f d   } | S(   Nc         @  sF   g  |  _  t t   j     } |   j  | <|  j  j |  |  S(   N(   Ru   t   tuplet   sortedt   itemsRo   t   append(   t   dec_clsR4   (   RD   Rr   (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   decorate  s
    	(    (   Rr   RD   R   (    (   RD   Rr   s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   strategy_for  s    c         G@  sm   xP |  j  D]E } | |  j k r
 |  j | } y | | SWqO t k
 rK qO Xq
 q
 Wt d |  | f   d  S(   Ns   can't locate strategy for %s %s(   t   __mro__Ro   Rp   t	   Exception(   Rr   R4   t   prop_clst
   strategies(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRq     s    N(   RG   RJ   RK   R   t   strategy_wildcard_keyRn   Rt   Rv   R   R!   R0   R6   t   collectionst   defaultdictRf   Ro   t   classmethodR   Rq   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR     s   									
c           B@  s&   e  Z d  Z e Z d   Z d   Z RS(   s#   Describe a modification to a Query.c         C@  s   d  S(   N(    (   R   t   query(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   process_query  s    c         C@  s   |  j  |  d S(   s   same as process_query(), except that this option may not
        apply to the given query.

        Used when secondary loaders resend existing options to a new
        Query.N(   R   (   R   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   process_query_conditionally	  s    (   RG   RJ   RK   RP   t   propagate_to_loadersR   R   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR     s   	c           B@  s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s  Describe 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.
      Simple column attributes may add their represented column to the
      list of selected columns, *eager loading* properties may add
      ``LEFT OUTER JOIN`` clauses 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.

    c         C@  s4   | |  _  t |  _ |  j  j |  _ |  j  j |  _ d  S(   N(   t   parent_propertyRP   t   is_class_levelR(   R4   (   R   R(   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRW   +  s    		c         C@  s   d  S(   N(    (   R   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR}   1  s    c         K@  s   d  S(   N(    (   R   R   R   R   t   loadoptR   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyRw   4  s    c         C@  s   d S(   s   Return row processing functions which fulfill the contract
        specified by MapperProperty.create_row_processor.

        StrategizedProperty delegates its create_row_processor method
        directly to this method. N(   NNN(   R   (   R   R   R   R   R   R    R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR!   7  s    c         C@  s   t  |  j  S(   N(   t   strR   (   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   __str__A  s    (   RG   RJ   RK   RW   R}   Rw   R!   R   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyR     s   				
(   R   s   EXT_CONTINUEs   EXT_STOPs	   ONETOMANYs
   MANYTOMANYs	   MANYTOONEs   NOT_EXTENSIONs   LoaderStrategyR   s   MapperOptions   MapperPropertys   PropComparatorR   s   StrategizedProperty(   RK   t
   __future__R    t    R   t   sa_excR   R   t   sqlR   R   R   t   baseR   R   R   R	   R
   R   R   R   t   path_registryR   t   __all__R   t   ColumnOperatorsR   R   t   objectR   R   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.pyt   <module>   s6   .             ^