
H`Tc           @   s.  d  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 m Z m Z m Z d d l m Z d d l m Z m Z m Z m Z m Z d d	 l m Z m Z m Z m Z m Z m 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 d g Z' e j( Z) e j* e j+ d e, f d     Y  Z- d d l. m/ Z/ d e/ f d     YZ0 d e, f d     YZ1 d e1 f d     YZ2 e j* d e, f d     Y Z3 d e1 f d     YZ4 d e1 f d     YZ5 d e, f d     YZ6 d  e j7 f d!     YZ8 d" S(#   s  The Query class and support.

Defines the :class:`.Query` class, the central
construct used by the ORM to construct database queries.

The :class:`.Query` class should not be confused with the
:class:`.Select` class, which defines database
SELECT operations at the SQL (non-ORM) level.  ``Query`` differs from
``Select`` in that it returns ORM-mapped objects and interacts with an
ORM session, whereas the ``Select`` construct interacts directly with the
database to return iterable result sets.

i(   t   chaini   (   t
   attributest
   interfacest   object_mappert   persistencet   exct   loading(   t   _entity_descriptort   _is_aliased_classt   _is_mapped_classt   _orm_columnst   _generative(   t   PathRegistry(   t   AliasedClasst
   ORMAdaptert   joint   with_parentt   aliasedi   (   t   sqlt   utilt   logR   t   inspectt
   inspection(   t   _interpret_as_from(   R   t
   expressiont   visitors(   t   ColumnCollection(   t
   propertiest   Queryt   QueryContextR   c           B   sJ  e  Z d  Z e Z e Z e Z d{ Z	 d{ Z
 e Z e Z d{ Z e Z d{ Z d{ Z d{ Z d{ Z d{ Z e   Z e Z e Z e Z e Z d{ Z d{ Z d| Z d} Z d{ Z i  Z d{ Z  d{ Z! e" j#   Z$ Z% e" j#   Z& e" j#   Z' e" j#   Z( d~ Z) d Z* e Z+ e, Z- d{ d  Z. d{ d  Z/ d   Z0 d   Z1 d   Z2 d   Z3 d   Z4 d   Z5 e6   d	    Z7 d
   Z8 d   Z9 d   Z: e; d    Z< d   Z= d   Z> d{ d  Z? d   Z@ d{ d  ZA d   ZB d   ZC d   ZD e e d  ZE e e d  ZF d   ZG d   ZH d   ZI d   ZJ d{ d{ d{ d{ d  ZK d   ZL e; d    ZM d{ e e d  ZN d{ e d   ZO d!   ZP d"   ZQ e; d#    ZR d$   ZS e6   d%    ZT e6   d&    ZU e6   d'    ZV e; d(    ZW e6   d)    ZX e6 eG  d{ d{ d*   ZY e6   d+    ZZ d,   Z[ e6   d-    Z\ e6   d.    Z] e6   d/    Z^ e6   d0    Z_ d{ d1  Z` e6   d{ d2   Za e6   d3    Zb d4   Zc e6   d5    Zd e6   d6    Ze d7   Zf ef Zg d8   Zh e6   d9    Zi e6   d:    Zj e" jk d; d< e  d=    Zl d>   Zm d?   Zn e6   d@    Zo dA   Zp e6   dB dC   Zq e6   dD    Zr e6   dE    Zs e6   e e d{ dF   Zt e6   dG    Zu e6 eH eI  dH    Zv dI   Zw e6 eH eI  dJ    Zx e6 eH eI  dK    Zy e6 eH eI  dL    Zz dM   Z{ dN   Z| dO   Z} dP   Z~ dQ   Z dR   Z dS   Z dT   Z dU   Z e6 eH eI  dV    Z dW   Z dX   Z dY   Z dZ   Z e6 eH  d[    Z e6 eG  d\    Z e6 eG  d]    Z d^   Z e6 eH  d_    Z e6 eH  d`    Z e6 eH  da    Z e6 eH  db    Z e6   dc    Z dd   Z e6 eG  de    Z df   Z dg   Z dh   Z di   Z dj   Z dk   Z e; dl    Z d{ dm  Z e dn  Z e; do    Z e; dp    Z dq   Z dr   Z ds dt  Z ds du  Z e dv  Z dw   Z dx   Z dy   Z dz   Z RS(   s  ORM-level SQL construction object.

    :class:`.Query` is the source of all SELECT statements generated by the
    ORM, both those formulated by end-user query operations as well as by
    high level internal operations such as related collection loading.  It
    features a generative interface whereby successive calls return a new
    :class:`.Query` object, a copy of the former with additional
    criteria and options associated with it.

    :class:`.Query` objects are normally initially generated using the
    :meth:`~.Session.query` method of :class:`.Session`.  For a full
    walkthrough of :class:`.Query` usage, see the
    :ref:`ormtutorial_toplevel`.

    c         C   s#   | |  _  i  |  _ |  j |  d  S(   N(   t   sessiont   _polymorphic_adapterst   _set_entities(   t   selft   entitiesR   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   __init__i   s    		c         C   sb   | d  k r t } n  g  |  _ d  |  _ x$ t j |  D] } | |  |  q7 W|  j |  j  d  S(   N(   t   Nonet   _QueryEntityt	   _entitiest   _primary_entityR   t   to_listt   _set_entity_selectables(   R!   R"   t   entity_wrappert   ent(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    n   s    			c         C   s  |  j  j   |  _  } x | D] } x | j D] } | | k r t |  } | j r | j j r | j j |  j k r |  j	 | j t
 j | j | j j   n  d  } n- | j r t
 j | j | j j  } n d  } | | f | | <n  | j | |   q- Wq Wd  S(   N(   t   _mapper_adapter_mapt   copyR"   R   t   is_aliased_classt   mappert   with_polymorphict   mapped_tableR   t"   _mapper_loads_polymorphically_witht   sql_utilt   ColumnAdaptert
   selectablet   _equivalent_columnsR$   t   setup_entity(   R!   R"   t   dR+   t   entityt   ext_infot   aliased_adapter(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR)   x   s.    
			c         C   sU   xN | j  p | g D]: } | |  j | <x$ | j   D] } | |  j | j <q3 Wq Wd  S(   N(   t   _with_polymorphic_mappersR   t   iterate_to_roott   local_table(   R!   R/   t   adaptert   m2t   m(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR2      s    c         C   sA  g  } d  } x | D] } t |  } t | d  rz | j sF | j rz | |  _ | rg t j d   n  | j | j	  q | j
 s t j d   q t | t j  r | j   } n  | r | } n  | j |  q Wt |  |  _ | r=t |  j  d k r=t | t j  r=|  j   } t j |  j d |  |  _ n  d  S(   NR/   sP   A selectable (FromClause) instance is expected when the base alias is being set.sJ   argument is not a mapped class, mapper, aliased(), or FromClause instance.i   i    (   R$   R   t   hasattrt	   is_mapperR.   t   _select_from_entityt   sa_exct   ArgumentErrort   appendR5   t   is_selectablet
   isinstanceR   t
   SelectBaset   aliast   tuplet	   _from_objt   lent   Aliast   _Query__all_equivsR3   R4   t   _from_obj_alias(   R!   t   objt   set_base_aliast   fat   select_from_aliast   from_objt   infot   equivs(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _set_select_from   s4    			c         C   sX   xQ | j  D]F } |  j j | d   x* | j   D] } |  j j | j d   q0 Wq
 Wd  S(   N(   R<   R   t   popR$   R=   R>   (   R!   R/   R@   RA   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _reset_polymorphic_adapter   s    c         C   s   d | j  k rG | j  d } |  j j | d   } | rG | j |  Sn  t | t j  rb | } n t | d  r} | j	 } n d  S|  j j | d   } | r | j |  Sd  S(   Nt   parententityt   table(
   t   _annotationsR   t   getR$   t   adapt_clauseRI   R   t
   FromClauseRB   R]   (   R!   t   elementt   searchRK   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _adapt_polymorphic_element   s    	c         C   s/   g  | D]$ } |  j  t j |  t t  ^ q S(   N(   t   _adapt_clauseR   t   _literal_as_textt   True(   R!   t   colst   o(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _adapt_col_list   s    c         C   s   t  |  _ d  S(   N(   t   Falset   _orm_only_adapt(   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _adapt_all_clauses   s    c            s   g    t  |  d |  } | rW |  j rW x- |  j j D] }   j | | j f  q4 Wn  |  j r   j t  |  d |  |  j j f  n  |  j r   j | |  j f  n    s | S  f d   } t j	 | i  |  S(   s\   Adapt incoming clauses to transformations which
        have been applied within this query.Rl   t   _orm_only_from_obj_aliasc            s_   xX   D]P \ } } | s8 d |  j  k s8 d |  j  k r | |   } | d  k	 rW | Sq q Wd  S(   Nt
   _orm_adaptR\   (   R^   R$   (   t   elemt	   _orm_onlyR?   t   e(   t   adapters(    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   replace  s    (
   t   getattrt   _filter_aliasest   _visitor_iteratorRG   Rt   RQ   R   Rd   R   t   replacement_traverse(   R!   t   clauset	   as_filtert   orm_onlyRT   Rt   (    (   Rs   sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyRe      s(    		c         C   s   |  j  d S(   Ni    (   R&   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _entity_zero  s    c         C   s   |  j  p |  j   j S(   N(   RD   R|   t   entity_zero(   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _mapper_zero"  s    	c         c   s/   x( |  j  D] } t | t  r
 | Vq
 q
 Wd  S(   N(   R&   RI   t   _MapperEntity(   R!   R+   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _mapper_entities&  s    c         C   s   |  j  j d |  j    S(   Nt   _joinpoint_entity(   t
   _joinpointR_   R~   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _joinpoint_zero,  s    	c         C   s   |  j  r |  j  j Sd  Sd  S(   N(   R'   R/   R$   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _mapper_zero_or_none2  s    	
c         C   s7   t  |  j  d k r- t j | p$ d   n  |  j   S(   Ni   s8   This operation requires a Query against a single mapper.(   RN   R&   RE   t   InvalidRequestErrorR~   (   R!   t	   rationale(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _only_mapper_zero8  s
    c         C   s5   |  j  |  j g k r+ t j d |   n  |  j j S(   Ns4   %s() can only be used against a single mapped class.(   R&   R'   RE   R   R}   (   R!   t   methname(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _only_full_mapper_zeroA  s
    c         C   s7   t  |  j  d k r- t j | p$ d   n  |  j   S(   Ni   s8   This operation requires a Query against a single mapper.(   RN   R&   RE   R   R|   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _only_entity_zeroH  s
    c         C   s1   i  } x$ |  j  D] } | j | j j  q W| S(   N(   R   t   updateR/   R6   (   R!   RX   R+   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   __all_equivsQ  s    c         C   s   |  j  d d t d t S(   NR_   t   order_byt   distinct(   t   _no_criterion_conditionRk   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _get_conditionW  s    c         C   s   |  j  d d t d t d  S(   NR_   R   R   (   t   _no_criterion_assertionRk   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _get_existing_condition[  s    c         C   s   |  j  s d  S|  j d  k	 sy |  j d  k	 sy |  j sy |  j d  k	 sy |  j d  k	 sy |  j sy | rj |  j sy | r |  j	 r t
 j d |   n  d  S(   Ns<   Query.%s() being called on a Query with existing criterion. (   t   _enable_assertionst
   _criterionR$   t
   _statementRM   t   _limitt   _offsett	   _group_byt	   _order_byt	   _distinctRE   R   (   R!   t   methR   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   ^  s    	c         C   sG   |  j  | | |  d |  _ d  |  _ |  _ t |  _ |  _ |  _ d  S(   N(    (	   R   RM   R$   R   R   Rk   R   R   R   (   R!   R   R   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   j  s    	c         C   s=   |  j  s d  S|  j r, t j d |   n  |  j |  d  S(   Ns<   Query.%s() being called on a Query with existing criterion. (   R   R   RE   R   R   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _no_clauseelement_conditionq  s    		c         C   s6   |  j  s d  S|  j d  k	 r2 t j d |   n  d  S(   Ns[   Query.%s() being called on a Query with an existing full statement - can't apply criterion.(   R   R   R$   RE   R   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _no_statement_conditionz  s    	c         C   sK   |  j  s d  S|  j d  k	 s+ |  j d  k	 rG t j d | | f   n  d  S(   Ns   Query.%s() being called on a Query which already has LIMIT or OFFSET applied. To modify the row-limited results of a  Query, call from_self() first.  Otherwise, call %s() before limit() or offset() are applied.(   R   R   R$   R   RE   R   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _no_limit_offset  s    	c         C   s   |  j  s d  Sxr d d d d t f d d t f d	 d
 t f f D]@ \ } } } t |  |  | k	 r> t j d | | f   q> q> Wd  S(   NR   s   limit()R   s   offset()R   s
   order_by()R   s
   group_by()R   s
   distinct()s-   Can't call Query.%s() when %s has been called(   s   _limits   limit()N(   s   _offsets   offset()N(   R   R$   Rk   Ru   RE   R   (   R!   R   t   attrR   t   notset(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _no_select_modifiers  s    	c         C   sR   | r | |  _  n  | r$ | |  _ n  | r6 | |  _ n  | rN t |  |  _ n  |  S(   N(   t   _populate_existingt   _version_checkt   _refresh_statet   sett   _only_load_props(   R!   t   populate_existingt   version_checkt   only_load_propst   refresh_state(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _get_options  s    c         C   s.   |  j  } | j |  } |  j j   | _ | S(   N(   t	   __class__t   __new__t   __dict__R-   (   R!   t   clst   q(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _clone  s    	c         C   sJ   |  j  d |  j  j } |  j r6 | j |  j  } n  | j i t d 6 S(   s   The full SELECT statement represented by this Query.

        The statement by default will not have disambiguating labels
        applied to the construct unless with_labels(True) is called
        first.

        t   labelst   no_replacement_traverse(   t   _compile_contextt   _with_labelst	   statementt   _paramst   paramst	   _annotateRg   (   R!   t   stmt(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    
	c         C   sR   |  j  t  } | r$ | j   } n  | j } | rB | j   } n  | j d |  S(   s  return the full SELECT statement represented by
        this :class:`.Query`, embedded within an :class:`.Alias`.

        Eager JOIN generation within the query is disabled.

        :param name: string name to be assigned as the alias;
            this is passed through to :meth:`.FromClause.alias`.
            If ``None``, a name will be deterministically generated
            at compile time.

        :param with_labels: if True, :meth:`.with_labels` will be called
         on the :class:`.Query` first to apply table-qualified labels
         to all columns.

        :param reduce_columns: if True, :meth:`.Select.reduce_columns` will
         be called on the resulting :func:`.select` construct,
         to remove same-named columns where one also refers to the other
         via foreign key or WHERE clause equivalence.

         .. versionchanged:: 0.8 the ``with_labels`` and ``reduce_columns``
            keyword arguments were added.

        t   name(   t   enable_eagerloadsRk   t   with_labelsR   t   reduce_columnsRK   (   R!   R   R   R   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   subquery  s    	c         C   s"   |  j  t  j j d | d |  S(   sO  Return the full SELECT statement represented by this
        :class:`.Query` represented as a common table expression (CTE).

        .. versionadded:: 0.7.6

        Parameters and usage are the same as those of the
        :meth:`.SelectBase.cte` method; see that method for
        further details.

        Here is the `Postgresql WITH
        RECURSIVE example
        <http://www.postgresql.org/docs/8.4/static/queries-with.html>`_.
        Note that, in this example, the ``included_parts`` cte and the
        ``incl_alias`` alias of it are Core selectables, which
        means the columns are accessed via the ``.c.`` attribute.  The
        ``parts_alias`` object is an :func:`.orm.aliased` instance of the
        ``Part`` entity, so column-mapped attributes are available
        directly::

            from sqlalchemy.orm import aliased

            class Part(Base):
                __tablename__ = 'part'
                part = Column(String, primary_key=True)
                sub_part = Column(String, primary_key=True)
                quantity = Column(Integer)

            included_parts = session.query(
                            Part.sub_part,
                            Part.part,
                            Part.quantity).\
                                filter(Part.part=="our part").\
                                cte(name="included_parts", recursive=True)

            incl_alias = aliased(included_parts, name="pr")
            parts_alias = aliased(Part, name="p")
            included_parts = included_parts.union_all(
                session.query(
                    parts_alias.sub_part,
                    parts_alias.part,
                    parts_alias.quantity).\
                        filter(parts_alias.part==incl_alias.c.sub_part)
                )

            q = session.query(
                    included_parts.c.sub_part,
                    func.sum(included_parts.c.quantity).
                        label('total_quantity')
                ).\
                group_by(included_parts.c.sub_part)

        .. seealso::

            :meth:`.SelectBase.cte`

        R   t	   recursive(   R   Rk   R   t   cte(   R!   R   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    9c         C   s   |  j  t  j j |  S(   s	  Return the full SELECT statement represented by this
        :class:`.Query`, converted
        to a scalar subquery with a label of the given name.

        Analogous to :meth:`sqlalchemy.sql.expression.SelectBase.label`.

        .. versionadded:: 0.6.5

        (   R   Rk   R   t   label(   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   "  s    c         C   s   |  j  t  j j   S(   s   Return the full SELECT statement represented by this
        :class:`.Query`, converted to a scalar subquery.

        Analogous to :meth:`sqlalchemy.sql.expression.SelectBase.as_scalar`.

        .. versionadded:: 0.6.5

        (   R   Rk   R   t	   as_scalar(   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   /  s    
c         C   s
   |  j    S(   s   Return the :class:`.Select` object emitted by this :class:`.Query`.

        Used for :func:`.inspect` compatibility, this is equivalent to::

            query.enable_eagerloads(False).with_labels().statement

        (   t   __clause_element__(   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR5   ;  s    	c         C   s   |  j  t  j   j S(   N(   R   Rk   R   R   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   F  s    c         C   s   | |  _  d S(   s  Control whether or not eager joins and subqueries are
        rendered.

        When set to False, the returned Query will not render
        eager joins regardless of :func:`~sqlalchemy.orm.joinedload`,
        :func:`~sqlalchemy.orm.subqueryload` options
        or mapper-level ``lazy='joined'``/``lazy='subquery'``
        configurations.

        This is used primarily when nesting the Query's
        statement into a subquery or other
        selectable.

        N(   t   _enable_eagerloads(   R!   t   value(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   I  s    c         C   s   t  |  _ d S(   s  Apply column labels to the return value of Query.statement.

        Indicates that this Query's `statement` accessor should return
        a SELECT statement that applies labels to all columns in the
        form <tablename>_<columnname>; this is commonly used to
        disambiguate columns from multiple tables which have the same
        name.

        When the `Query` actually issues SQL to load rows, it always
        uses column labeling.

        N(   Rg   R   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   [  s    c         C   s   | |  _  d S(   s  Control whether assertions are generated.

        When set to False, the returned Query will
        not assert its state before certain operations,
        including that LIMIT/OFFSET has not been applied
        when filter() is called, no criterion exists
        when get() is called, and no "from_statement()"
        exists when filter()/order_by()/group_by() etc.
        is called.  This more permissive mode is used by
        custom Query subclasses to specify criterion or
        other modifiers outside of the usual usage patterns.

        Care should be taken to ensure that the usage
        pattern is even possible.  A statement applied
        by from_statement() will override any criterion
        set by filter() or order_by(), for example.

        N(   R   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   enable_assertionsk  s    c         C   s   |  j  S(   s   A readonly attribute which returns the current WHERE criterion for
        this Query.

        This returned value is a SQL expression construct, or ``None`` if no
        criterion has been established.

        (   R   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   whereclause  s    	c         C   s   | |  _  d S(   s  indicate that this query applies to objects loaded
        within a certain path.

        Used by deferred loaders (see strategies.py) which transfer
        query options from an originating query to a newly generated
        query intended for the deferred load.

        N(   t   _current_path(   R!   t   path(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _with_current_path  s    
c         C   se   |  j  s t j d   n  |  j d j   } | g |  j d |  _ | j |  | d | d | d S(   sp  Load columns for inheriting classes.

        :meth:`.Query.with_polymorphic` applies transformations
        to the "main" mapped class represented by this :class:`.Query`.
        The "main" mapped class here means the :class:`.Query`
        object's first argument is a full class, i.e.
        ``session.query(SomeClass)``. These transformations allow additional
        tables to be present in the FROM clause so that columns for a
        joined-inheritance subclass are available in the query, both for the
        purposes of load-time efficiency as well as the ability to use
        these columns at query time.

        See the documentation section :ref:`with_polymorphic` for
        details on how this method is used.

        .. versionchanged:: 0.8
            A new and more flexible function
            :func:`.orm.with_polymorphic` supersedes
            :meth:`.Query.with_polymorphic`, as it can apply the equivalent
            functionality to any set of columns or classes in the
            :class:`.Query`, not just the "zero mapper".  See that
            function for a description of arguments.

        s(   No primary mapper set up for this Query.i    i   R5   t   polymorphic_onN(   R'   RE   R   R&   R   t   set_with_polymorphic(   R!   t   cls_or_mappersR5   R   R9   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR0     s    		c         C   s)   | |  _  |  j j i t d 6 |  _ d S(   sM  Yield only ``count`` rows at a time.

        The purpose of this method is when fetching very large result sets
        (> 10K rows), to batch results in sub-collections and yield them
        out partially, so that the Python interpreter doesn't need to declare
        very large areas of memory which is both time consuming and leads
        to excessive memory use.   The performance from fetching hundreds of
        thousands of rows can often double when a suitable yield-per setting
        (e.g. approximately 1000) is used, even with DBAPIs that buffer
        rows (which are most).

        The :meth:`.yield_per` method **is not compatible with most
        eager loading schemes, including joinedload and subqueryload**.
        See the warning below.

        .. warning::

            Use this method with caution; if the same instance is
            present in more than one batch of rows, end-user changes
            to attributes will be overwritten.

            In particular, it's usually impossible to use this setting
            with eagerly loaded collections (i.e. any lazy='joined' or
            'subquery') since those collections will be cleared for a
            new load when encountered in a subsequent result batch.
            In the case of 'subquery' loading, the full result for all
            rows is fetched which generally defeats the purpose of
            :meth:`~sqlalchemy.orm.query.Query.yield_per`.

            Also note that while
            :meth:`~sqlalchemy.orm.query.Query.yield_per` will set the
            ``stream_results`` execution option to True, currently
            this is only understood by
            :mod:`~sqlalchemy.dialects.postgresql.psycopg2` dialect
            which will stream results using server side cursors
            instead of pre-buffer all rows for this query. Other
            DBAPIs **pre-buffer all rows** before making them
            available.  The memory use of raw database rows is much less
            than that of an ORM-mapped object, but should still be taken into
            consideration when benchmarking.

        t   stream_resultsN(   t
   _yield_pert   _execution_optionst   unionRg   (   R!   t   count(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt	   yield_per  s    ,		c         C   s  t  | d  r | j   } n  t j |  } |  j d  } t |  t | j  k r t j d d j	 d   | j D    n  | j
 |  } |  j r| j r|  j d k rt j |  j | t j  } | d k	 r|  j   t | j | j  s d S| Sn  t j |  |  S(   s	  Return an instance based on the given primary key identifier,
        or ``None`` if not found.

        E.g.::

            my_user = session.query(User).get(5)

            some_object = session.query(VersionedFoo).get((5, 10))

        :meth:`~.Query.get` is special in that it provides direct
        access to the identity map of the owning :class:`.Session`.
        If the given primary key identifier is present
        in the local identity map, the object is returned
        directly from this collection and no SQL is emitted,
        unless the object has been marked fully expired.
        If not present,
        a SELECT is performed in order to locate the object.

        :meth:`~.Query.get` also will perform a check if
        the object is present in the identity map and
        marked as expired - a SELECT
        is emitted to refresh the object as well as to
        ensure that the row is still present.
        If not, :class:`~sqlalchemy.orm.exc.ObjectDeletedError` is raised.

        :meth:`~.Query.get` is only used to return a single
        mapped instance, not multiple instances or
        individual column constructs, and strictly
        on a single primary key value.  The originating
        :class:`.Query` must be constructed in this way,
        i.e. against a single mapped entity,
        with no additional filtering criterion.  Loading
        options via :meth:`~.Query.options` may be applied
        however, and will be used if the object is not
        yet locally present.

        A lazy-loading, many-to-one attribute configured
        by :func:`.relationship`, using a simple
        foreign-key-to-primary-key criterion, will also use an
        operation equivalent to :meth:`~.Query.get` in order to retrieve
        the target value from the local identity map
        before querying the database.  See :doc:`/orm/loading`
        for further details on relationship loading.

        :param ident: A scalar or tuple value representing
         the primary key.   For a composite primary key,
         the order of identifiers corresponds in most cases
         to that of the mapped :class:`.Table` object's
         primary key columns.  For a :func:`.mapper` that
         was given the ``primary key`` argument during
         construction, the order of identifiers corresponds
         to the elements present in this collection.

        :return: The object instance, or ``None``.

        t   __composite_values__R_   sm   Incorrect number of values in identifier to formulate primary key for query.get(); primary key columns are %st   ,c         s   s   |  ] } d  | Vq d S(   s   '%s'N(    (   t   .0t   c(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pys	   <genexpr>6  s    N(   RB   R   R   R(   R   RN   t   primary_keyRE   R   R   t   identity_key_from_primary_keyR   t   always_refresht   _for_update_argR$   R   t   get_from_identityR   R   t   PASSIVE_OFFR   t
   issubclassR   t   class_t   load_on_ident(   R!   t   identR/   t   keyt   instance(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR_     s(    ;#


c         G   s#   |  j  j d   | D  |  _  d S(   s#  Return a :class:`.Query` construct which will correlate the given
        FROM clauses to that of an enclosing :class:`.Query` or
        :func:`~.expression.select`.

        The method here accepts mapped classes, :func:`.aliased` constructs,
        and :func:`.mapper` constructs as arguments, which are resolved into
        expression constructs, in addition to appropriate expression
        constructs.

        The correlation arguments are ultimately passed to
        :meth:`.Select.correlate` after coercion to expression constructs.

        The correlation arguments take effect in such cases
        as when :meth:`.Query.from_self` is used, or when
        a subquery as returned by :meth:`.Query.subquery` is
        embedded in another :func:`~.expression.select` construct.

         c         s   s-   |  ]# } | d  k	 r! t |  n d  Vq d  S(   N(   R$   R   (   R   t   s(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pys	   <genexpr>`  s   N(   t
   _correlateR   (   R!   t   args(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt	   correlateJ  s    	c         C   s   | |  _  d S(   s%  Return a Query with a specific 'autoflush' setting.

        Note that a Session with autoflush=False will
        not autoflush, even if this flag is set to True at the
        Query level.  Therefore this flag is usually used only
        to disable autoflush for a specific Query.

        N(   t
   _autoflush(   R!   t   setting(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt	   autoflushd  s    
c         C   s   t  |  _ d S(   s  Return a :class:`.Query` that will expire and refresh all instances
        as they are loaded, or reused from the current :class:`.Session`.

        :meth:`.populate_existing` does not improve behavior when
        the ORM is used normally - the :class:`.Session` object's usual
        behavior of maintaining a transaction and expiring all attributes
        after rollback or commit handles object state automatically.
        This method is not intended for general use.

        N(   Rg   R   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   p  s    c         C   s   | |  _  d S(   s   Set the 'invoke all eagers' flag which causes joined- and
        subquery loaders to traverse into already-loaded related objects
        and collections.

        Default is that of :attr:`.Query._invoke_all_eagers`.

        N(   t   _invoke_all_eagers(   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _with_invoke_all_eagers~  s    	c         C   s   | d k r t |  } xp | j D]7 } t | t j  r" | j |  j   k r" | } Pq" q" Wt j	 d |  j   j
 j | j j f   n  |  j t | |   S(   sC  Add filtering criterion that relates the given instance
        to a child object or collection, using its attribute state
        as well as an established :func:`.relationship()`
        configuration.

        The method uses the :func:`.with_parent` function to generate
        the clause, the result of which is passed to :meth:`.Query.filter`.

        Parameters are the same as :func:`.with_parent`, with the exception
        that the given property can be None, in which case a search is
        performed against this :class:`.Query` object's target mapper.

        s\   Could not locate a property which relates instances of class '%s' to instances of class '%s'N(   R$   R   t   iterate_propertiesRI   R   t   RelationshipPropertyR/   R~   RE   R   R   t   __name__R   t   filterR   (   R!   R   t   propertyR/   t   prop(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    c         C   sS   | d k	 r t | |  } n  t |  j  |  _ t |  |  } |  j | g  d S(   sI   add a mapped entity to the list of result columns
        to be returned.N(   R$   R   t   listR&   R   R)   (   R!   R9   RK   RA   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt
   add_entity  s
    c         C   s   | |  _  d S(   sM   Return a :class:`.Query` that will use the given :class:`.Session`.

        N(   R   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   with_session  s    c         G   sS   |  j    j t  j t  j j d  } |  j |  } | rO | j |  n  | S(   s   return a Query that selects from this Query's
        SELECT statement.

        \*entities - optional list of entities which will replace
        those being selected.

        N(	   R   R   Rk   t   _set_enable_single_critR   R   R$   t   _from_selectableR    (   R!   R"   t
   fromclauseR   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt	   from_self  s    	c         C   s   | |  _  d  S(   N(   t   _enable_single_crit(   R!   t   val(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    c         C   s~   x! d D] } |  j  j | d   q W|  j | g t  t |  _ |  j } g  |  _ x% | D] } | j |  |  j	 d  qY Wd  S(   NR   R   R   R   R   R   t	   _joinpathR   R   t   _havingt	   _prefixesi    (   s
   _statements
   _criterions	   _order_bys	   _group_bys   _limits   _offsets	   _joinpaths
   _joinpoints	   _distincts   _havings	   _prefixes(
   R   RZ   R$   RY   Rg   Rk   Rn   R&   t   adapt_to_selectableRM   (   R!   R   R   t   old_entitiesRr   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s         
			c         G   sN   | s t  d  S|  j   } | j | d t | j sD d | _ n  t  |  S(   s\   Return an iterator yielding result tuples corresponding
        to the given list of columnsR*   i
   (    (   t   iterR   R    t   _ColumnEntityR   (   R!   t   columnsR   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   values  s    
	c         C   s4   y t  |  j |   d SWn t k
 r/ d SXd S(   sL   Return a scalar result corresponding to the given
        column expression.i    N(   t   nextR  t   StopIterationR$   (   R!   t   column(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    c         G   s   |  j  |  d S(   sJ  Return a new :class:`.Query` replacing the SELECT list with the
        given entities.

        e.g.::

            # Users, filtered on some arbitrary criterion
            # and then ordered by related email address
            q = session.query(User).\
                        join(User.address).\
                        filter(User.name.like('%ed%')).\
                        order_by(Address.email)

            # given *only* User.id==5, Address.email, and 'q', what
            # would the *next* User in the result be ?
            subq = q.with_entities(Address.email).\
                        order_by(None).\
                        filter(User.id==5).\
                        subquery()
            q = q.join((subq, subq.c.email < Address.email)).\
                        limit(1)

        .. versionadded:: 0.6.5

        N(   R    (   R!   R"   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   with_entities  s    c         G   sW   t  |  j  |  _ t |  j  } x | D] } t |  |  q( W|  j |  j |  d S(   sX   Add one or more column expressions to the list
        of result columns to be returned.N(   R   R&   RN   R  R)   (   R!   R  t   lR   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   add_columns  s
    s   0.7s9   :meth:`.add_column` is superseded by :meth:`.add_columns`c         C   s   |  j  |  S(   s   Add a column expression to the list of result columns to be
        returned.

        Pending deprecation: :meth:`.add_column` will be superseded by
        :meth:`.add_columns`.

        (   R  (   R!   R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt
   add_column'  s    c         G   s   |  j  t |  S(   s/  Return a new Query object, applying the given list of
        mapper options.

        Most supplied options regard changing how column- and
        relationship-mapped attributes are loaded. See the sections
        :ref:`deferred` and :doc:`/orm/loading` for reference
        documentation.

        (   t   _optionsRk   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   options5  s    
c         G   s   |  j  t |  S(   N(   R  Rg   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _conditional_optionsA  s    c         G   s   |  j  j   |  _  t t j |   } |  j | |  _ | r^ x< | D] } | j |   qD Wn x | D] } | j |   qe Wd  S(   N(   t   _attributesR-   RL   R   t   flatten_iteratort   _with_optionst   process_query_conditionallyt   process_query(   R!   t   conditionalR   t   optst   opt(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR  D  s    c         C   s
   | |   S(   s  Return a new :class:`.Query` object transformed by
        the given function.

        E.g.::

            def filter_something(criterion):
                def transform(q):
                    return q.filter(criterion)
                return transform

            q = q.with_transformation(filter_something(x==5))

        This allows ad-hoc recipes to be created for :class:`.Query`
        objects.  See the example at :ref:`hybrid_transformers`.

        .. versionadded:: 0.7.4

        (    (   R!   t   fn(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   with_transformationR  s    t   *c         C   s.   t  |  j } |  j | | | f f 7_ d S(   s_  Add an indexing hint for the given entity or selectable to
        this :class:`.Query`.

        Functionality is passed straight through to
        :meth:`~sqlalchemy.sql.expression.Select.with_hint`,
        with the addition that ``selectable`` can be a
        :class:`.Table`, :class:`.Alias`, or ORM entity / mapped class
        /etc.
        N(   R   R5   t   _with_hints(   R!   R5   t   textt   dialect_name(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt	   with_hintg  s    c         K   s   |  j  j |  |  _  d S(   sS   Set non-SQL options which take effect during execution.

        The options are the same as those accepted by
        :meth:`.Connection.execution_options`.

        Note that the ``stream_results`` execution option is enabled
        automatically if the :meth:`~sqlalchemy.orm.query.Query.yield_per()`
        method is used.

        N(   R   R   (   R!   t   kwargs(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   execution_optionsv  s    c         C   s   t  j |  |  _ d S(   s[  Return a new :class:`.Query` object with the specified "locking mode",
        which essentially refers to the ``FOR UPDATE`` clause.

        .. deprecated:: 0.9.0 superseded by :meth:`.Query.with_for_update`.

        :param mode: a string representing the desired locking mode.
         Valid values are:

         * ``None`` - translates to no lockmode

         * ``'update'`` - translates to ``FOR UPDATE``
           (standard SQL, supported by most dialects)

         * ``'update_nowait'`` - translates to ``FOR UPDATE NOWAIT``
           (supported by Oracle, PostgreSQL 8.1 upwards)

         * ``'read'`` - translates to ``LOCK IN SHARE MODE`` (for MySQL),
           and ``FOR SHARE`` (for PostgreSQL)

        .. seealso::

            :meth:`.Query.with_for_update` - improved API for
            specifying the ``FOR UPDATE`` clause.

        N(   t   LockmodeArgt   parse_legacy_queryR   (   R!   t   mode(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   with_lockmode  s    c         C   s"   t  d | d | d |  |  _ d S(   s  return a new :class:`.Query` with the specified options for the
        ``FOR UPDATE`` clause.

        The behavior of this method is identical to that of
        :meth:`.SelectBase.with_for_update`.  When called with no arguments,
        the resulting ``SELECT`` statement will have a ``FOR UPDATE`` clause
        appended.  When additional arguments are specified, backend-specific
        options such as ``FOR UPDATE NOWAIT`` or ``LOCK IN SHARE MODE``
        can take effect.

        E.g.::

            q = sess.query(User).with_for_update(nowait=True, of=User)

        The above query on a Postgresql backend will render like::

            SELECT users.id AS users_id FROM users FOR UPDATE OF users NOWAIT

        .. versionadded:: 0.9.0 :meth:`.Query.with_for_update` supersedes
           the :meth:`.Query.with_lockmode` method.

        .. seealso::

            :meth:`.GenerativeSelect.with_for_update` - Core level method with
            full argument and behavioral description.

        t   readt   nowaitt   ofN(   R!  R   (   R!   R%  R&  R'  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   with_for_update  s    c         O   sp   t  |  d k r& | j | d  n$ t  |  d k rJ t j d   n  |  j j   |  _ |  j j |  d S(   s  add values for bind parameters which may have been
        specified in filter().

        parameters may be specified using \**kwargs, or optionally a single
        dictionary as the first positional argument. The reason for both is
        that \**kwargs is convenient, however some parameter dictionaries
        contain unicode keys in which case \**kwargs cannot be used.

        i   i    sF   params() takes zero or one positional argument, which is a dictionary.N(   RN   R   RE   RF   R   R-   (   R!   R   R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    c         G   sj   xc t  |  D]U } t j |  } |  j | t t  } |  j d k	 rY |  j | @|  _ q | |  _ q Wd S(   s  apply the given filtering criterion to a copy
        of this :class:`.Query`, using SQL expressions.

        e.g.::

            session.query(MyClass).filter(MyClass.name == 'some name')

        Multiple criteria are joined together by AND::

            session.query(MyClass).\
                filter(MyClass.name == 'some name', MyClass.id > 5)

        The criterion is any SQL expression object applicable to the
        WHERE clause of a select.   String expressions are coerced
        into SQL expression constructs via the :func:`.text` construct.

        .. versionchanged:: 0.7.5
            Multiple criteria joined by AND.

        .. seealso::

            :meth:`.Query.filter_by` - filter on keyword expressions.

        N(   R   R   Rf   Re   Rg   R   R$   (   R!   t	   criterion(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    c         K   sP   g  | j    D]' \ } } t |  j   |  | k ^ q } |  j t j |    S(   s]  apply the given filtering criterion to a copy
        of this :class:`.Query`, using keyword expressions.

        e.g.::

            session.query(MyClass).filter_by(name = 'some name')

        Multiple criteria are joined together by AND::

            session.query(MyClass).\
                filter_by(name = 'some name', id = 5)

        The keyword expressions are extracted from the primary
        entity of the query, or the last entity that was the
        target of a call to :meth:`.Query.join`.

        .. seealso::

            :meth:`.Query.filter` - filter on SQL expressions.

        (   t   itemsR   R   R   R   t   and_(   R!   R  R   R   t   clauses(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt	   filter_by  s    7c         G   s   t  |  d k r^ | d t k r> d |  j k r: |  ` n  d S| d d k r^ d |  _ d Sn  |  j |  } |  j t k s |  j d k r | |  _ n |  j | |  _ d S(   s  apply one or more ORDER BY criterion to the query and return
        the newly resulting ``Query``

        All existing ORDER BY settings can be suppressed by
        passing ``None`` - this will suppress any ORDER BY configured
        on mappers as well.

        Alternatively, an existing ORDER BY setting on the Query
        object can be entirely cancelled by passing ``False``
        as the value - use this before calling methods where
        an ORDER BY is invalid.

        i   i    R   N(   RN   Rk   R   R   R$   Rj   (   R!   R)  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    		c         G   si   t  t g  | D] } t |  ^ q    } |  j |  } |  j t k rU | |  _ n |  j | |  _ d S(   sh   apply one or more GROUP BY criterion to the query and return
        the newly resulting :class:`.Query`N(   R   R    R
   Rj   R   Rk   (   R!   R)  R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   group_by3  s
    +c         C   s   t  | t j  r$ t j |  } n  | d k	 rU t  | t j  rU t j d   n  |  j	 | t
 t
  } |  j d k	 r |  j | @|  _ n	 | |  _ d S(   s	  apply a HAVING criterion to the query and return the
        newly resulting :class:`.Query`.

        :meth:`~.Query.having` is used in conjunction with
        :meth:`~.Query.group_by`.

        HAVING criterion makes it possible to use filters on aggregate
        functions like COUNT, SUM, AVG, MAX, and MIN, eg.::

            q = session.query(User.id).\
                        join(User.addresses).\
                        group_by(User.id).\
                        having(func.count(Address.id) > 2)

        sH   having() argument must be of type sqlalchemy.sql.ClauseElement or stringN(   RI   R   t   string_typesR   R  R$   t   ClauseElementRE   RF   Re   Rg   R   (   R!   R)  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   having@  s    c         G   s#   |  j  t j |  g t |     S(   s  Produce a UNION of this Query against one or more queries.

        e.g.::

            q1 = sess.query(SomeClass).filter(SomeClass.foo=='bar')
            q2 = sess.query(SomeClass).filter(SomeClass.bar=='foo')

            q3 = q1.union(q2)

        The method accepts multiple Query objects so as to control
        the level of nesting.  A series of ``union()`` calls such as::

            x.union(y).union(z).all()

        will nest on each ``union()``, and produces::

            SELECT * FROM (SELECT * FROM (SELECT * FROM X UNION
                            SELECT * FROM y) UNION SELECT * FROM Z)

        Whereas::

            x.union(y, z).all()

        produces::

            SELECT * FROM (SELECT * FROM X UNION SELECT * FROM y UNION
                            SELECT * FROM Z)

        Note that many database backends do not allow ORDER BY to
        be rendered on a query called within UNION, EXCEPT, etc.
        To disable all ORDER BY clauses including those configured
        on mappers, issue ``query.order_by(None)`` - the resulting
        :class:`.Query` object will not render ORDER BY within
        its SELECT statement.

        (   R   R   R   R   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   b  s    &c         G   s#   |  j  t j |  g t |     S(   s   Produce a UNION ALL of this Query against one or more queries.

        Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See
        that method for usage examples.

        (   R   R   t	   union_allR   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR2    s    c         G   s#   |  j  t j |  g t |     S(   s   Produce an INTERSECT of this Query against one or more queries.

        Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See
        that method for usage examples.

        (   R   R   t	   intersectR   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR3    s    c         G   s#   |  j  t j |  g t |     S(   s   Produce an INTERSECT ALL of this Query against one or more queries.

        Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See
        that method for usage examples.

        (   R   R   t   intersect_allR   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR4    s    c         G   s#   |  j  t j |  g t |     S(   s   Produce an EXCEPT of this Query against one or more queries.

        Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See
        that method for usage examples.

        (   R   R   t   except_R   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR5    s    c         G   s#   |  j  t j |  g t |     S(   s   Produce an EXCEPT ALL of this Query against one or more queries.

        Works the same way as :meth:`~sqlalchemy.orm.query.Query.union`. See
        that method for usage examples.

        (   R   R   t
   except_allR   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR6    s    c         O   si   | j  d t  | j  d t  } } | rJ t d d j | j    n  |  j | d t d | d | S(   s&+  Create a SQL JOIN against this :class:`.Query` object's criterion
        and apply generatively, returning the newly resulting :class:`.Query`.

        **Simple Relationship Joins**

        Consider a mapping between two classes ``User`` and ``Address``,
        with a relationship ``User.addresses`` representing a collection
        of ``Address`` objects associated with each ``User``.   The most
        common usage of :meth:`~.Query.join` is to create a JOIN along this
        relationship, using the ``User.addresses`` attribute as an indicator
        for how this should occur::

            q = session.query(User).join(User.addresses)

        Where above, the call to :meth:`~.Query.join` along ``User.addresses``
        will result in SQL equivalent to::

            SELECT user.* FROM user JOIN address ON user.id = address.user_id

        In the above example we refer to ``User.addresses`` as passed to
        :meth:`~.Query.join` as the *on clause*, that is, it indicates
        how the "ON" portion of the JOIN should be constructed.  For a
        single-entity query such as the one above (i.e. we start by selecting
        only from ``User`` and nothing else), the relationship can also be
        specified by its string name::

            q = session.query(User).join("addresses")

        :meth:`~.Query.join` can also accommodate multiple
        "on clause" arguments to produce a chain of joins, such as below
        where a join across four related entities is constructed::

            q = session.query(User).join("orders", "items", "keywords")

        The above would be shorthand for three separate calls to
        :meth:`~.Query.join`, each using an explicit attribute to indicate
        the source entity::

            q = session.query(User).\
                    join(User.orders).\
                    join(Order.items).\
                    join(Item.keywords)

        **Joins to a Target Entity or Selectable**

        A second form of :meth:`~.Query.join` allows any mapped entity
        or core selectable construct as a target.   In this usage,
        :meth:`~.Query.join` will attempt
        to create a JOIN along the natural foreign key relationship between
        two entities::

            q = session.query(User).join(Address)

        The above calling form of :meth:`~.Query.join` will raise an error if
        either there are no foreign keys between the two entities, or if
        there are multiple foreign key linkages between them.   In the
        above calling form, :meth:`~.Query.join` is called upon to
        create the "on clause" automatically for us.  The target can
        be any mapped entity or selectable, such as a :class:`.Table`::

            q = session.query(User).join(addresses_table)

        **Joins to a Target with an ON Clause**

        The third calling form allows both the target entity as well
        as the ON clause to be passed explicitly.   Suppose for
        example we wanted to join to ``Address`` twice, using
        an alias the second time.  We use :func:`~sqlalchemy.orm.aliased`
        to create a distinct alias of ``Address``, and join
        to it using the ``target, onclause`` form, so that the
        alias can be specified explicitly as the target along with
        the relationship to instruct how the ON clause should proceed::

            a_alias = aliased(Address)

            q = session.query(User).\
                    join(User.addresses).\
                    join(a_alias, User.addresses).\
                    filter(Address.email_address=='ed@foo.com').\
                    filter(a_alias.email_address=='ed@bar.com')

        Where above, the generated SQL would be similar to::

            SELECT user.* FROM user
                JOIN address ON user.id = address.user_id
                JOIN address AS address_1 ON user.id=address_1.user_id
                WHERE address.email_address = :email_address_1
                AND address_1.email_address = :email_address_2

        The two-argument calling form of :meth:`~.Query.join`
        also allows us to construct arbitrary joins with SQL-oriented
        "on clause" expressions, not relying upon configured relationships
        at all.  Any SQL expression can be passed as the ON clause
        when using the two-argument form, which should refer to the target
        entity in some way as well as an applicable source entity::

            q = session.query(User).join(Address, User.id==Address.user_id)

        .. versionchanged:: 0.7
            In SQLAlchemy 0.6 and earlier, the two argument form of
            :meth:`~.Query.join` requires the usage of a tuple:
            ``query(User).join((Address, User.id==Address.user_id))``\ .
            This calling form is accepted in 0.7 and further, though
            is not necessary unless multiple join conditions are passed to
            a single :meth:`~.Query.join` call, which itself is also not
            generally necessary as it is now equivalent to multiple
            calls (this wasn't always the case).

        **Advanced Join Targeting and Adaption**

        There is a lot of flexibility in what the "target" can be when using
        :meth:`~.Query.join`.   As noted previously, it also accepts
        :class:`.Table` constructs and other selectables such as
        :func:`.alias` and :func:`.select` constructs, with either the one
        or two-argument forms::

            addresses_q = select([Address.user_id]).\
                        where(Address.email_address.endswith("@bar.com")).\
                        alias()

            q = session.query(User).\
                        join(addresses_q, addresses_q.c.user_id==User.id)

        :meth:`~.Query.join` also features the ability to *adapt* a
        :meth:`~sqlalchemy.orm.relationship` -driven ON clause to the target
        selectable. Below we construct a JOIN from ``User`` to a subquery
        against ``Address``, allowing the relationship denoted by
        ``User.addresses`` to *adapt* itself to the altered target::

            address_subq = session.query(Address).\
                            filter(Address.email_address == 'ed@foo.com').\
                            subquery()

            q = session.query(User).join(address_subq, User.addresses)

        Producing SQL similar to::

            SELECT user.* FROM user
                JOIN (
                    SELECT address.id AS id,
                            address.user_id AS user_id,
                            address.email_address AS email_address
                    FROM address
                    WHERE address.email_address = :email_address_1
                ) AS anon_1 ON user.id = anon_1.user_id

        The above form allows one to fall back onto an explicit ON
        clause at any time::

            q = session.query(User).\
                    join(address_subq, User.id==address_subq.c.user_id)

        **Controlling what to Join From**

        While :meth:`~.Query.join` exclusively deals with the "right"
        side of the JOIN, we can also control the "left" side, in those
        cases where it's needed, using :meth:`~.Query.select_from`.
        Below we construct a query against ``Address`` but can still
        make usage of ``User.addresses`` as our ON clause by instructing
        the :class:`.Query` to select first from the ``User``
        entity::

            q = session.query(Address).select_from(User).\
                            join(User.addresses).\
                            filter(User.name == 'ed')

        Which will produce SQL similar to::

            SELECT address.* FROM user
                JOIN address ON user.id=address.user_id
                WHERE user.name = :name_1

        **Constructing Aliases Anonymously**

        :meth:`~.Query.join` can construct anonymous aliases
        using the ``aliased=True`` flag.  This feature is useful
        when a query is being joined algorithmically, such as
        when querying self-referentially to an arbitrary depth::

            q = session.query(Node).\
                    join("children", "children", aliased=True)

        When ``aliased=True`` is used, the actual "alias" construct
        is not explicitly available.  To work with it, methods such as
        :meth:`.Query.filter` will adapt the incoming entity to
        the last join point::

            q = session.query(Node).\
                    join("children", "children", aliased=True).\
                    filter(Node.name == 'grandchild 1')

        When using automatic aliasing, the ``from_joinpoint=True``
        argument can allow a multi-node join to be broken into
        multiple calls to :meth:`~.Query.join`, so that
        each path along the way can be further filtered::

            q = session.query(Node).\
                    join("children", aliased=True).\
                    filter(Node.name='child 1').\
                    join("children", aliased=True, from_joinpoint=True).\
                    filter(Node.name == 'grandchild 1')

        The filtering aliases above can then be reset back to the
        original ``Node`` entity using :meth:`~.Query.reset_joinpoint`::

            q = session.query(Node).\
                    join("children", "children", aliased=True).\
                    filter(Node.name == 'grandchild 1').\
                    reset_joinpoint().\
                    filter(Node.name == 'parent 1)

        For an example of ``aliased=True``, see the distribution
        example :ref:`examples_xmlpersistence` which illustrates
        an XPath-like query system using algorithmic joins.

        :param \*props: A collection of one or more join conditions,
         each consisting of a relationship-bound attribute or string
         relationship name representing an "on clause", or a single
         target entity, or a tuple in the form of ``(target, onclause)``.
         A special two-argument calling form of the form ``target, onclause``
         is also accepted.
        :param aliased=False: If True, indicate that the JOIN target should be
         anonymously aliased.  Subsequent calls to :meth:`~.Query.filter`
         and similar will adapt the incoming criterion to the target
         alias, until :meth:`~.Query.reset_joinpoint` is called.
        :param from_joinpoint=False: When using ``aliased=True``, a setting
         of True here will cause the join to be from the most recent
         joined target, rather than starting back from the original
         FROM clauses of the query.

        .. seealso::

            :ref:`ormtutorial_joins` in the ORM tutorial.

            :ref:`inheritance_toplevel` for details on how
            :meth:`~.Query.join` is used for inheritance relationships.

            :func:`.orm.join` - a standalone ORM-level join function,
            used internally by :meth:`.Query.join`, which in previous
            SQLAlchemy versions was the primary ORM-level joining interface.

        R   t   from_joinpoints   unknown arguments: %sR   t	   outerjoint   create_aliases(   RZ   Rk   t	   TypeErrorR   t   keyst   _join(   R!   t   propsR  R   R7  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    c         O   sf   | j  d t  | j  d t  } } | rG t d d j |    n  |  j | d t d | d | S(   s   Create a left outer join against this ``Query`` object's criterion
        and apply generatively, returning the newly resulting ``Query``.

        Usage is the same as the ``join()`` method.

        R   R7  s   unknown arguments: %sR   R8  R9  (   RZ   Rk   R:  R   R<  Rg   (   R!   R=  R  R   R7  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR8    s    c         C   se   | |  _  xL d | k rW | d \ } } | j   } | | | <| | f | d <| } q W| |  _ d  S(   Nt   prev(   R   R-   R   (   R!   t   jpt   fR>  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _update_joinpoint  s    	

c         C   s  | s |  j    n  t |  d k rr t | d t j t t f  rr t | d t t j t	 j
 f  rr | f } n  x{t j |  D]j} t | t  r | \ } } n d	 } t | t	 j
 t j f  r | | } } n | | } } d	 }	 }
 t | t j  r$|  j   }	 t |	 |  } | } n | rt | t	 j
  r| j }	 t |  j    } t | d d	  | j t | d d	  } } } | |	 k r|  j   }	 t |	 | j  } | } qn  t | t	 j
  r| d	 k r| j j } t | d d	  } | r| } q| j j } n  | j }	 | j }
 t | t j  sC|
 } n  | s|	 | |
 j f } | |  j k r|  j | j   } | |  j f | d <|  j |  q qqn' | d	 k	 r| d	 k rt d   n  |  j |	 | | | | |
  q Wd	 S(
   s   consumes arguments from join() or outerjoin(), places them into a
        consistent format with which to form the actual JOIN constructs.

        i   i    i   R/   R.   t   _of_typeR>  s   query.join(a==b) not supported.N(    t   _reset_joinpointRN   RI   R   Ra   t   typeR   t   strR0  R   t   PropComparatorR   R(   RL   R$   R/  R   R   t   _parententityR   Ru   R5   R   R   R/   R   t   QueryableAttributeR   R-   RA  t   NotImplementedErrort   _join_left_to_right(   R!   R;  R8  R9  R7  t   arg1t   arg2t   right_entityt   onclauset   left_entityR   t
   descriptorRW   t   left_mappert   left_selectablet   left_is_aliasedt   of_typet   edgeR?  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR<    sr    
						c         C   sE  |  j  j   |  _  | d k rV |  j r7 |  j d } qV |  j rV |  j d j } qV n  | d k r t j d |  j d   n  | | k r | r t j d | | f   n  t |  } t |  } t	 }	 | st
 | d d  }
 |
 r_|
 j st |
 j t j  r_xu |  j p| j g D]: } t j | j |  rt j | | j  rt }	 PqqWqt j | j | j  rt }	 qn  |	 r| j | j k rt j d | j   n  |  j | | | | | |	  \ } } | r| r|  j i | d 6| | | j f |  j f d 6 n i | d 6|  _ |  j | | | | |  d S(	   s)   append a JOIN to the query's from clause.i    sm   Don't know how to join from %s; please use select_from() to establish the left entity/selectable of this joins>   Can't construct a join from %s to %s, they are the same entityR/   s*   Can't join table/selectable '%s' to itselfR   R>  N(   R   R-   R$   RM   R&   t   entity_zero_or_selectableRE   R   R   Rk   Ru   R0   RI   R1   R   t   JoinR5   R3   t   selectables_overlapRg   t   _prepare_right_sideRA  R   R   t   _join_to_left(   R!   t   leftt   rightRN  R8  R9  R   t   l_infot   r_infot   overlapt   right_mapperRV   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyRJ  D  s^    					#c         C   s$  | } t  | d d   | j t  | d t  } }	 }
 | rP |  j | f 7_ n  | r | r | j | j  r t j d | | f   n  | r | r | j } n  t } | r,| |	 k r,|	 j	 | j
  s t j d |	 j | j
 j f   n  t |	 t j  r|	 j   }	 t } n  t | |	  } n  | oZ|
 oZ| j rWt | j t j  pZ| } | r| sp| rt | d t } t } n  | rt | d | r| j pi  d |  j |  _ n  t | t j  r|  j | t t  } n  | r| r|  j | t | d | j  n  | | f S(   NR/   R.   sI   Join target %s does not correspond to the right side of join condition %ss(   Selectable '%s' is not derived from '%s't   flatt   equivalentst   chain_to(   Ru   R$   R5   Rk   t   _join_entitiest   common_parentR/   RE   R   t   is_derived_fromR1   t   descriptionRI   R   RJ   RK   Rg   R   R0   t   _with_polymorphic_selectableRO   R   R6   Rv   R0  Re   R2   (   R!   R^  R\  RN  R9  R   R_  RW   R`  t   right_selectablet   right_is_aliasedt   need_adaptert   aliased_entity(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyRY    sb    		c         C   s  | } t  | d d   } | j } |  j r t j |  j |  \ }	 }
 |
 d  k	 r y t |
 | | d | }
 Wn/ t j k
 r } t j	 d | | f   n X|  j |	  |
 f |  j |	 d |  _ d  Sn  | rx< |  j
 D]" } | j |  r | j }
 Pq q W| }
 n | }
 |
 d  k	 s#t  y t |
 | | d | }
 Wn/ t j k
 rp} t j	 d | | f   n X|  j |
 f |  _ d  S(   NR/   t   isoutersL   Could not find a FROM clause to join from.  Tried joining to %s, but got: %si   (   Ru   R$   R5   RM   R3   t   find_join_sourcet   orm_joinRE   RF   R   R&   t   corresponds_tot   AssertionError(   R!   R]  R[  R\  RN  R8  RW   RQ  RR  t   replace_clause_indexRy   t   aeR+   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyRZ    sD    				c         C   s   |  j  |  _ d  |  _ d  S(   N(   R   R   R$   Rv   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyRC    s    c         C   s   |  j    d S(   sS  Return a new :class:`.Query`, where the "join point" has
        been reset back to the base FROM entities of the query.

        This method is usually used in conjunction with the
        ``aliased=True`` feature of the :meth:`~.Query.join`
        method.  See the example in :meth:`~.Query.join` for how
        this is used.

        N(   RC  (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   reset_joinpoint  s    c         G   s   |  j  | t  d S(   sP  Set the FROM clause of this :class:`.Query` explicitly.

        :meth:`.Query.select_from` is often used in conjunction with
        :meth:`.Query.join` in order to control which entity is selected
        from on the "left" side of the join.

        The entity or selectable object here effectively replaces the
        "left edge" of any calls to :meth:`~.Query.join`, when no
        joinpoint is otherwise established - usually, the default "join
        point" is the leftmost entity in the :class:`~.Query` object's
        list of entities to be selected.

        A typical example::

            q = session.query(Address).select_from(User).\
                join(User.addresses).\
                filter(User.name == 'ed')

        Which produces SQL equivalent to::

            SELECT address.* FROM user
            JOIN address ON user.id=address.user_id
            WHERE user.name = :name_1

        :param \*from_obj: collection of one or more entities to apply
         to the FROM clause.  Entities can be mapped classes,
         :class:`.AliasedClass` objects, :class:`.Mapper` objects
         as well as core :class:`.FromClause` elements like subqueries.

        .. versionchanged:: 0.9
            This method no longer applies the given FROM object
            to be the selectable from which matching entities
            select from; the :meth:`.select_entity_from` method
            now accomplishes this.  See that method for a description
            of this behavior.

        .. seealso::

            :meth:`~.Query.join`

            :meth:`.Query.select_entity_from`

        N(   RY   Rk   (   R!   RV   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   select_from  s    .c         C   s   |  j  | g t  d S(   s  Set the FROM clause of this :class:`.Query` to a
        core selectable, applying it as a replacement FROM clause
        for corresponding mapped entities.

        This method is similar to the :meth:`.Query.select_from`
        method, in that it sets the FROM clause of the query.  However,
        where :meth:`.Query.select_from` only affects what is placed
        in the FROM, this method also applies the given selectable
        to replace the FROM which the selected entities would normally
        select from.

        The given ``from_obj`` must be an instance of a :class:`.FromClause`,
        e.g. a :func:`.select` or :class:`.Alias` construct.

        An example would be a :class:`.Query` that selects ``User`` entities,
        but uses :meth:`.Query.select_entity_from` to have the entities
        selected from a :func:`.select` construct instead of the
        base ``user`` table::

            select_stmt = select([User]).where(User.id == 7)

            q = session.query(User).\
                    select_entity_from(select_stmt).\
                    filter(User.name == 'ed')

        The query generated will select ``User`` entities directly
        from the given :func:`.select` construct, and will be::

            SELECT anon_1.id AS anon_1_id, anon_1.name AS anon_1_name
            FROM (SELECT "user".id AS id, "user".name AS name
            FROM "user"
            WHERE "user".id = :id_1) AS anon_1
            WHERE anon_1.name = :name_1

        Notice above that even the WHERE criterion was "adapted" such that
        the ``anon_1`` subquery effectively replaces all references to the
        ``user`` table, except for the one that it refers to internally.

        Compare this to :meth:`.Query.select_from`, which as of
        version 0.9, does not affect existing entities.  The
        statement below::

            q = session.query(User).\
                    select_from(select_stmt).\
                    filter(User.name == 'ed')

        Produces SQL where both the ``user`` table as well as the
        ``select_stmt`` construct are present as separate elements
        in the FROM clause.  No "adaptation" of the ``user`` table
        is applied::

            SELECT "user".id AS user_id, "user".name AS user_name
            FROM "user", (SELECT "user".id AS id, "user".name AS name
            FROM "user"
            WHERE "user".id = :id_1) AS anon_1
            WHERE "user".name = :name_1

        :meth:`.Query.select_entity_from` maintains an older
        behavior of :meth:`.Query.select_from`.  In modern usage,
        similar results can also be achieved using :func:`.aliased`::

            select_stmt = select([User]).where(User.id == 7)
            user_from_select = aliased(User, select_stmt.alias())

            q = session.query(user_from_select)

        :param from_obj: a :class:`.FromClause` object that will replace
         the FROM clause of this :class:`.Query`.

        .. seealso::

            :meth:`.Query.select_from`

        .. versionadded:: 0.8
            :meth:`.Query.select_entity_from` was added to specify
            the specific behavior of entity replacement, however
            the :meth:`.Query.select_from` maintains this behavior
            as well until 0.9.

        N(   RY   Rg   (   R!   RV   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   select_entity_fromL  s    Sc      	   C   s  t  | t  r t j |  \ } } } t  | t  rY t  | t  rY | | d k rY g  St  | t  rt | d k  s t  | t  r | d k  r t |   | S|  j | |  } | d  k	 r t |  d  d  | j  St |  Sn3 | d k r t |   d St |  | | d ! d Sd  S(   Ni    ii   (   RI   t   sliceR   t   decode_slicet   intR   R$   t   step(   R!   t   itemt   startt   stopRz  t   res(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   __getitem__  s     c         C   s   | d k	 r> | d k	 r> |  j p$ d | |  _ | | |  _ nU | d k rb | d k	 rb | |  _ n1 | d k	 r | d k r |  j p d | |  _ n  |  j d k r d |  _ n  d S(   si   apply LIMIT/OFFSET to the ``Query`` based on a "
        "range and return the newly resulting ``Query``.i    N(   R$   R   R   (   R!   R|  R}  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyRw    s    c         C   s   | |  _  d S(   s[   Apply a ``LIMIT`` to the query and return the newly resulting

        ``Query``.

        N(   R   (   R!   t   limit(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    s    c         C   s   | |  _  d S(   s\   Apply an ``OFFSET`` to the query and return the newly resulting
        ``Query``.

        N(   R   (   R!   t   offset(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    s    c         G   sR   | s t  |  _ n< |  j |  } t |  j t  rE |  j | 7_ n	 | |  _ d S(   s  Apply a ``DISTINCT`` to the query and return the newly resulting
        ``Query``.

        :param \*expr: optional column expressions.  When present,
         the Postgresql dialect will render a ``DISTINCT ON (<expressions>>)``
         construct.

        N(   Rg   R   Rj   RI   R   (   R!   R)  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    
c         G   s(   |  j  r |  j  | 7_  n	 | |  _  d S(   s-  Apply the prefixes to the query and return the newly resulting
        ``Query``.

        :param \*prefixes: optional prefixes, typically strings,
         not using any commas.   In particular is useful for MySQL keywords.

        e.g.::

            query = sess.query(User.name).\
                prefix_with('HIGH_PRIORITY').\
                prefix_with('SQL_SMALL_RESULT', 'ALL')

        Would render::

            SELECT HIGH_PRIORITY SQL_SMALL_RESULT ALL users.name AS users_name
            FROM users

        .. versionadded:: 0.7.7

        N(   R   (   R!   t   prefixes(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   prefix_with  s    	c         C   s
   t  |   S(   s   Return the results represented by this ``Query`` as a list.

        This results in an execution of the underlying query.

        (   R   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   all
	  s    c         C   s^   t  | t j  r$ t j |  } n  t  | t j t j f  sQ t j	 d   n  | |  _
 d S(   s%  Execute the given SELECT statement and return results.

        This method bypasses all internal statement compilation, and the
        statement is executed without modification.

        The statement is typically either a :func:`~.expression.text`
        or :func:`~.expression.select` construct, and should return the set
        of columns
        appropriate to the entity class represented by this :class:`.Query`.

        .. seealso::

            :ref:`orm_tutorial_literal_sql` - usage examples in the
            ORM tutorial

        sB   from_statement accepts text(), select(), and union() objects only.N(   RI   R   R/  R   R  R   t
   TextClauseRJ   RE   RF   R   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   from_statement	  s    c         C   sZ   |  j  d k	 r% t |   d d !} n t |  d d ! } t |  d k rR | d Sd Sd S(   s  Return the first result of this ``Query`` or
        None if the result doesn't contain any row.

        first() applies a limit of one within the generated SQL, so that
        only one primary entity row is generated on the server side
        (note this may consist of multiple result rows if join-loaded
        collections are present).

        Calling ``first()`` results in an execution of the underlying query.

        i    i   N(   R   R$   R   RN   (   R!   t   ret(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   first0	  s    c         C   s]   t  |   } t |  } | d k r, | d S| d k rJ t j d   n t j d   d S(   s  Return exactly one result or raise an exception.

        Raises ``sqlalchemy.orm.exc.NoResultFound`` if the query selects
        no rows.  Raises ``sqlalchemy.orm.exc.MultipleResultsFound``
        if multiple object identities are returned, or if multiple
        rows are returned for a query that does not return object
        identities.

        Note that an entity query, that is, one which selects one or
        more mapped classes as opposed to individual column attributes,
        may ultimately represent many rows but only one row of
        unique entity or entities - this is a successful result for one().

        Calling ``one()`` results in an execution of the underlying query.

        .. versionchanged:: 0.6
            ``one()`` fully fetches all results instead of applying
            any kind of limit, so that the "unique"-ing of entities does not
            conceal multiple object identities.

        i   i    s   No row was found for one()s"   Multiple rows were found for one()N(   R   RN   t   orm_exct   NoResultFoundt   MultipleResultsFound(   R!   R  R
  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   oneE	  s    c         C   sG   y+ |  j    } t | t  s" | S| d SWn t j k
 rB d SXd S(   s4  Return the first element of the first result or None
        if no rows present.  If multiple rows are returned,
        raises MultipleResultsFound.

          >>> session.query(Item).scalar()
          <Item>
          >>> session.query(Item.id).scalar()
          1
          >>> session.query(Item.id).filter(Item.id < 0).scalar()
          None
          >>> session.query(Item.id, Item.name).scalar()
          1
          >>> session.query(func.count(Parent.id)).scalar()
          20

        This results in an execution of the underlying query.

        i    N(   R  RI   RL   R  R  R$   (   R!   R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   scalarf	  s    c         C   sH   |  j    } t | j _ |  j r; |  j r; |  j j   n  |  j |  S(   N(   R   Rg   R   t
   use_labelsR   R   R   t   _execute_and_instances(   R!   t   context(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   __iter__	  s
    c         K   s4   |  j  j |   } |  j r0 | j |  j   } n  | S(   N(   R   t
   connectionR   R   (   R!   t   kwt   conn(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _connection_from_session	  s
    			c         C   sR   |  j  d |  j   d | j d t  } | j | j |  j  } t j |  | |  S(   NR/   Ry   t   close_with_result(   R  R   R   Rg   t   executeR   R   t	   instances(   R!   t   querycontextR  t   result(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR  	  s    			c         C   sK   g  |  j  D]= } i | j d 6| j d 6t | d t  d 6| j d 6^ q
 S(   s  Return metadata about the columns which would be
        returned by this :class:`.Query`.

        Format is a list of dictionaries::

            user_alias = aliased(User, name='user2')
            q = sess.query(User, User.id, user_alias)

            # this expression:
            q.column_descriptions

            # would return:
            [
                {
                    'name':'User',
                    'type':User,
                    'aliased':False,
                    'expr':User,
                },
                {
                    'name':'id',
                    'type':Integer(),
                    'aliased':False,
                    'expr':User.id,
                },
                {
                    'name':'user2',
                    'type':User,
                    'aliased':True,
                    'expr':user_alias
                }
            ]

        R   RD  R.   R   t   expr(   R&   t   _label_nameRD  Ru   Rk   R  (   R!   R+   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   column_descriptions	  s    %c         C   s4   | } | d k r! t |   } n  t j |  | |  S(   s  Given a ResultProxy cursor as returned by connection.execute(),
        return an ORM result as an iterator.

        e.g.::

            result = engine.execute("select * from users")
            for u in session.query(User).instances(result):
                print u
        N(   R$   R   R   R  (   R!   t   cursort   _Query__contextR  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR  	  s    
c         C   s   t  j |  | |  S(   s?  Merge a result into this :class:`.Query` object's Session.

        Given an iterator returned by a :class:`.Query` of the same structure
        as this one, return an identical iterator of results, with all mapped
        instances merged into the session using :meth:`.Session.merge`. This
        is an optimized method which will merge all mapped instances,
        preserving the structure of the result rows and unmapped columns with
        less method overhead than that of calling :meth:`.Session.merge`
        explicitly for each value.

        The structure of the results is determined based on the column list of
        this :class:`.Query` - if these do not correspond, unchecked errors
        will occur.

        The 'load' argument is the same as that of :meth:`.Session.merge`.

        For an example of how :meth:`~.Query.merge_result` is used, see
        the source code for the example :ref:`examples_caching`, where
        :meth:`~.Query.merge_result` is used to efficiently restore state
        from a cache back into a target :class:`.Session`.

        (   R   t   merge_result(   R!   t   iteratort   load(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR  	  s    c         C   sF   i |  j  d 6|  j d 6|  j d 6|  j d 6|  j p7 d  d 6|  j d 6S(   NR  R  R   R  R.  R1  (   R   R   R   R   R   R$   R   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _select_args	  s    



c         C   sC   |  j  } | j d  d  k	 pB | j d  d  k	 pB | j d t  S(   NR  R  R   (   R  R_   R$   Rk   (   R!   R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _should_nest_selectable	  s    	c         C   s+   t  j |  j d  j   j j d g   S(   s  A convenience method that turns a query into an EXISTS subquery
        of the form EXISTS (SELECT 1 FROM ... WHERE ...).

        e.g.::

            q = session.query(User).filter(User.name == 'fred')
            session.query(q.exists())

        Producing SQL similar to::

            SELECT EXISTS (
                SELECT 1 FROM users WHERE users.name = :name_1
            ) AS anon_1

        The EXISTS construct is usually used in the WHERE clause::

            session.query(User.id).filter(q.exists()).scalar()

        Note that some databases such as SQL Server don't allow an
        EXISTS expression to be present in the columns clause of a
        SELECT.    To select a simple boolean value based on the exists
        as a WHERE, use :func:`.literal`::

            from sqlalchemy import literal

            session.query(literal(True)).filter(q.exists()).scalar()

        .. versionadded:: 0.8.1

        t   1(   R   t   existsR  R   R   t   with_only_columns(   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR  
  s    %c         C   s.   t  j j t  j d   } |  j |  j   S(   so  Return a count of rows this Query would return.

        This generates the SQL for this Query as follows::

            SELECT count(1) AS count_1 FROM (
                SELECT <rest of query follows...>
            ) AS anon_1

        .. versionchanged:: 0.7
            The above scheme is newly refined as of 0.7b3.

        For fine grained control over specific columns
        to count, to skip the usage of a subquery or
        otherwise control of the FROM clause,
        or to use other aggregate functions,
        use :attr:`~sqlalchemy.sql.expression.func`
        expressions in conjunction
        with :meth:`~.Session.query`, i.e.::

            from sqlalchemy import func

            # count User records, without
            # using a subquery.
            session.query(func.count(User.id))

            # return count of user "id" grouped
            # by "name"
            session.query(func.count(User.id)).\
                    group_by(User.name)

            from sqlalchemy import distinct

            # count distinct "name" values
            session.query(func.count(distinct(User.name)))

        R  (   R   t   funcR   t   literal_columnR   R  (   R!   t   col(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   *
  s    %t   evaluatec         C   s&   t  j j |  |  } | j   | j S(   sD  Perform a bulk delete query.

        Deletes rows matched by this query from the database.

        :param synchronize_session: chooses the strategy for the removal of
            matched objects from the session. Valid values are:

            ``False`` - don't synchronize the session. This option is the most
            efficient and is reliable once the session is expired, which
            typically occurs after a commit(), or explicitly using
            expire_all(). Before the expiration, objects may still remain in
            the session which were in fact deleted which can lead to confusing
            results if they are accessed via get() or already loaded
            collections.

            ``'fetch'`` - performs a select query before the delete to find
            objects that are matched by the delete query and need to be
            removed from the session. Matched objects are removed from the
            session.

            ``'evaluate'`` - Evaluate the query's criteria in Python straight
            on the objects in the session. If evaluation of the criteria isn't
            implemented, an error is raised.  In that case you probably
            want to use the 'fetch' strategy as a fallback.

            The expression evaluator currently doesn't account for differing
            string collations between the database and Python.

        :return: the count of rows matched as returned by the database's
          "row count" feature.

        This method has several key caveats:

        * The method does **not** offer in-Python cascading of relationships
          - it is assumed that ON DELETE CASCADE/SET NULL/etc. is configured
          for any foreign key references which require it, otherwise the
          database may emit an integrity violation if foreign key references
          are being enforced.

          After the DELETE, dependent objects in the :class:`.Session` which
          were impacted by an ON DELETE may not contain the current
          state, or may have been deleted. This issue is resolved once the
          :class:`.Session` is expired,
          which normally occurs upon :meth:`.Session.commit` or can be forced
          by using :meth:`.Session.expire_all`.  Accessing an expired object
          whose row has been deleted will invoke a SELECT to locate the
          row; when the row is not found, an
          :class:`~sqlalchemy.orm.exc.ObjectDeletedError` is raised.

        * The :meth:`.MapperEvents.before_delete` and
          :meth:`.MapperEvents.after_delete`
          events are **not** invoked from this method.  Instead, the
          :meth:`.SessionEvents.after_bulk_delete` method is provided to act
          upon a mass DELETE of entity rows.

        .. seealso::

            :meth:`.Query.update`

            :ref:`inserts_and_updates` - Core SQL tutorial

        (   R   t
   BulkDeletet   factoryt   exec_t   rowcount(   R!   t   synchronize_sessiont	   delete_op(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   deleteR
  s    A	
c         C   s)   t  j j |  | |  } | j   | j S(   s  Perform a bulk update query.

        Updates rows matched by this query in the database.

        :param values: a dictionary with attributes names as keys and literal
          values or sql expressions as values.

        :param synchronize_session: chooses the strategy to update the
            attributes on objects in the session. Valid values are:

            ``False`` - don't synchronize the session. This option is the most
            efficient and is reliable once the session is expired, which
            typically occurs after a commit(), or explicitly using
            expire_all(). Before the expiration, updated objects may still
            remain in the session with stale values on their attributes, which
            can lead to confusing results.

            ``'fetch'`` - performs a select query before the update to find
            objects that are matched by the update query. The updated
            attributes are expired on matched objects.

            ``'evaluate'`` - Evaluate the Query's criteria in Python straight
            on the objects in the session. If evaluation of the criteria isn't
            implemented, an exception is raised.

            The expression evaluator currently doesn't account for differing
            string collations between the database and Python.

        :return: the count of rows matched as returned by the database's
          "row count" feature.

        This method has several key caveats:

        * The method does **not** offer in-Python cascading of relationships
          - it is assumed that ON UPDATE CASCADE is configured for any foreign
          key references which require it, otherwise the database may emit an
          integrity violation if foreign key references are being enforced.

          After the UPDATE, dependent objects in the :class:`.Session` which
          were impacted by an ON UPDATE CASCADE may not contain the current
          state; this issue is resolved once the :class:`.Session` is expired,
          which normally occurs upon :meth:`.Session.commit` or can be forced
          by using :meth:`.Session.expire_all`.

        * As of 0.8, this method will support multiple table updates, as
          detailed in :ref:`multi_table_updates`, and this behavior does
          extend to support updates of joined-inheritance and other multiple
          table mappings.  However, the **join condition of an inheritance
          mapper is currently not automatically rendered**.
          Care must be taken in any multiple-table update to explicitly
          include the joining condition between those tables, even in mappings
          where this is normally automatic.
          E.g. if a class ``Engineer`` subclasses ``Employee``, an UPDATE of
          the ``Engineer`` local table using criteria against the ``Employee``
          local table might look like::

                session.query(Engineer).\
                    filter(Engineer.id == Employee.id).\
                    filter(Employee.name == 'dilbert').\
                    update({"engineer_type": "programmer"})

        * The :meth:`.MapperEvents.before_update` and
          :meth:`.MapperEvents.after_update`
          events are **not** invoked from this method.  Instead, the
          :meth:`.SessionEvents.after_bulk_update` method is provided to act
          upon a mass UPDATE of entity rows.

        .. seealso::

            :meth:`.Query.delete`

            :ref:`inserts_and_updates` - Core SQL tutorial

        (   R   t
   BulkUpdateR  R  R  (   R!   R  R  t	   update_op(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   
  s    R	
c         C   s:  t  |   } | j d  k	 r | S| | _ |  j | _ x! |  j D] } | j |  |  q> Wx) | j D] } | d } | | d   qb W| j r t	 | j  | _
 n | j
 | _
 |  j r |  j |  n  | j s |  j r t j d   q t j d   n  | j r$|  j r$|  j |  | _ n |  j |  | _ | S(   Ni    i   sy   No column-based properties specified for refresh operation. Use session.expire() to reload collections and related items.s4   Query contains no columns with which to SELECT from.(   R   R   R$   R   R   R&   t   setup_contextt   create_eager_joinst   from_clauseR   t   fromsR   t   _adjust_for_single_inheritancet   primary_columnsR   RE   R   t   multi_row_eager_loadersR  t   _compound_eager_statementt   _simple_statement(   R!   R   R  R9   t   rect   strategy(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   
  s2    	
				c   
   
   C   s  | j  r= t t g  | j  D] } t j |  ^ q    } n d  | _  g  } t j | j | | j	 d | j
 d | j d | j  |  j } x  |  j D] } | j |   } q W|  j r | j |  j   } n  | j   } |  j   } t j | |  | _ t j | g | j d | j } | j | _ | } x/ | j j   D] }	 t j | |	 |	 j  } q;W| j |  | j  r| j | j j | j     n  | j | j   | S(   NRV   R  R   (   R   R   R    R3   t   unwrap_order_byR$   R   t   selectR  R   R  R   R  R  R  R   R   RK   RP   R4   R?   t   secondary_columnsR   t   eager_joinsR  t   splice_joinst   stop_ont   append_fromt   append_order_byt   copy_and_processt   eager_order_by(
   R!   R  Ri   t   order_by_col_exprt   innert   hintRX   R   R  t
   eager_join(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    sJ    	+	
						c         C   s5  | j  s d  | _  n  |  j rj | j  rj t t g  | j  D] } t j |  ^ q7    } | j | 7_ n  | j t	 | j
 j    7_ t j | j | j | j d | j d | j d | j  |  j } | j | _ x  |  j D] } | j |   } q W|  j r| j |  j   } n  | j r1| j | j   n  | S(   NRV   R  R   (   R   R$   R   R   R    R3   R  R  R  RL   R  R  R   R  R  R   R   R  R   R  R  R   R   R  R  (   R!   R  Ri   R  R   R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR  `  s2    	(					c         C   s   x t  |  j j    D] \ } } | |  j k r7 q n  | j j } | d k	 r | rg | j |  } n  |  j | t	 t	  } t
 j t
 j j | j  |  | _ q q Wd S(   s@  Apply single-table-inheritance filtering.

        For all distinct single-table-inheritance mappers represented in
        the columns clause of this query, add criterion to the WHERE
        clause of the given QueryContext such that only the appropriate
        subtypes are selected from the total results.

        N(   R   R,   R  Rd  R/   t   _single_table_criterionR$   t   traverseRe   Rk   R   R+  t   True_t   _ifnoneR   (   R!   R  R:   R?   t   single_crit(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    s    
"c         C   s   t  |  j   j  S(   N(   RE  R   R   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   __str__  s    N(    (    (    (    (   R   t
   __module__t   __doc__Rg   R   R   Rk   R   R$   R   R   R   R   R   R   R   R   R   R   R   t	   frozensetR   R   R   R   R   R   R   RM   Rd  RD   R,   Rv   RQ   R   t   immutabledictR   R   R   R   R  R  R  R   t   _path_registryR   R#   R    R)   R2   RY   R[   Rd   Rj   R   Rm   Re   R|   R~   R   R   R   R   R   R   R   RP   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R5   R   R   R   R   R   R   R0   R   R_   R   R   R   R   R   R   R   R   R   R   R  t   _valuesR   R	  R  t   pending_deprecationR  R  R  R  R  R  R   R$  R(  R   R   R-  R   R.  R1  R   R2  R3  R4  R5  R6  R   R8  RA  R<  RJ  RY  RZ  RC  Rt  Ru  Rv  R  Rw  R  R  R   R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R   R  R   R   R  R  R  R  (    (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   1   sJ  	
	!		#				9																 <				$0	Z"							$	 "	)								j	F	U	,	0U					!					.	(	(FW.	C	$	(   t   ForUpdateArgR!  c           B   s   e  Z e d     Z RS(   c         C   s   | d  t f k r d  S| d k r1 t } t } nG | d k rJ t } } n. | d k re t } t } n t j d |   t d | d |  S(   NR%  R   t   update_nowaits"   Unknown with_lockmode argument: %rR&  (   R$   Rk   Rg   RE   RF   R!  (   R!   R#  R%  R&  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR"    s    		(   R   R  t   classmethodR"  (    (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR!    s   R%   c           B   s    e  Z d  Z d   Z d   Z RS(   s:   represent an entity column returned within a Query result.c         O   sl   |  t  k r_ | d } t | t j  r> t |  r> t }  q_ t | t  rV t }  q_ t }  n  t	 j
 |   S(   Ni   (   R%   RI   R   R/  R	   R   t   Bundlet   _BundleEntityR  t   objectR   (   R   R   R  R9   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    
			c         C   s+   |  j  j |  j   } |  j j   | _ | S(   N(   R   R   R   R-   (   R!   R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    (   R   R  R  R   R   (    (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR%     s   	R   c           B   s   e  Z d  Z d   Z e Z d   Z d   Z e Z	 e
 d    Z e
 d    Z d   Z d   Z d   Z d	   Z d
   Z d   Z RS(   s    mapper/class/AliasedClass entityc         C   s>   | j  s |  | _  n  | j j |   | g |  _ | |  _ d  S(   N(   R'   R&   RG   R"   R  (   R!   t   queryR9   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR#     s
    	c         C   s   | j  |  _  | |  _ | j |  _ | j |  _ | j |  _ | j |  _ | |  _ | j ri |  j j	 |  _
 n |  j  j j |  _
 |  j j |  _ t |  j  j j  |  _ d  S(   N(   R/   R;   R5   R.   t   with_polymorphic_mapperst   _with_polymorphicR   t   _polymorphic_discriminatorR}   R   R  R   R   R  R   t   boolt   dispatcht   append_resultt   custom_rows(   R!   R:   R;   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR7     s    			c         C   s   |  j  r t d   n  | d k r8 | j |  j  d S|  j j | |  \ } } | |  _ | |  _ | |  _ | j	 |  j t
 j | |  j j   d S(   s   Receive an update from a call to query.with_polymorphic().

        Note the newer style of using a free standing with_polymporphic()
        construct doesn't make use of this method.


        s6   Can't use with_polymorphic() against an Aliased objectN(   R.   RI  R$   R[   R/   t   _with_polymorphic_argsR  R  R5   R2   R3   R4   R6   (   R!   R  R   R5   R   t   mappersRV   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    						c         C   s
   |  j  j S(   N(   R/   R   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyRD    s    c         C   s   |  j  S(   N(   R}   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyRV    s    c         C   st   | j  r2 |  j  r. | j |  j j k r. t Sn  t S|  j  rd |  j j rT | |  j k S| |  j k Sn  | j |  j  S(   N(   R.   t   _base_aliasR}   Rg   Rk   t   _use_mapper_pathR  Re  (   R!   R9   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyRp    s    			c         C   s   | j  j |   d  S(   N(   R&   RG   (   R!   R  t   sel(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    c         C   sy   d  } |  j s6 | j r? | j j |  j d   } q? n	 |  j } | rl | j rc | j | j  } qu | } n	 | j } | S(   N(   R$   R.   R   R_   R/   R;   RQ   t   wrap(   R!   R  R  R?   R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   _get_entity_clauses   s    						c         C   s   |  j  | |  } | j r6 | r6 | j | j  } n | sH | j } n  | ry |  j j ry t j |  j |  j j  } n  | j	 |  k r t
 j |  j | |  j | d | j d | j d |  j } n' t
 j |  j | |  j | d |  j } | |  j f S(   NR   R   t   polymorphic_discriminator(   R  R?   R  R/   t   _requires_row_aliasingR3   R4   R5   R6   R'   R   t   instance_processorR   R   R   R  R  (   R!   R  R  R  R?   t	   _instance(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   row_processor4  s2    		c         C   sb  |  j  | |  } | j |  j f 7_ | j t k r{ |  j j r{ |  j j | _ | r{ | j t j | j   | _ q{ n  |  j	 r |  j j
 |  j	  } n |  j j } xZ | D]R } | j r | j | j k r q n  | j | |  |  j | d | j d | j q W|  j d  k	 r^|  j |  j j k	 r^| rB| j |  j } n	 |  j } | j j |  n  d  S(   NR   t   column_collection(   R  R  R5   R   Rk   R/   t
   adapt_listR   R(   R  t   _iterate_polymorphic_propertiest   _polymorphic_propertiesR   R   t   setupR   R  R  R$   R   R  RG   (   R!   R  R  R?   t   poly_propertiesR   t   pd(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR  Y  s<    					c         C   s   t  |  j  S(   N(   RE  R/   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    s    (   R   R  R  R#   Rg   t   supports_single_entityR7   R   t   idt	   filter_fnR   RD  RV  Rp  R   R  R  R  R  (    (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s   							%	.R  c           B   s\   e  Z d  Z e Z d   Z d Z d Z d   Z	 d   Z
 e d    Z d   Z d   Z RS(   s>  A grouping of SQL expressions that are returned by a :class:`.Query`
    under one namespace.

    The :class:`.Bundle` essentially allows nesting of the tuple-based
    results returned by a column-oriented :class:`.Query` object.  It also
    is extensible via simple subclassing, where the primary capability
    to override is that of how the set of expressions should be returned,
    allowing post-processing as well as custom return types, without
    involving ORM identity-mapped classes.

    .. versionadded:: 0.9.0

    .. seealso::

        :ref:`bundles`

    c         O   sb   | |  _  |  _ | |  _ t   |  _ |  _ |  j j d   | D  | j d |  j  |  _ d S(   sQ  Construct a new :class:`.Bundle`.

        e.g.::

            bn = Bundle("mybundle", MyClass.x, MyClass.y)

            for row in session.query(bn).filter(
                    bn.c.x == 5).filter(bn.c.y == 4):
                print(row.mybundle.x, row.mybundle.y)

        :param name: name of the bundle.
        :param \*exprs: columns or SQL expressions comprising the bundle.
        :param single_entity=False: if True, rows for this :class:`.Bundle`
         can be returned as a "single entity" outside of any enclosing tuple
         in the same manner as a mapped entity.

        c         s   s*   |  ]  } t  | d  | j  | f Vq d S(   R   N(   Ru   t   _label(   R   R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pys	   <genexpr>  s   t   single_entityN(	   R   R  t   exprsR   R   R  R   RZ   R   (   R!   R   R  R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR#     s    	c         C   s,   |  j  j |  j   } | j j |  j  | S(   N(   R   R   R   R   (   R!   t   cloned(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    c         C   s   t  j d t |  j  S(   Nt   group(   R   t
   ClauseListRk   R   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    c         C   s   |  j    j S(   N(   R   R,  (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR,    s    c         C   s   |  j    } | | _ | S(   s<   Provide a copy of this :class:`.Bundle` passing a new label.(   R   R   (   R!   R   R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    	c            s      f d   } | S(   s   Produce the "row processing" function for this :class:`.Bundle`.

        May be overridden by subclasses.

        .. seealso::

            :ref:`bundles` - includes an example of subclassing.

        c            s,   t  j g   D] } | |  d   ^ q    S(   N(   R   t
   KeyedTupleR$   (   t   rowR  t   proc(   R   t   procs(    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    s    (    (   R!   R  R  R   R  (    (   R   R  sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   create_row_processor  s    
N(   R   R  R  Rk   R   R#   R$   R  R   R   R   R   R,  R   R	  (    (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    s   				R  c           B   se   e  Z e d   Z e Z e d    Z d   Z e d    Z	 d   Z
 d   Z d   Z d   Z RS(   c         C   s   | j  j |   | |  _ |  _ t |  |  _ | j |  _ g  |  _  | r xF | j D]8 } t | t	  ry t
 |  |  qT t |  | d |  qT Wn  d |  _ d   |  _ |  j j |  _ d  S(   Nt	   namespacec         S   s   |  S(   N(    (   R{  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   <lambda>  s    (    (   R&   RG   t   bundleR  RD  R   R  R  RI   R  R  R  R"   R  R   R  (   R!   R  R  t   setup_entitiesR  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR#     s    		c         C   s5   x. |  j  D] } | j } | d  k	 r
 | Sq
 Wd  Sd  S(   N(   R&   R}   R$   (   R!   R+   t   ezero(    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR}     s
    	c         C   s   t  S(   N(   Rk   (   R!   R9   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyRp    s    c         C   s5   x. |  j  D] } | j } | d  k	 r
 | Sq
 Wd  Sd  S(   N(   R&   RV  R$   (   R!   R+   R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyRV     s
    	c         C   s@   t  | |  j d t } x! |  j D] } | j | |  q" Wd  S(   NR  (   R  R  Rk   R&   R   (   R!   R  R  R   R+   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR   )  s    c         C   s(   x! |  j  D] } | j | |  q
 Wd  S(   N(   R&   R7   (   R!   R:   R;   R+   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR7   2  s    c         C   s(   x! |  j  D] } | j | |  q
 Wd  S(   N(   R&   R  (   R!   R  R  R+   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR  6  s    c         C   s\   t  g  |  j D] } | j | | |  ^ q   \ } } |  j j | | |  } | |  j f S(   N(   t   zipR&   R  R  R	  R  (   R!   R  R  R  R+   R  R   R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR  :  s
    1(   R   R  Rg   R#   Rk   R  R   R}   Rp  RV  R   R7   R  R  (    (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    s   							R  c           B   st   e  Z d  Z d
 d  Z e Z e Z e d    Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z d	   Z RS(   s   Column/expression based entity.c            sf  | |  _  | |  _ t | t j  rB t j |  } | j |  _ nK t | t	 j
 t j f  rx | j |  _ | j   } n t | d d   |  _ t | t j  r t | d  r x[ | j D]) } | | k r Pn  t | | d | q Wd  Sn  t | t  rt | |  d  St | t j  s8t j d | f   n  | j |  _ } | j r`d   |  _ n t j       f d   |  _ | j rt | d t  r| j  |  j  } n  | j! j" |   | |  _# t$   |  _% t$ | j&  |  _'  t j(  f d   t) j* | i   D  |  _+ |  j+ r;t, |  j+  d	 |  _- n' |  j d  k	 rY|  j |  _- n	 d  |  _- d  S(
   NR   t   _select_iterableR
  s<   SQL expression, column, or mapped entity expected - got '%r'c         S   s   |  S(   N(    (   R{  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR  l  s    c            s       S(   N(    (   R{  (   t   counter(    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR  o  s    t
   is_literalc         3   s=   |  ]3 } d  | j  k r   j | j  r | j  d  Vq d S(   R\   N(   R^   t   intersectiont   _from_objects(   R   Rp   (   t   actual_froms(    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pys	   <genexpr>  s   i    (.   R  R
  RI   R   R/  R   R  R   R  R   RH  R   RF  R   t   _query_clause_elementRu   R$   R   t   ColumnElementRB   R  R  R  R  RE   R   RD  t   hashableR  R  R  Rk   R   R&   RG   R  R   R  R  R  t
   OrderedSetR   t   iterateR"   R   R}   (   R!   R  R  R
  R   t   type_(    (   R  R  sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR#   H  sX    					c         C   s8   |  j  d  k	 r |  j  S|  j r0 t |  j  d Sd  Sd  S(   Ni    (   R}   R$   R  R   (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyRV    s
    	c         C   sC   t  | | j |  j   } |  j | _ |  j | _ |  j | _ d  S(   N(   R  t   corresponding_columnR  R  R}   R"   (   R!   R  R  R   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s    c         C   s5   d |  j  k r | j |  _ n  |  j j | j  d  S(   NR5   (   R   R5   R  t   add(   R!   R:   R;   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR7     s    c         C   sP   |  j  d  k r t St |  r, | |  j  k St |  j   oK | j |  j   Sd  S(   N(   R}   R$   Rk   R   Re  (   R!   R9   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyRp    s    c         C   s   | j  | t t  S(   N(   Re   Rk   Rg   (   R!   R  R  R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt#   _resolve_expr_against_query_aliases  s    c            sP   |  j  | |  j |    | j r4 | j j     n    f d   } | |  j f S(   Nc            s   |    S(   N(    (   R  R  (   R  (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    s    (   R  R  R?   R  R  (   R!   R  R  R  R  (    (   R  sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    s    	c         C   sD   |  j  | |  j |  } | j t |  j  7_ | j j |  d  S(   N(   R  R  R  RL   R  RG   (   R!   R  R  R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    s    c         C   s   t  |  j  S(   N(   RE  R  (   R!   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    s    N(   R   R  R  R$   R#   Rk   R  R  R   RV  R   R7   Rp  R  R  R  R  (    (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR  E  s   M							c           B   s)   e  Z e Z d Z d Z d Z d    Z RS(   c         C   s3  | j  d  k	 rb t | j  t j  rS | j  j rS | j  j rS | j  j   |  _ q | j  |  _ n- d  |  _ | j	 |  _
 | j |  _ | j |  _ | |  _ | j |  _ | j |  _ | j |  _ | j |  _ | j |  _ g  |  _ g  |  _ g  |  _ i  |  _ g  |  _ t d   | j D  |  _  | j! j"   |  _# d  S(   Nc         s   s   |  ] } | j  r | Vq d  S(   N(   t   propagate_to_loaders(   R   Ri   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pys	   <genexpr>  s    ($   R   R$   RI   R   RJ   t   _textualR  t   apply_labelsR   RM   R  R   R   R   R   R  R   R   R   R   t   invoke_all_eagersR   R   R   R   R  R  R  R  R  R   R  t   propagate_optionsR  R-   R   (   R!   R  (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR#     s.    							N(    (	   R   R  Rk   R  R$   R?   R  t
   for_updateR#   (    (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR     s
   t   AliasOptionc           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  d S(   s!  Return a :class:`.MapperOption` that will indicate to the :class:`.Query`
        that the main table has been aliased.

        This is a seldom-used option to suit the
        very rare case that :func:`.contains_eager`
        is being used in conjunction with a user-defined SELECT
        statement that aliases the parent table.  E.g.::

            # define an aliased UNION called 'ulist'
            ulist = users.select(users.c.user_id==7).\
                            union(users.select(users.c.user_id>7)).\
                            alias('ulist')

            # add on an eager load of "addresses"
            statement = ulist.outerjoin(addresses).\
                            select().apply_labels()

            # create query, indicating "ulist" will be an
            # alias for the main table, "addresses"
            # property should be eager loaded
            query = session.query(User).options(
                                    contains_alias(ulist),
                                    contains_eager(User.addresses))

            # then get results via the statement
            results = query.from_statement(statement).all()

        :param alias: is the string name of an alias, or a
         :class:`~.sql.expression.Alias` object representing
         the alias.

        N(   RK   (   R!   RK   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR#     s    !c         C   sR   t  |  j t j  r3 | j   j j |  j  } n	 |  j } t j |  | _ d  S(   N(	   RI   RK   R   R/  R~   R1   R3   R4   RQ   (   R!   R  RK   (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR    s    	(   R   R  R#   R  (    (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyR%    s   	#N(9   R  t	   itertoolsR    t    R   R   R   R   R   R  R   t   baseR   R   R	   R
   R   t   path_registryR   R   R   R   R   Ro  R   R   R   R   RE   R   R   t   sql.expressionR   R3   R   R   t   sql.baseR   R   t   __all__t   rootR  t   _self_inspectst   class_loggerR  R   t   sql.selectableR  R!  R%   R   R  R  R  R   t   MapperOptionR%  (    (    (    sZ   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/query.pyt   <module>   sH   .((.		           u	oJ%