
H`Tc           @   s  d  Z  d d l Z d d l m Z m Z m Z m Z d d l 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 m Z m Z m Z m Z m Z d d
 l m Z d d l m Z d d l Z d d d d g Z e j    Z! d   Z" d e# f d     YZ$ e j% d  Z& e j% d  Z' e j% d  Z( e j% d  Z) e j% d  Z* d e# f d     YZ+ d e$ f d     YZ, d e$ f d     YZ- d   Z. d   Z/ d   Z0 e j1   Z2 d S(   s1   Provides the Session class and related utilities.iNi   (   t   utilt   sqlt   enginet   exc(   R    t
   expressioni   (   t   SessionExtensiont
   attributesR   t   queryt   loadingt   identity(   t   inspect(   t   object_mappert   class_mappert   _class_to_mappert   _state_mappert   object_statet	   _none_sett	   state_strt   instance_str(   t   UOWTransaction(   t   statet   Sessiont   SessionTransactionR   t   sessionmakerc         C   s3   |  j  r/ y t |  j  SWq/ t k
 r+ q/ Xn  d S(   s_   Given an :class:`.InstanceState`, return the :class:`.Session`
        associated, if any.
    N(   t
   session_idt	   _sessionst   KeyErrort   None(   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   _state_session#   s    	t   _SessionClassMethodsc           B   sJ   e  Z d  Z e d    Z e e j d  d     Z e d    Z RS(   sB   Class-level methods for :class:`.Session`, :class:`.sessionmaker`.c         C   s%   x t  j   D] } | j   q Wd S(   s   Close *all* sessions in memory.N(   R   t   valuest   close(   t   clst   sess(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt	   close_all3   s    s   sqlalchemy.orm.utilc         O   s   | j  | |   S(   sZ   Return an identity key.

        This is an alias of :func:`.util.identity_key`.

        (   t   identity_key(   R    t   orm_utilt   argst   kwargs(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR#   :   s    c         C   s
   t  |  S(   sx   Return the :class:`.Session` to which an object belongs.

        This is an alias of :func:`.object_session`.

        (   t   object_session(   R    t   instance(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR'   D   s    (	   t   __name__t
   __module__t   __doc__t   classmethodR"   R    t   dependenciesR#   R'   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR   /   s
   	t   ACTIVEt   PREPAREDt	   COMMITTEDt   DEACTIVEt   CLOSEDc           B   s   e  Z d  Z d Z d e d  Z e d    Z e e e d d  Z	 e d    Z
 d   Z e d  Z d d  Z d	   Z e d
  Z d   Z d   Z d   Z d   Z d   Z e d  Z d   Z d   Z d   Z d   Z RS(   s  A :class:`.Session`-level transaction.

    :class:`.SessionTransaction` is a mostly behind-the-scenes object
    not normally referenced directly by application code.   It coordinates
    among multiple :class:`.Connection` objects, maintaining a database
    transaction for each one individually, committing or rolling them
    back all at once.   It also provides optional two-phase commit behavior
    which can augment this coordination operation.

    The :attr:`.Session.transaction` attribute of :class:`.Session`
    refers to the current :class:`.SessionTransaction` object in use, if any.


    A :class:`.SessionTransaction` is associated with a :class:`.Session`
    in its default mode of ``autocommit=False`` immediately, associated
    with no database connections.  As the :class:`.Session` is called upon
    to emit SQL on behalf of various :class:`.Engine` or :class:`.Connection`
    objects, a corresponding :class:`.Connection` and associated
    :class:`.Transaction` is added to a collection within the
    :class:`.SessionTransaction` object, becoming one of the
    connection/transaction pairs maintained by the
    :class:`.SessionTransaction`.

    The lifespan of the :class:`.SessionTransaction` ends when the
    :meth:`.Session.commit`, :meth:`.Session.rollback` or
    :meth:`.Session.close` methods are called.  At this point, the
    :class:`.SessionTransaction` removes its association with its parent
    :class:`.Session`.   A :class:`.Session` that is in ``autocommit=False``
    mode will create a new :class:`.SessionTransaction` to replace it
    immediately, whereas a :class:`.Session` that's in ``autocommit=True``
    mode will remain without a :class:`.SessionTransaction` until the
    :meth:`.Session.begin` method is called.

    Another detail of :class:`.SessionTransaction` behavior is that it is
    capable of "nesting".  This means that the :meth:`.Session.begin` method
    can be called while an existing :class:`.SessionTransaction` is already
    present, producing a new :class:`.SessionTransaction` that temporarily
    replaces the parent :class:`.SessionTransaction`.   When a
    :class:`.SessionTransaction` is produced as nested, it assigns itself to
    the :attr:`.Session.transaction` attribute.  When it is ended via
    :meth:`.Session.commit` or :meth:`.Session.rollback`, it restores its
    parent :class:`.SessionTransaction` back onto the
    :attr:`.Session.transaction` attribute.  The behavior is effectively a
    stack, where :attr:`.Session.transaction` refers to the current head of
    the stack.

    The purpose of this stack is to allow nesting of
    :meth:`.Session.rollback` or :meth:`.Session.commit` calls in context
    with various flavors of :meth:`.Session.begin`. This nesting behavior
    applies to when :meth:`.Session.begin_nested` is used to emit a
    SAVEPOINT transaction, and is also used to produce a so-called
    "subtransaction" which allows a block of code to use a
    begin/rollback/commit sequence regardless of whether or not its enclosing
    code block has begun a transaction.  The :meth:`.flush` method, whether
    called explicitly or via autoflush, is the primary consumer of the
    "subtransaction" feature, in that it wishes to guarantee that it works
    within in a transaction block regardless of whether or not the
    :class:`.Session` is in transactional mode when the method is called.

    See also:

    :meth:`.Session.rollback`

    :meth:`.Session.commit`

    :meth:`.Session.begin`

    :meth:`.Session.begin_nested`

    :attr:`.Session.is_active`

    :meth:`.SessionEvents.after_commit`

    :meth:`.SessionEvents.after_rollback`

    :meth:`.SessionEvents.after_soft_rollback`

    c         C   s   | |  _  i  |  _ | |  _ | |  _ t |  _ | rL | rL t j d   n  |  j  j re |  j	   n  |  j  j
 j r |  j  j
 j |  j  |   n  d  S(   NsO   Can't start a SAVEPOINT transaction when no existing transaction is in progress(   t   sessiont   _connectionst   _parentt   nestedR.   t   _statet   sa_exct   InvalidRequestErrort   _enable_transaction_accountingt   _take_snapshott   dispatcht   after_transaction_create(   t   selfR3   t   parentR6   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   __init__   s    					c         C   s   |  j  d  k	 o |  j t k S(   N(   R3   R   R7   R.   (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt	   is_active   s    s   This transaction is closedc         C   s   |  j  t k r! t j d   n |  j  t k rK | s t j d   q n~ |  j  t k r | r | r |  j r t j d |  j   q | s t j d   q q n! |  j  t k r t j |   n  d  S(   Ns\   This session is in 'committed' state; no further SQL can be emitted within this transaction.s[   This session is in 'prepared' state; no further SQL can be emitted within this transaction.s   This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: %ss   This Session's transaction has been rolled back by a nested rollback() call.  To begin a new transaction, issue Session.rollback() first.(	   R7   R0   R8   R9   R/   R1   t   _rollback_exceptionR2   t   ResourceClosedError(   R>   t   prepared_okt   rollback_okt   deactive_okt
   closed_msg(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   _assert_active   s$    	c         C   s   |  j  p |  j S(   N(   R6   R5   (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   _is_transaction_boundary   s    c         K   s,   |  j    |  j j | |  } |  j |  S(   N(   RH   R3   t   get_bindt   _connection_for_bind(   R>   t   bindkeyR&   t   bind(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt
   connection   s    
c         C   s    |  j    t |  j |  d | S(   NR6   (   RH   R   R3   (   R>   R6   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   _begin   s    
c         C   sV   |  j  | k r |  f S|  j  d  k r; t j d |   n  |  f |  j  j |  Sd  S(   Ns4   Transaction %s is not on the active transaction list(   R5   R   R8   R9   t   _iterate_parents(   R>   t   upto(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyRP      s    c         C   s   |  j  sI |  j j |  _ |  j j |  _ |  j j |  _ |  j j |  _ d  S|  j j se |  j j   n  t	 j
   |  _ t	 j
   |  _ t	 j
   |  _ t	 j
   |  _ d  S(   N(   RI   R5   t   _newt   _deletedt   _dirtyt   _key_switchesR3   t	   _flushingt   flusht   weakreft   WeakKeyDictionary(   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR;      s    	c         C   sr  |  j  s t  xH t |  j  j |  j j  D]( } |  j j |  | j r. | ` q. q. WxR |  j j	   D]A \ } \ } } |  j j
 j |  | | _ |  j j
 j |  qj WxN t |  j  j |  j j  D]. } | j r | ` n  |  j j | d t q W|  j j st  xX |  j j
 j   D]D } | sK| j sK| |  j k r&| j | j |  j j
 j  q&q&Wd  S(   Nt   discard_existing(   RI   t   AssertionErrort   setRR   t   unionR3   t   _expunge_statet   keyRU   t   itemst   identity_mapt   discardt   replaceRS   t   deletedt   _update_implt   Truet
   all_statest   modifiedRT   t   _expiret   dictt	   _modified(   R>   t
   dirty_onlyt   st   oldkeyt   newkey(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   _restore_snapshot	  s"    %	"	%		c         C   s   |  j  s t  |  j r |  j j r x6 |  j j j   D]" } | j | j |  j j j	  q8 Wx |  j
 D] } d  | _ qh W|  j
 j   nN |  j r |  j j j |  j  |  j j
 j |  j
  |  j j j |  j  n  d  S(   N(   RI   R[   R6   R3   t   expire_on_commitRa   Rg   Ri   Rj   Rk   RS   R   R   t   clearR5   RR   t   updateRU   (   R>   Rm   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   _remove_snapshot"  s     	c         C   s6  |  j    | |  j k r( |  j | d S|  j rS |  j j |  } |  j s | SnK t | t j  r | } | j |  j k r t j	 d   q n | j
   } |  j j r |  j d  k r | j   } n$ |  j r | j   } n | j   } | | | | k	 f |  j | <|  j | j <|  j j j |  j |  |  | S(   Ni    sM   Session already has a Connection associated for the given Connection's Engine(   RH   R4   R5   RK   R6   t
   isinstanceR   t
   ConnectionR8   R9   t   contextual_connectR3   t   twophaseR   t   begin_twophaset   begin_nestedt   beginR<   t   after_begin(   R>   RM   t   connt   transaction(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyRK   0  s*    
			*c         C   s<   |  j  d  k	 s |  j j r. t j d   n  |  j   d  S(   NsD   'twophase' mode not enabled, or not root transaction; can't prepare.(   R5   R   R3   Rx   R8   R9   t   _prepare_impl(   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   prepareP  s    c         C   sV  |  j    |  j d  k s" |  j r; |  j j j |  j  n  |  j j } | |  k	 r} x' | j d |   D] } | j	   qf Wn  |  j j
 s xF t d  D]& } |  j j   r Pn  |  j j   q Wt j d   n  |  j d  k rI|  j j rIy2 x+ t |  j j    D] } | d j   qWWqIt j    |  j   Wd  QXqIXn  t |  _ d  S(   NRQ   id   sr   Over 100 subsequent flushes have occurred within session.commit() - is an after_flush() hook creating new objects?i   (   RH   R5   R   R6   R3   R<   t   before_commitR~   RP   t   commitRV   t   ranget	   _is_cleanRW   R   t
   FlushErrorRx   R\   R4   R   R   R    t   safe_reraiset   rollbackR/   R7   (   R>   t   stxt   subtransactiont   _flush_guardt   t(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR   W  s,    
c         C   s   |  j  d t  |  j t k	 r, |  j   n  |  j d  k sD |  j r x+ t |  j	 j
    D] } | d j   qZ Wt |  _ |  j j j |  j  |  j j r |  j   q n  |  j   |  j S(   NRD   i   (   RH   Rf   R7   R/   R   R5   R   R6   R\   R4   R   R   R0   R3   R<   t   after_commitR:   Rt   R   (   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR   v  s    	
c         C   sP  |  j  d t d t  |  j j } | |  k	 rX x' | j d |   D] } | j   qA Wn  |  j t t f k r xO |  j   D]> } | j	 d  k s | j r | j   t | _ Pqz t | _ qz Wn  |  j } |  j j r| j   rt j d  |  j d |  j  n  |  j   |  j	 r6| r6t j   d |  j	 _ n  | j j | |   |  j	 S(   NRD   RE   RQ   s\   Session's state has been changed on a non-active transaction - this state will be discarded.Rl   i   (   RH   Rf   R3   R~   RP   R   R7   R.   R/   R5   R   R6   t   _rollback_implR1   R:   R   R    t   warnRp   t   syst   exc_infoRB   R<   t   after_soft_rollback(   R>   t   _capture_exceptionR   R   R~   R!   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s.    
		
c         C   sj   x+ t  |  j j    D] } | d j   q W|  j j rP |  j d |  j  n  |  j j j	 |  j  d  S(   Ni   Rl   (
   R\   R4   R   R   R3   R:   Rp   R6   R<   t   after_rollback(   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s
    c         C   s   |  j  |  j _ |  j  d  k rg xF t |  j j    D], \ } } } | rV | j   q4 | j   q4 Wn  t |  _	 |  j j
 j r |  j j
 j |  j |   n  |  j  d  k r |  j j s |  j j   q n  d  |  _ d  |  _ d  S(   N(   R5   R3   R~   R   R\   R4   R   R   R2   R7   R<   t   after_transaction_endt
   autocommitR{   (   R>   RN   R~   t	   autoclose(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    "		c         C   s   |  S(   N(    (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt	   __enter__  s    c         C   s~   |  j  d t d t  |  j j d  k r, d  S| d  k rp y |  j   Wqz t j    |  j   Wd  QXqz Xn
 |  j   d  S(   NRF   RD   (	   RH   Rf   R3   R~   R   R   R    R   R   (   R>   t   typet   valuet	   traceback(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   __exit__  s    N(   R)   R*   R+   R   RB   t   FalseR@   t   propertyRA   RH   RI   RN   RO   RP   R;   Rp   Rt   RK   R   R   R   R   R   R   R   R   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR   V   s0   O 	
			 			%				c           B   s  e  Z d  Z dS Z dT e e e e e e dT dT dT e j d  Z	 dT Z
 dT Z e j d    Z e e d  Z d   Z d   Z d   Z d   Z dT dT dT e d  Z d    Z dT dT dT d!  Z dT dT dT d"  Z d#   Z d$   Z d%   Z d&   Z dT dT d'  Z d(   Z e e j d)     Z d*   Z  dT dT d+  Z! d,   Z" dT d-  Z# d.   Z$ d/   Z% e j& d0 d1  d2    Z' d3   Z( d4   Z) d5   Z* d6   Z+ d7   Z, e d8  Z- d9   Z. d:   Z/ d;   Z0 e d<  Z1 e dT d=  Z2 d>   Z3 d?   Z4 e d@  Z5 dA   Z6 dB   Z7 dC   Z8 dD   Z9 e dE  Z: dF   Z; dG   Z< dH   Z= dT dI  Z> dJ   Z? dK   Z@ dT dL  ZA e e dM  ZB e dN    ZC dT ZD e dO    ZE e dP    ZF e dQ    ZG e dR    ZH RS(U   s   Manages persistence operations for ORM-mapped objects.

    The Session's usage paradigm is described at :doc:`/orm/session`.


    t   __contains__t   __iter__t   addt   add_allR{   Rz   R   R   RN   t   deletet   executet   expiret
   expire_allt   expunget   expunge_allRW   RJ   t   is_modifiedt   mergeR   t   refreshR   t   scalarc         C   s  | r t  j |  _ n t j d  t  j |  _ |  j   |  _ i  |  _ i  |  _ | |  _	 i  |  _
 t |  _ t |  _ d |  _ t   |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |
 r |  j j |
  n  |	 r
x* t j |	  D] } t j |  |  q Wn  | d k	 rxm | j   D]\ \ } } t |  } | j rW|  j  | |  q#| j! rs|  j" | |  q#t s#t#  q#Wn  |  j s|  j$   n  |  t% |  j <d S(   sx  Construct a new Session.

        See also the :class:`.sessionmaker` function which is used to
        generate a :class:`.Session`-producing callable with a given
        set of arguments.

        :param autocommit:

          .. warning::

             The autocommit flag is **not for general use**, and if it is
             used, queries should only be invoked within the span of a
             :meth:`.Session.begin` / :meth:`.Session.commit` pair.  Executing
             queries outside of a demarcated transaction is a legacy mode
             of usage, and can in some cases lead to concurrent connection
             checkouts.

          Defaults to ``False``. When ``True``, the
          :class:`.Session` does not keep a persistent transaction running,
          and will acquire connections from the engine on an as-needed basis,
          returning them immediately after their use. Flushes will begin and
          commit (or possibly rollback) their own transaction if no
          transaction is present. When using this mode, the
          :meth:`.Session.begin` method is used to explicitly start
          transactions.

          .. seealso::

            :ref:`session_autocommit`

        :param autoflush: When ``True``, all query operations will issue a
           :meth:`~.Session.flush` call to this ``Session`` before proceeding.
           This is a convenience feature so that :meth:`~.Session.flush` need
           not be called repeatedly in order for database queries to retrieve
           results. It's typical that ``autoflush`` is used in conjunction with
           ``autocommit=False``. In this scenario, explicit calls to
           :meth:`~.Session.flush` are rarely needed; you usually only need to
           call :meth:`~.Session.commit` (which flushes) to finalize changes.

        :param bind: An optional :class:`.Engine` or :class:`.Connection` to
           which this ``Session`` should be bound. When specified, all SQL
           operations performed by this session will execute via this
           connectable.

        :param binds: An optional dictionary which contains more granular
           "bind" information than the ``bind`` parameter provides. This
           dictionary can map individual :class`.Table`
           instances as well as :class:`~.Mapper` instances to individual
           :class:`.Engine` or :class:`.Connection` objects. Operations which
           proceed relative to a particular :class:`.Mapper` will consult this
           dictionary for the direct :class:`.Mapper` instance as
           well as the mapper's ``mapped_table`` attribute in order to locate a
           connectable to use. The full resolution is described in the
           :meth:`.Session.get_bind`.
           Usage looks like::

            Session = sessionmaker(binds={
                SomeMappedClass: create_engine('postgresql://engine1'),
                somemapper: create_engine('postgresql://engine2'),
                some_table: create_engine('postgresql://engine3'),
                })

          Also see the :meth:`.Session.bind_mapper`
          and :meth:`.Session.bind_table` methods.

        :param \class_: Specify an alternate class other than
           ``sqlalchemy.orm.session.Session`` which should be used by the
           returned class. This is the only argument that is local to the
           :class:`.sessionmaker` function, and is not sent directly to the
           constructor for ``Session``.

        :param _enable_transaction_accounting:  Defaults to ``True``.  A
           legacy-only flag which when ``False`` disables *all* 0.5-style
           object accounting on transaction boundaries, including auto-expiry
           of instances on rollback and commit, maintenance of the "new" and
           "deleted" lists upon rollback, and autoflush of pending changes
           upon :meth:`~.Session.begin`, all of which are interdependent.

        :param expire_on_commit:  Defaults to ``True``. When ``True``, all
           instances will be fully expired after each :meth:`~.commit`,
           so that all attribute/object access subsequent to a completed
           transaction will load from the most recent database state.

        :param extension: An optional
           :class:`~.SessionExtension` instance, or a list
           of such instances, which will receive pre- and post- commit and
           flush events, as well as a post-rollback event. **Deprecated.**
           Please see :class:`.SessionEvents`.

        :param info: optional dictionary of arbitrary data to be associated
           with this :class:`.Session`.  Is available via the
           :attr:`.Session.info` attribute.  Note the dictionary is copied at
           construction time so that modifications to the per-
           :class:`.Session` dictionary will be local to that
           :class:`.Session`.

           .. versionadded:: 0.9.0

        :param query_cls:  Class which should be used to create new Query
           objects, as returned by the :meth:`~.Session.query` method. Defaults
           to :class:`.Query`.

        :param twophase:  When ``True``, all transactions will be started as
            a "two phase" transaction, i.e. using the "two phase" semantics
            of the database in use along with an XID.  During a
            :meth:`~.commit`, after :meth:`~.flush` has been issued for all
            attached databases, the :meth:`~.TwoPhaseTransaction.prepare`
            method on each database's :class:`.TwoPhaseTransaction` will be
            called. This allows each database to roll back the entire
            transaction, before each transaction is committed.

        :param weak_identity_map:  Defaults to ``True`` - when set to
           ``False``, objects placed in the :class:`.Session` will be
           strongly referenced until explicitly removed or the
           :class:`.Session` is closed.  **Deprecated** - this option
           is obsolete.

        sC   weak_identity_map=False is deprecated.  This feature is not needed.N(&   R	   t   WeakInstanceDictt   _identity_clsR    t   warn_deprecatedt   StrongInstanceDictRa   RR   RS   RM   t   _Session__bindsR   RV   t   _warn_on_eventsR   R~   t   _new_sessionidt   hash_keyt	   autoflushR   Rq   R:   Rx   t
   _query_clst   infoRs   t   to_listR   t   _adapt_listenerR`   R
   t   is_selectablet
   bind_tablet	   is_mappert   bind_mapperR[   R{   R   (   R>   RM   R   Rq   R:   R   Rx   t   weak_identity_mapt   bindst	   extensionR   t	   query_clst   extt   mapperortablet   insp(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR@     sF    }																c         C   s   i  S(   s  A user-modifiable dictionary.

        The initial value of this dictioanry can be populated using the
        ``info`` argument to the :class:`.Session` constructor or
        :class:`.sessionmaker` constructor or factory methods.  The dictionary
        here is always local to this :class:`.Session` and can be modified
        independently of all other :class:`.Session` objects.

        .. versionadded:: 0.9.0

        (    (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    c         C   sd   |  j  d k	 rH | s | r6 |  j  j d |  |  _  q] t j d   n t |  d | |  _  |  j  S(   s  Begin a transaction on this :class:`.Session`.

        If this Session is already within a transaction, either a plain
        transaction or nested transaction, an error is raised, unless
        ``subtransactions=True`` or ``nested=True`` is specified.

        The ``subtransactions=True`` flag indicates that this
        :meth:`~.Session.begin` can create a subtransaction if a transaction
        is already in progress. For documentation on subtransactions, please
        see :ref:`session_subtransactions`.

        The ``nested`` flag begins a SAVEPOINT transaction and is equivalent
        to calling :meth:`~.Session.begin_nested`. For documentation on
        SAVEPOINT transactions, please see :ref:`session_begin_nested`.

        R6   sS   A transaction is already begun.  Use subtransactions=True to allow subtransactions.N(   R~   R   RO   R8   R9   R   (   R>   t   subtransactionsR6   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR{     s    c         C   s   |  j  d t  S(   s  Begin a `nested` transaction on this Session.

        The target database(s) must support SQL SAVEPOINTs or a
        SQLAlchemy-supported vendor implementation of the idea.

        For documentation on SAVEPOINT
        transactions, please see :ref:`session_begin_nested`.

        R6   (   R{   Rf   (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyRz     s    
c         C   s#   |  j  d k r n |  j  j   d S(   s  Rollback the current transaction in progress.

        If no transaction is in progress, this method is a pass-through.

        This method rolls back the current transaction or nested transaction
        regardless of subtransactions being in effect.  All subtransactions up
        to the first real transaction are closed.  Subtransactions occur when
        :meth:`.begin` is called multiple times.

        .. seealso::

            :ref:`session_rollback`

        N(   R~   R   R   (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    c         C   sH   |  j  d k r7 |  j s% |  j   q7 t j d   n  |  j  j   d S(   s  Flush pending changes and commit the current transaction.

        If no transaction is in progress, this method raises an
        :exc:`~sqlalchemy.exc.InvalidRequestError`.

        By default, the :class:`.Session` also expires all database
        loaded state on all ORM-managed attributes after transaction commit.
        This so that subsequent operations load the most recent
        data from the database.   This behavior can be disabled using
        the ``expire_on_commit=False`` option to :class:`.sessionmaker` or
        the :class:`.Session` constructor.

        If a subtransaction is in effect (which occurs when begin() is called
        multiple times), the subtransaction will be closed, and the next call
        to ``commit()`` will operate on the enclosing transaction.

        When using the :class:`.Session` in its default mode of
        ``autocommit=False``, a new transaction will
        be begun immediately after the commit, but note that the newly begun
        transaction does *not* use any connection resources until the first
        SQL is actually emitted.

        .. seealso::

            :ref:`session_committing`

        s   No transaction is begun.N(   R~   R   R   R{   R8   R9   R   (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s
    	c         C   sH   |  j  d k r7 |  j s% |  j   q7 t j d   n  |  j  j   d S(   sx  Prepare the current transaction in progress for two phase commit.

        If no transaction is in progress, this method raises an
        :exc:`~sqlalchemy.exc.InvalidRequestError`.

        Only root transactions of two phase sessions can be prepared. If the
        current transaction is not such, an
        :exc:`~sqlalchemy.exc.InvalidRequestError` is raised.

        s   No transaction is begun.N(   R~   R   R   R{   R8   R9   R   (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR   
  s
    	c         K   s:   | d k r' |  j | d | | } n  |  j | d | S(   s  Return a :class:`.Connection` object corresponding to this
        :class:`.Session` object's transactional state.

        If this :class:`.Session` is configured with ``autocommit=False``,
        either the :class:`.Connection` corresponding to the current
        transaction is returned, or if no transaction is in progress, a new
        one is begun and the :class:`.Connection` returned (note that no
        transactional state is established with the DBAPI until the first
        SQL statement is emitted).

        Alternatively, if this :class:`.Session` is configured with
        ``autocommit=True``, an ad-hoc :class:`.Connection` is returned
        using :meth:`.Engine.contextual_connect` on the underlying
        :class:`.Engine`.

        Ambiguity in multi-bind or unbound :class:`.Session` objects can be
        resolved through any of the optional keyword arguments.   This
        ultimately makes usage of the :meth:`.get_bind` method for resolution.

        :param bind:
          Optional :class:`.Engine` to be used as the bind.  If
          this engine is already involved in an ongoing transaction,
          that connection will be used.  This argument takes precedence
          over ``mapper``, ``clause``.

        :param mapper:
          Optional :func:`.mapper` mapped class, used to identify
          the appropriate bind.  This argument takes precedence over
          ``clause``.

        :param clause:
            A :class:`.ClauseElement` (i.e. :func:`~.sql.expression.select`,
            :func:`~.sql.expression.text`,
            etc.) which will be used to locate a bind, if a bind
            cannot otherwise be identified.

        :param close_with_result: Passed to :meth:`.Engine.connect`,
          indicating the :class:`.Connection` should be considered
          "single use", automatically closing when the first result set is
          closed.  This flag only has an effect if this :class:`.Session` is
          configured with ``autocommit=True`` and does not already have a
          transaction in progress.

        :param \**kw:
          Additional keyword arguments are sent to :meth:`get_bind()`,
          allowing additional arguments to be passed to custom
          implementations of :meth:`get_bind`.

        t   clauset   close_with_resultN(   R   RJ   RK   (   R>   t   mapperR   RM   R   t   kw(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyRN     s    5c         K   s0   |  j  d  k	 r |  j  j |  S| j |   Sd  S(   N(   R~   R   RK   Rw   (   R>   R   R&   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyRK   X  s    c         K   s[   t  j |  } | d k r6 |  j | d | | } n  |  j | d t j | | pW i   S(   s  Execute a SQL expression construct or string statement within
        the current transaction.

        Returns a :class:`.ResultProxy` representing
        results of the statement execution, in the same manner as that of an
        :class:`.Engine` or
        :class:`.Connection`.

        E.g.::

            result = session.execute(
                        user_table.select().where(user_table.c.id == 5)
                    )

        :meth:`~.Session.execute` accepts any executable clause construct,
        such as :func:`~.sql.expression.select`,
        :func:`~.sql.expression.insert`,
        :func:`~.sql.expression.update`,
        :func:`~.sql.expression.delete`, and
        :func:`~.sql.expression.text`.  Plain SQL strings can be passed
        as well, which in the case of :meth:`.Session.execute` only
        will be interpreted the same as if it were passed via a
        :func:`~.expression.text` construct.  That is, the following usage::

            result = session.execute(
                        "SELECT * FROM user WHERE id=:param",
                        {"param":5}
                    )

        is equivalent to::

            from sqlalchemy import text
            result = session.execute(
                        text("SELECT * FROM user WHERE id=:param"),
                        {"param":5}
                    )

        The second positional argument to :meth:`.Session.execute` is an
        optional parameter set.  Similar to that of
        :meth:`.Connection.execute`, whether this is passed as a single
        dictionary, or a list of dictionaries, determines whether the DBAPI
        cursor's ``execute()`` or ``executemany()`` is used to execute the
        statement.   An INSERT construct may be invoked for a single row::

            result = session.execute(
                users.insert(), {"id": 7, "name": "somename"})

        or for multiple rows::

            result = session.execute(users.insert(), [
                                    {"id": 7, "name": "somename7"},
                                    {"id": 8, "name": "somename8"},
                                    {"id": 9, "name": "somename9"}
                                ])

        The statement is executed within the current transactional context of
        this :class:`.Session`.   The :class:`.Connection` which is used
        to execute the statement can also be acquired directly by
        calling the :meth:`.Session.connection` method.  Both methods use
        a rule-based resolution scheme in order to determine the
        :class:`.Connection`, which in the average case is derived directly
        from the "bind" of the :class:`.Session` itself, and in other cases
        can be based on the :func:`.mapper`
        and :class:`.Table` objects passed to the method; see the
        documentation for :meth:`.Session.get_bind` for a full description of
        this scheme.

        The :meth:`.Session.execute` method does *not* invoke autoflush.

        The :class:`.ResultProxy` returned by the :meth:`.Session.execute`
        method is returned with the "close_with_result" flag set to true;
        the significance of this flag is that if this :class:`.Session` is
        autocommitting and does not have a transaction-dedicated
        :class:`.Connection` available, a temporary :class:`.Connection` is
        established for the statement execution, which is closed (meaning,
        returned to the connection pool) when the :class:`.ResultProxy` has
        consumed all available data. This applies *only* when the
        :class:`.Session` is configured with autocommit=True and no
        transaction has been started.

        :param clause:
            An executable statement (i.e. an :class:`.Executable` expression
            such as :func:`.expression.select`) or string SQL statement
            to be executed.

        :param params:
            Optional dictionary, or list of dictionaries, containing
            bound parameter values.   If a single dictionary, single-row
            execution occurs; if a list of dictionaries, an
            "executemany" will be invoked.  The keys in each dictionary
            must correspond to parameter names present in the statement.

        :param mapper:
          Optional :func:`.mapper` or mapped class, used to identify
          the appropriate bind.  This argument takes precedence over
          ``clause`` when locating a bind.   See :meth:`.Session.get_bind`
          for more details.

        :param bind:
          Optional :class:`.Engine` to be used as the bind.  If
          this engine is already involved in an ongoing transaction,
          that connection will be used.  This argument takes
          precedence over ``mapper`` and ``clause`` when locating
          a bind.

        :param \**kw:
          Additional keyword arguments are sent to :meth:`.Session.get_bind()`
          to allow extensibility of "bind" schemes.

        .. seealso::

            :ref:`sqlexpression_toplevel` - Tutorial on using Core SQL
            constructs.

            :ref:`connections_toplevel` - Further information on direct
            statement execution.

            :meth:`.Connection.execute` - core level statement execution
            method, which is :meth:`.Session.execute` ultimately uses
            in order to execute the statement.

        R   R   N(   R   t   _literal_as_textR   RJ   RK   Rf   R   (   R>   R   t   paramsR   RM   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR   ^  s
    {c      	   K   s(   |  j  | d | d | d | | j   S(   s:   Like :meth:`~.Session.execute` but return a scalar result.R   R   RM   (   R   R   (   R>   R   R   R   RM   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    c         C   sD   |  j    |  j d k	 r@ x$ |  j j   D] } | j   q) Wn  d S(   s>  Close this Session.

        This clears all items and ends any transaction in progress.

        If this session were created with ``autocommit=False``, a new
        transaction is immediately begun.  Note that this new transaction does
        not use any connection resources until they are first needed.

        N(   R   R~   R   RP   R   (   R>   R~   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    

c         C   sV   x. |  j  j   t |  j  D] } | j   q W|  j   |  _  i  |  _ i  |  _ d S(   s   Remove all object instances from this ``Session``.

        This is equivalent to calling ``expunge(obj)`` on all objects in this
        ``Session``.

        N(   Ra   Rg   t   listRR   t   _detachR   RS   (   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s
    #	c         C   sS   t  | t  r t |  } n  | |  j | j <x | j D] } | |  j | <q8 Wd S(   s%  Bind operations for a mapper to a Connectable.

        mapper
          A mapper instance or mapped class

        bind
          Any Connectable: a :class:`.Engine` or :class:`.Connection`.

        All subsequent operations involving this mapper will use the given
        `bind`.

        N(   Ru   R   R   R   t   base_mappert   _all_tables(   R>   R   RM   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s
    c         C   s   | |  j  | <d S(   s$  Bind operations on a Table to a Connectable.

        table
          A :class:`.Table` instance

        bind
          Any Connectable: a :class:`.Engine` or :class:`.Connection`.

        All subsequent operations involving this :class:`.Table` will use the
        given `bind`.

        N(   R   (   R>   t   tableRM   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    c      	   C   s  | | k o d k n r> |  j r, |  j St j d   n  | d k	 rV t |  pY d } |  j r | r | j |  j k r |  j | j S| j |  j k r |  j | j Sn  | d k	 r x: t j	 | d t
 D]  } | |  j k r |  j | Sq Wq n  |  j r
|  j St | t j j  r/| j r/| j S| rK| j j rK| j j Sg  } | d k	 rq| j d |  n  | d k	 r| j d  n  t j d d j |    d S(   s<	  Return a "bind" to which this :class:`.Session` is bound.

        The "bind" is usually an instance of :class:`.Engine`,
        except in the case where the :class:`.Session` has been
        explicitly bound directly to a :class:`.Connection`.

        For a multiply-bound or unbound :class:`.Session`, the
        ``mapper`` or ``clause`` arguments are used to determine the
        appropriate bind to return.

        Note that the "mapper" argument is usually present
        when :meth:`.Session.get_bind` is called via an ORM
        operation such as a :meth:`.Session.query`, each
        individual INSERT/UPDATE/DELETE operation within a
        :meth:`.Session.flush`, call, etc.

        The order of resolution is:

        1. if mapper given and session.binds is present,
           locate a bind based on mapper.
        2. if clause given and session.binds is present,
           locate a bind based on :class:`.Table` objects
           found in the given clause present in session.binds.
        3. if session.bind is present, return that.
        4. if clause given, attempt to return a bind
           linked to the :class:`.MetaData` ultimately
           associated with the clause.
        5. if mapper given, attempt to return a bind
           linked to the :class:`.MetaData` ultimately
           associated with the :class:`.Table` or other
           selectable to which the mapper is mapped.
        6. No bind can be found, :exc:`~sqlalchemy.exc.UnboundExecutionError`
           is raised.

        :param mapper:
          Optional :func:`.mapper` mapped class or instance of
          :class:`.Mapper`.   The bind can be derived from a :class:`.Mapper`
          first by consulting the "binds" map associated with this
          :class:`.Session`, and secondly by consulting the :class:`.MetaData`
          associated with the :class:`.Table` to which the :class:`.Mapper`
          is mapped for a bind.

        :param clause:
            A :class:`.ClauseElement` (i.e. :func:`~.sql.expression.select`,
            :func:`~.sql.expression.text`,
            etc.).  If the ``mapper`` argument is not present or could not
            produce a bind, the given expression construct will be searched
            for a bound element, typically a :class:`.Table` associated with
            bound :class:`.MetaData`.

        sl   This session is not bound to a single Engine or Connection, and no context was provided to locate a binding.t   include_cruds	   mapper %ss   SQL expressions8   Could not locate a bind configured on %s or this Sessions   , N(   R   RM   R8   t   UnboundExecutionErrorR   R   R   t   mapped_tablet   sql_utilt   find_tablesRf   Ru   R   R   t   ClauseElementt   appendt   join(   R>   R   R   t   c_mapperR   t   context(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyRJ   +  s<    4			
c         O   s   |  j  | |  |  S(   sT   Return a new :class:`.Query` object corresponding to this
        :class:`.Session`.(   R   (   R>   t   entitiesR&   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    c         c   s$   |  j  } t |  _  |  V| |  _  d S(   s  Return a context manager that disables autoflush.

        e.g.::

            with session.no_autoflush:

                some_object = SomeClass()
                session.add(some_object)
                # won't autoflush
                some_object.related_thing = session.query(SomeRelated).first()

        Operations that proceed within the ``with:`` block
        will not be subject to flushes occurring upon query
        access.  This is useful when initializing a series
        of objects which involve existing database queries,
        where the uncompleted object should not yet be flushed.

        .. versionadded:: 0.7.6

        N(   R   R   (   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   no_autoflush  s    		c         C   s[   |  j  rW |  j rW y |  j   WqW t j k
 rS } | j d  t j |  qW Xn  d  S(   Ns   raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely(   R   RV   RW   R8   t   StatementErrort
   add_detailR    t   raise_from_cause(   R>   t   e(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt
   _autoflush  s    c      	   C   s   y t  j |  } Wn# t j k
 r8 t j |   n X|  j | |  t j |  j t	 |   | j
 d | d | d | d k r t j d t |    n  d S(   sX  Expire and refresh the attributes on the given instance.

        A query will be issued to the database and all attributes will be
        refreshed with their current database value.

        Lazy-loaded relational attributes will remain lazily loaded, so that
        the instance-wide refresh operation will be followed immediately by
        the lazy load of that attribute.

        Eagerly-loaded relational attributes will eagerly load within the
        single refresh operation.

        Note that a highly isolated transaction will return the same values as
        were previously read in that same transaction, regardless of changes
        in database state outside of that transaction - usage of
        :meth:`~Session.refresh` usually only makes sense if non-ORM SQL
        statement were emitted in the ongoing transaction, or if autocommit
        mode is turned on.

        :param attribute_names: optional.  An iterable collection of
          string attribute names indicating a subset of attributes to
          be refreshed.

        :param lockmode: Passed to the :class:`~sqlalchemy.orm.query.Query`
          as used by :meth:`~sqlalchemy.orm.query.Query.with_lockmode`.

        .. seealso::

            :ref:`session_expire` - introductory material

            :meth:`.Session.expire`

            :meth:`.Session.expire_all`

        t   refresh_statet   lockmodet   only_load_propss   Could not refresh instance '%s'N(   R   t   instance_stateR   t   NO_STATEt   UnmappedInstanceErrort   _expire_stateR   t   load_on_identR   R   R_   R   R8   R9   R   (   R>   R(   t   attribute_namesR   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    $c         C   s7   x0 |  j  j   D] } | j | j |  j  j  q Wd S(   s  Expires all persistent instances within this Session.

        When any attributes on a persistent instance is next accessed,
        a query will be issued using the
        :class:`.Session` object's current transactional context in order to
        load all expired attributes for the given instance.   Note that
        a highly isolated transaction will return the same values as were
        previously read in that same transaction, regardless of changes
        in database state outside of that transaction.

        To expire individual objects and individual attributes
        on those objects, use :meth:`Session.expire`.

        The :class:`.Session` object's default behavior is to
        expire all state whenever the :meth:`Session.rollback`
        or :meth:`Session.commit` methods are called, so that new
        state can be loaded for the new transaction.   For this reason,
        calling :meth:`Session.expire_all` should not be needed when
        autocommit is ``False``, assuming the transaction is isolated.

        .. seealso::

            :ref:`session_expire` - introductory material

            :meth:`.Session.expire`

            :meth:`.Session.refresh`

        N(   Ra   Rg   Ri   Rj   Rk   (   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    c         C   sM   y t  j |  } Wn# t j k
 r8 t j |   n X|  j | |  d S(   s  Expire the attributes on an instance.

        Marks the attributes of an instance as out of date. When an expired
        attribute is next accessed, a query will be issued to the
        :class:`.Session` object's current transactional context in order to
        load all expired attributes for the given instance.   Note that
        a highly isolated transaction will return the same values as were
        previously read in that same transaction, regardless of changes
        in database state outside of that transaction.

        To expire all objects in the :class:`.Session` simultaneously,
        use :meth:`Session.expire_all`.

        The :class:`.Session` object's default behavior is to
        expire all state whenever the :meth:`Session.rollback`
        or :meth:`Session.commit` methods are called, so that new
        state can be loaded for the new transaction.   For this reason,
        calling :meth:`Session.expire` only makes sense for the specific
        case that a non-ORM SQL statement was emitted in the current
        transaction.

        :param instance: The instance to be refreshed.
        :param attribute_names: optional list of string attribute names
          indicating a subset of attributes to be expired.

        .. seealso::

            :ref:`session_expire` - introductory material

            :meth:`.Session.expire`

            :meth:`.Session.refresh`

        N(   R   R   R   R   R   R   (   R>   R(   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s
    #c         C   s   |  j  |  | r) | j | j |  nU t | j j j d |   } |  j |  x' | D] \ } } } } |  j |  q[ Wd  S(   Ns   refresh-expire(   t   _validate_persistentt   _expire_attributesRj   R   t   managerR   t   cascade_iteratort   _conditional_expire(   R>   R   R   t   cascadedt   ot   mt   st_t   dct_(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR   8  s    c         C   sU   | j  r% | j | j |  j j  n, | |  j k rQ |  j j |  | j   n  d S(   s5   Expire a state if persistent, else expunge if pendingN(   R_   Ri   Rj   Ra   Rk   RR   t   popR   (   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR   E  s
    	s   0.7sB   The non-weak-referencing identity map feature is no longer needed.c         C   s   |  j  j   S(   s  Remove unreferenced instances cached in the identity map.

        Note that this method is only meaningful if "weak_identity_map" is set
        to False.  The default weak identity map is self-pruning.

        Removes any object in this Session's identity map that is not
        referenced in user code, modified, new or scheduled for deletion.
        Returns the number of objects pruned.

        (   Ra   t   prune(   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR   N  s    c         C   s   y t  j |  } Wn# t j k
 r8 t j |   n X| j |  j k	 rg t j d t	 |    n  t
 | j j j d |   } |  j |  x' | D] \ } } } } |  j |  q Wd S(   s   Remove the `instance` from this ``Session``.

        This will free all internal references to the instance.  Cascading
        will be applied according to the *expunge* cascade rule.

        s*   Instance %s is not present in this SessionR   N(   R   R   R   R   R   R   R   R8   R9   R   R   R   R   R   R^   (   R>   R(   R   R   R   R   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR   ]  s    c         C   s   | |  j  k r, |  j  j |  | j   nd |  j j |  rn |  j j |  |  j j | d   | j   n" |  j r |  j j j | d   n  d  S(   N(	   RR   R   R   Ra   t   contains_stateRb   RS   R   R~   (   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR^   s  s    	c         C   s  x.| D]&} t  |  } | j   } | d  k	 r | j |  } t j | d  r] | j sp t j | d  r t j	 d t
 |    n  | j d  k r | | _ ns | j | k r|  j j |  | |  j j k r |  j j | d } n	 | j } | | f |  j j | <| | _ n  |  j j |  q q Wt j j d   | D |  j  |  j |  x0 t |  j |  j  D] } |  j j |  qwWd  S(   Ni   sN  Instance %s has a NULL identity key.  If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the mapped Column object is configured to expect these generated values.  Ensure also that this flush() is not occurring at an inappropriate time, such aswithin a load() event.i    c         s   s   |  ] } | | j  f Vq d  S(   N(   Rj   (   t   .0R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pys	   <genexpr>  s    (   R   t   objR   t   _identity_key_from_stateR   t   issubsett   allow_partial_pkst
   issupersetR   R   R   R_   Ra   Rb   R~   RU   Rc   t   statelibt   InstanceStatet   _commit_all_statest   _register_alteredR\   t   intersectionRR   R   (   R>   t   statesR   R   R   t   instance_keyt   orig_key(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   _register_newly_persistent~  s6    
		
c         C   s\   |  j  rX |  j rX xC | D]8 } | |  j k rA t |  j j | <q t |  j j | <q Wn  d  S(   N(   R:   R~   RR   Rf   RT   (   R>   R  R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s
    c         C   sf   x_ | D]W } |  j  r2 |  j r2 t |  j j | <n  |  j j |  |  j j | d   t | _ q Wd  S(   N(	   R:   R~   Rf   RS   Ra   Rb   R   R   Rd   (   R>   R  R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   _remove_newly_deleted  s    c         C   si   | r |  j  r |  j d  n  y t j |  } Wn# t j k
 rW t j |   n X|  j |  d S(   s   Place an object in the ``Session``.

        Its state will be persisted to the database on the next flush
        operation.

        Repeated calls to ``add()`` will be ignored. The opposite of ``add()``
        is ``expunge()``.

        s   Session.add()N(   R   t   _flush_warningR   R   R   R   R   t   _save_or_update_state(   R>   R(   t   _warnR   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    
c         C   sA   |  j  r |  j d  n  x! | D] } |  j | d t q  Wd S(   s:   Add the given collection of instances to this ``Session``.s   Session.add_all()R	  N(   R   R  R   R   (   R>   t	   instancesR(   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    	c         C   s\   |  j  |  t |  } x< | j d | d |  j D] \ } } } } |  j  |  q5 Wd  S(   Ns   save-updatet   halt_on(   t   _save_or_update_implR   R   t   _contains_state(   R>   R   R   R   R   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR    s    	c         C   s  |  j  r |  j d  n  y t j |  } Wn# t j k
 rQ t j |   n X| j d k r} t	 j
 d t |    n  | |  j k r d S|  j | d t t | j j j d |   } | j   |  j | <|  j j |  x' | D] \ } } } } |  j |  q Wd S(   sf   Mark an instance as deleted.

        The database delete operation occurs upon ``flush()``.

        s   Session.delete()s   Instance '%s' is not persistedNt   include_beforeR   (   R   R  R   R   R   R   R   R_   R   R8   R9   R   RS   t   _attachRf   R   R   R   R   R   Ra   R   t   _delete_impl(   R>   R(   R   t   cascade_statesR   R   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s&    	c         C   s   |  j  r |  j d  n  i  } | r2 |  j   n  t |  |  j } z; t |  _ |  j t j |  t j	 |  d | d | SWd | |  _ Xd S(   sS	  Copy the state of a given instance into a corresponding instance
        within this :class:`.Session`.

        :meth:`.Session.merge` examines the primary key attributes of the
        source instance, and attempts to reconcile it with an instance of the
        same primary key in the session.   If not found locally, it attempts
        to load the object from the database based on primary key, and if
        none can be located, creates a new instance.  The state of each
        attribute on the source instance is then copied to the target
        instance.  The resulting target instance is then returned by the
        method; the original source instance is left unmodified, and
        un-associated with the :class:`.Session` if not already.

        This operation cascades to associated instances if the association is
        mapped with ``cascade="merge"``.

        See :ref:`unitofwork_merging` for a detailed discussion of merging.

        :param instance: Instance to be merged.
        :param load: Boolean, when False, :meth:`.merge` switches into
         a "high performance" mode which causes it to forego emitting history
         events as well as all database access.  This flag is used for
         cases such as transferring graphs of objects into a :class:`.Session`
         from a second level cache, or to transfer just-loaded objects
         into the :class:`.Session` owned by a worker thread or process
         without re-querying the database.

         The ``load=False`` use case adds the caveat that the given
         object has to be in a "clean" state, that is, has no pending changes
         to be flushed - even if the incoming object is detached from any
         :class:`.Session`.   This is so that when
         the merge operation populates local attributes and
         cascades to related objects and
         collections, the values can be "stamped" onto the
         target object as is, without generating any history or attribute
         events, and without the need to reconcile the incoming data with
         any existing related objects or collections that might not
         be loaded.  The resulting objects from ``load=False`` are always
         produced as "clean", so it is only appropriate that the given objects
         should be "clean" as well, else this suggests a mis-use of the
         method.

        s   Session.merge()t   loadt
   _recursiveN(
   R   R  R   R   R   R   t   _mergeR   R   t   instance_dict(   R>   R(   R  R  R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    -	
		c         C   s  t  |  } | | k r  | | St } | j } | d  k re | sS t j d   n  | j |  } n  | |  j k r |  j | } n | s | j r t j d   n  | j	 j
   } t j |  }	 | |	 _ |  j |	  t } nY t j | d  s| j r5t j | d  r5|  j | j  j | d  } n d  } | d  k r| j	 j
   } t j |  }	 t j |  }
 t } |  j |	  n t j |  }	 t j |  }
 | | | <| |	 k	 r| j d  k	 ra| j | | | j d t j } | j |	 |
 | j d t j } | t j k	 ra| t j k	 ra| | k rat j d | t |	  | f   qan  | j |	 _ | j  |	 _  x3 | j! D]% } | j" |  | | |	 |
 | |  qWn  | s|	 j# |
 |  j  n  | r|	 j$ j% j& |	 d   n  | S(   Ns   merge() with load=False option does not support objects transient (i.e. unpersisted) objects.  flush() all changes on mapped instances before merging with load=False.s   merge() with load=False option does not support objects marked as 'dirty'.  flush() all changes on mapped instances before merging with load=False.i   t   passives   Version id '%s' on merged state %s does not match existing version '%s'. Leave the version attribute unset when merging to update the most recent version.('   R   R   R_   R   R8   R9   R   Ra   Rh   t   class_managert   new_instanceR   R   Re   Rf   R   R   R   R   R   t   class_t   getR  R  t   version_id_colt   _get_state_attr_by_columnt   PASSIVE_NO_INITIALIZEt   PASSIVE_NO_RESULTR   t   StaleDataErrorR   t	   load_patht   load_optionst   iterate_propertiesR   t   _commit_allR   R<   R  (   R>   R   t
   state_dictR  R  R   R  R_   t   mergedt   merged_statet   merged_dictt   existing_versiont   merged_versiont   prop(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR  Q  s    					"
			c         C   s2   |  j  j |  s. t j d t |    n  d  S(   Ns3   Instance '%s' is not persistent within this Session(   Ra   R   R8   R9   R   (   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    c         C   s   | j  d  k	 r+ t j d t |    n  |  j |  | |  j k ro | j   |  j | <t |  j  | _	 n  |  j
 |  d  S(   NsG   Object '%s' already has an identity - it can't be registered as pending(   R_   R   R8   R9   R   t   _before_attachRR   R   t   lent   insert_orderR  (   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt
   _save_impl  s    c         C   s   |  j  j |  r% | |  j k r% d  S| j d  k rP t j d t |    n  | j ru t j d t |    n  |  j	 |  |  j j
 | d   | r |  j  j |  n |  j  j |  |  j |  d  S(   Ns   Instance '%s' is not persistedss   Instance '%s' has been deleted.  Use the make_transient() function to send this object back to the transient state.(   Ra   R   RS   R_   R   R8   R9   R   Rd   R+  R   Rc   R   R  (   R>   R   RZ   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyRe     s"    	c         C   s0   | j  d  k r |  j |  n |  j |  d  S(   N(   R_   R   R.  Re   (   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR    s    c         C   s`   | |  j  k r d  S| j d  k r& d  S|  j | d t | j   |  j  | <|  j j |  d  S(   NR  (   RS   R_   R   R  Rf   R   Ra   R   (   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR    s    c         C   s/   t  j |  } |  j | d t t | _ d S(   s  Associate an object with this :class:`.Session` for related
        object loading.

        .. warning::

            :meth:`.enable_relationship_loading` exists to serve special
            use cases and is not recommended for general use.

        Accesses of attributes mapped with :func:`.relationship`
        will attempt to load a value from the database using this
        :class:`.Session` as the source of connectivity.  The values
        will be loaded based on foreign key values present on this
        object - it follows that this functionality
        generally only works for many-to-one-relationships.

        The object will be attached to this session, but will
        **not** participate in any persistence operations; its state
        for almost all purposes will remain either "transient" or
        "detached", except for the case of relationship loading.

        Also note that backrefs will often not work as expected.
        Altering a relationship-bound attribute on the target object
        may not fire off a backref event, if the effective value
        is what was already loaded from a foreign-key-holding value.

        The :meth:`.Session.enable_relationship_loading` method is
        similar to the ``load_on_pending`` flag on :func:`.relationship`.
        Unlike that flag, :meth:`.Session.enable_relationship_loading` allows
        an object to remain transient while still being able to load
        related items.

        To make a transient object associated with a :class:`.Session`
        via :meth:`.Session.enable_relationship_loading` pending, add
        it to the :class:`.Session` using :meth:`.Session.add` normally.

        :meth:`.Session.enable_relationship_loading` does not improve
        behavior when the ORM is used normally - object references should be
        constructed at the object level, not at the foreign key level, so
        that they are present in an ordinary way before flush()
        proceeds.  This method is not intended for general use.

        .. versionadded:: 0.8

        .. seealso::

            ``load_on_pending`` at :func:`.relationship` - this flag
            allows per-relationship loading of many-to-ones on items that
            are pending.

        R  N(   R   R   R  Rf   t   _load_pending(   R>   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   enable_relationship_loading  s    3c         C   s>   | j  |  j k r: |  j j r: |  j j |  | j    n  d  S(   N(   R   R   R<   t   before_attachR   (   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR+  %  s    c      	   C   sM  | j  rS | j  |  j k rS |  j j |  rS t j d t |  | j  f   n  | j r | j |  j k	 r | j t k r t j d t |  | j |  j f   n  | j |  j k rI| r |  j	 j
 r |  j	 j
 |  | j    n  |  j | _ | j r| j d  k r| j   | _ n  |  j	 j rI|  j	 j |  | j    qIn  d  S(   NsZ   Can't attach instance %s; another instance with key %s is already present in this session.s>   Object '%s' is already attached to session '%s' (this is '%s')(   R_   Ra   R   R8   R9   R   R   R   R   R<   R1  R   Rh   t   _strong_objR   t   after_attach(   R>   R   R  (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR  *  s,    			c         C   sF   y t  j |  } Wn# t j k
 r8 t j |   n X|  j |  S(   s   Return True if the instance is associated with this session.

        The instance may be pending or persistent within the Session for a
        result of True.

        (   R   R   R   R   R   R  (   R>   R(   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR   E  s
    c         C   s,   t  t |  j j    t |  j j     S(   sW   Iterate over all pending or persistent instances within this
        Session.

        (   t   iterR   RR   R   Ra   (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR   R  s    c         C   s   | |  j  k p |  j j |  S(   N(   RR   Ra   R   (   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR  Z  s    c         C   sV   |  j  r t j d   n  |  j   r+ d Sz t |  _  |  j |  Wd t |  _  Xd S(   s  Flush all the object changes to the database.

        Writes out all pending object creations, deletions and modifications
        to the database as INSERTs, DELETEs, UPDATEs, etc.  Operations are
        automatically ordered by the Session's unit of work dependency
        solver.

        Database operations will be issued in the current transactional
        context and do not affect the state of the transaction, unless an
        error occurs, in which case the entire transaction is rolled back.
        You may flush() as often as you like within a transaction to move
        changes from Python to the database's transaction buffer.

        For ``autocommit`` Sessions with no active manual transaction, flush()
        will create a transaction on the fly that surrounds the entire set of
        operations int the flush.

        :param objects: Optional; restricts the flush operation to operate
          only on elements that are in the given collection.

          This feature is for an extremely narrow set of use cases where
          particular objects may need to be operated upon before the
          full flush() occurs.  It is not intended for general use.

        s   Session is already flushingN(   RV   R8   R9   R   Rf   t   _flushR   (   R>   t   objects(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyRW   ]  s    		c         C   s   t  j d |  d  S(   Ns   Usage of the '%s' operation is not currently supported within the execution stage of the flush process. Results may not be consistent.  Consider using alternative event listeners or connection-level operations instead.(   R    R   (   R>   t   method(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR    s    c         C   s"   |  j  j   o! |  j o! |  j S(   N(   Ra   t   check_modifiedRS   RR   (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    
c      	   C   s/  |  j  } | r8 |  j r8 |  j r8 |  j j j   d  St |   } |  j j rr |  j j |  | |  |  j  } n  t	 |  j  } t	 |  j  } t	 |  j
 |  } | rt	   } x] | D]L } y t j |  } Wn# t j k
 r t j |   n X| j |  q Wn d  } t	   }	 | rG| j |  j |  j
 |  }
 n | j |  j
 |  }
 xL |
 D]D } t |  j |  o| j } | j | d | |	 j |  qfW| r| j |  j
 |	  }
 n | j
 |	  }
 x! |
 D] } | j | d t qW| j sd  S|  j d t  | _ } y t |  _ z | j   Wd  t |  _ X|  j j |  |  | j    | r|  j j rt! |  j j  } t" j# j$ g  |  j j D] } | | j% f ^ qd |  j t& j' d |  n  |  j j( |  |  | j)   Wn* t& j*    | j+ d t  Wd  QXn Xd  S(   Nt   isdeleteR   R  s   Attribute history events accumulated on %d previously clean instances within inner-flush event handlers have been reset, and will not result in database updates. Consider using set_committed_value() within inner-flush event handlers to avoid this warning.R   (,   t   _dirty_statesRS   RR   Ra   Rk   Rr   R   R<   t   before_flushR\   t
   differenceR   R   R   R   R   R   R   R]   R  R   t
   _is_orphant   has_identityt   register_objectRf   t   has_workR{   R~   R   R   R   t   after_flusht   finalize_flush_changesR,  R   R   R   Rj   R    R   t   after_flush_postexecR   R   R   (   R>   R6  t   dirtyt   flush_contextRd   t   newt   objsetR   R   t	   processedt   proct	   is_orphanR~   t   len_(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR5    sr    			$			

	%
		c   
      C   s   t  |  } | j s t S| j } x | j j D]o } | rN t | j d  s/ t | j d  rg q/ n  | j j | | d t j	 \ } } }	 | s |	 r/ t
 Sq/ Wt Sd S(   s  Return ``True`` if the given instance has locally
        modified attributes.

        This method retrieves the history for each instrumented
        attribute on the instance and performs a comparison of the current
        value to its previously committed value, if any.

        It is in effect a more expensive and accurate
        version of checking for the given instance in the
        :attr:`.Session.dirty` collection; a full test for
        each attribute's net "dirty" status is performed.

        E.g.::

            return session.is_modified(someobject)

        .. versionchanged:: 0.8
            When using SQLAlchemy 0.7 and earlier, the ``passive``
            flag should **always** be explicitly set to ``True``,
            else SQL loads/autoflushes may proceed which can affect
            the modified state itself:
            ``session.is_modified(someobject, passive=True)``\ .
            In 0.8 and above, the behavior is corrected and
            this flag is ignored.

        A few caveats to this method apply:

        * Instances present in the :attr:`.Session.dirty` collection may
          report ``False`` when tested with this method.  This is because
          the object may have received change events via attribute mutation,
          thus placing it in :attr:`.Session.dirty`, but ultimately the state
          is the same as that loaded from the database, resulting in no net
          change here.
        * Scalar attributes may not have recorded the previously set
          value when a new value was applied, if the attribute was not loaded,
          or was expired, at the time the new value was received - in these
          cases, the attribute is assumed to have a change, even if there is
          ultimately no net change against its database value. SQLAlchemy in
          most cases does not need the "old" value when a set event occurs, so
          it skips the expense of a SQL call if the old value isn't present,
          based on the assumption that an UPDATE of the scalar value is
          usually needed, and in those few cases where it isn't, is less
          expensive on average than issuing a defensive SELECT.

          The "old" value is fetched unconditionally upon set only if the
          attribute container has the ``active_history`` flag set to ``True``.
          This flag is set typically for primary key attributes and scalar
          object references that are not a simple many-to-one.  To set this
          flag for any arbitrary mapped column, use the ``active_history``
          argument with :func:`.column_property`.

        :param instance: mapped instance to be tested for pending changes.
        :param include_collections: Indicates if multivalued collections
         should be included in the operation.  Setting this to ``False`` is a
         way to detect only local-column based properties (i.e. scalar columns
         or many-to-one foreign keys) that would result in an UPDATE for this
         instance upon flush.
        :param passive:
         .. versionchanged:: 0.8
             Ignored for backwards compatibility.
             When using SQLAlchemy 0.7 and earlier, this flag should always
             be set to ``True``.

        t   get_collectiont   get_historyR  N(   R   Rh   R   Rj   R   R   t   hasattrt   implRM  t	   NO_CHANGERf   (
   R>   R(   t   include_collectionsR  R   t   dict_t   attrt   addedt	   unchangedRd   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s    B		c         C   s   |  j  o |  j  j S(   s+  True if this :class:`.Session` is in "transaction mode" and
        is not in "partial rollback" state.

        The :class:`.Session` in its default mode of ``autocommit=False``
        is essentially always in "transaction mode", in that a
        :class:`.SessionTransaction` is associated with it as soon as
        it is instantiated.  This :class:`.SessionTransaction` is immediately
        replaced with a new one as soon as it is ended, due to a rollback,
        commit, or close operation.

        "Transaction mode" does *not* indicate whether
        or not actual database connection resources are in use;  the
        :class:`.SessionTransaction` object coordinates among zero or more
        actual database transactions, and starts out with none, accumulating
        individual DBAPI connections as different data sources are used
        within its scope.   The best way to track when a particular
        :class:`.Session` has actually begun to use DBAPI resources is to
        implement a listener using the :meth:`.SessionEvents.after_begin`
        method, which will deliver both the :class:`.Session` as well as the
        target :class:`.Connection` to a user-defined event listener.

        The "partial rollback" state refers to when an "inner" transaction,
        typically used during a flush, encounters an error and emits a
        rollback of the DBAPI connection.  At this point, the
        :class:`.Session` is in "partial rollback" and awaits for the user to
        call :meth:`.Session.rollback`, in order to close out the
        transaction stack.  It is in this "partial rollback" period that the
        :attr:`.is_active` flag returns False.  After the call to
        :meth:`.Session.rollback`, the :class:`.SessionTransaction` is
        replaced with a new one and :attr:`.is_active` returns ``True`` again.

        When a :class:`.Session` is used in ``autocommit=True`` mode, the
        :class:`.SessionTransaction` is only instantiated within the scope
        of a flush call, or when :meth:`.Session.begin` is called.  So
        :attr:`.is_active` will always be ``False`` outside of a flush or
        :meth:`.Session.begin` block in this mode, and will be ``True``
        within the :meth:`.Session.begin` block as long as it doesn't enter
        "partial rollback" state.

        From all the above, it follows that the only purpose to this flag is
        for application frameworks that wish to detect is a "rollback" is
        necessary within a generic error handling routine, for
        :class:`.Session` objects that would otherwise be in
        "partial rollback" mode.  In a typical integration case, this is also
        not necessary as it is standard practice to emit
        :meth:`.Session.rollback` unconditionally within the outermost
        exception catch.

        To track the transactional state of a :class:`.Session` fully,
        use event listeners, primarily the :meth:`.SessionEvents.after_begin`,
        :meth:`.SessionEvents.after_commit`,
        :meth:`.SessionEvents.after_rollback` and related events.

        (   R~   RA   (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyRA   Q  s    8c         C   s   |  j  j   S(   s   The set of all persistent states considered dirty.

        This method returns all states that were modified including
        those that were possibly deleted.

        (   Ra   R:  (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR:    s    c         C   s8   t  j g  |  j D]! } | |  j k r | j   ^ q  S(   sZ  The set of all persistent instances considered dirty.

        E.g.::

            some_mapped_object in session.dirty

        Instances are considered dirty when they were modified but not
        deleted.

        Note that this 'dirty' calculation is 'optimistic'; most
        attribute-setting or collection modification operations will
        mark an instance as 'dirty' and place it in this set, even if
        there is no net change to the attribute's value.  At flush
        time, the value of each attribute is compared to its
        previously saved value, and if there's no net change, no SQL
        operation will occur (this is a more expensive operation so
        it's only done at flush time).

        To check if an instance has actionable net changes to its
        attributes, use the :meth:`.Session.is_modified` method.

        (   R    t   IdentitySetR:  RS   R   (   R>   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyRD    s    c         C   s   t  j t |  j j     S(   sD   The set of all instances marked as 'deleted' within this ``Session``(   R    RV  R   RS   R   (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyRd     s    c         C   s   t  j t |  j j     S(   sA   The set of all instances marked as 'new' within this ``Session``.(   R    RV  R   RR   R   (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyRF    s    (   s   __contains__s   __iter__s   adds   add_alls   begins   begin_nesteds   closes   commits
   connections   deletes   executes   expires
   expire_alls   expunges   expunge_alls   flushs   get_binds   is_modifieds   merges   querys   refreshs   rollbacks   scalarN(I   R)   R*   R+   t   public_methodsR   Rf   R   R   t   QueryR@   t   connection_callableR~   R    t   memoized_propertyR   R{   Rz   R   R   R   RN   RK   R   R   R   R   R   R   RJ   R   t   contextmanagerR   R   R   R   R   R   R   t
   deprecatedR   R   R^   R  R   R  R   R   R  R   R   R  R   R.  Re   R  R  R0  R+  R  R   R   R  RW   R  R   R5  R   RA   Ra   R:  RD  Rd   RF  (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s        					$	9					^		4	!)						3						
	'Ab					7				&		gY:
c           B   sD   e  Z d  Z d e e e e d d  Z d   Z d   Z	 d   Z
 RS(   s'  A configurable :class:`.Session` factory.

    The :class:`.sessionmaker` factory generates new
    :class:`.Session` objects when called, creating them given
    the configurational arguments established here.

    e.g.::

        # global scope
        Session = sessionmaker(autoflush=False)

        # later, in a local scope, create and use a session:
        sess = Session()

    Any keyword arguments sent to the constructor itself will override the
    "configured" keywords::

        Session = sessionmaker()

        # bind an individual session to a connection
        sess = Session(bind=connection)

    The class also includes a method :meth:`.configure`, which can
    be used to specify additional keyword arguments to the factory, which
    will take effect for subsequent :class:`.Session` objects generated.
    This is usually used to associate one or more :class:`.Engine` objects
    with an existing :class:`.sessionmaker` factory before it is first
    used::

        # application starts
        Session = sessionmaker()

        # ... later
        engine = create_engine('sqlite:///foo.db')
        Session.configure(bind=engine)

        sess = Session()

    .. seealso:

        :ref:`session_getting` - introductory text on creating
        sessions using :class:`.sessionmaker`.

    c         K   si   | | d <| | d <| | d <| | d <| d k	 rA | | d <n  | |  _ t | j | f i   |  _ d S(   s8  Construct a new :class:`.sessionmaker`.

        All arguments here except for ``class_`` correspond to arguments
        accepted by :class:`.Session` directly.  See the
        :meth:`.Session.__init__` docstring for more details on parameters.

        :param bind: a :class:`.Engine` or other :class:`.Connectable` with
         which newly created :class:`.Session` objects will be associated.
        :param class_: class to use in order to create new :class:`.Session`
         objects.  Defaults to :class:`.Session`.
        :param autoflush: The autoflush setting to use with newly created
         :class:`.Session` objects.
        :param autocommit: The autocommit setting to use with newly created
         :class:`.Session` objects.
        :param expire_on_commit=True: the expire_on_commit setting to use
         with newly created :class:`.Session` objects.
        :param info: optional dictionary of information that will be available
         via :attr:`.Session.info`.  Note this dictionary is *updated*, not
         replaced, when the ``info`` parameter is specified to the specific
         :class:`.Session` construction operation.

         .. versionadded:: 0.9.0

        :param \**kw: all other keyword arguments are passed to the
         constructor of newly created :class:`.Session` objects.

        RM   R   R   Rq   R   N(   R   R   R   R)   R  (   R>   RM   R  R   R   Rq   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR@     s    



	c         K   s   xo |  j  j   D]^ \ } } | d k r^ d | k r^ | j   } | j | d  | | d <q | j | |  q W|  j |   S(   se  Produce a new :class:`.Session` object using the configuration
        established in this :class:`.sessionmaker`.

        In Python, the ``__call__`` method is invoked on an object when
        it is "called" in the same way as a function::

            Session = sessionmaker()
            session = Session()  # invokes sessionmaker.__call__()

        R   (   R   R`   t   copyRs   t
   setdefaultR  (   R>   t   local_kwt   kt   vt   d(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   __call__&	  s    c         K   s   |  j  j |  d S(   s   (Re)configure the arguments for this sessionmaker.

        e.g.::

            Session = sessionmaker()

            Session.configure(bind=create_engine('sqlite://'))
        N(   R   Rs   (   R>   t   new_kw(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt	   configure:	  s    	c         C   s9   d |  j  j |  j j d j d   |  j j   D  f S(   Ns   %s(class_=%r,%s)s   , c         s   s%   |  ] \ } } d  | | f Vq d S(   s   %s=%rN(    (   R   R`  Ra  (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pys	   <genexpr>I	  s    (   t	   __class__R)   R  R   R   R`   (   R>   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   __repr__E	  s    		N(   R)   R*   R+   R   R   Rf   R   R@   Rc  Re  Rg  (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR     s   -	'		c         C   sf   t  j |   } t |  } | r1 | j |  n  | j j   | j rP | ` n  | j rb | ` n  d S(   s  Make the given instance 'transient'.

    This will remove its association with any
    session and additionally will remove its "identity key",
    such that it's as though the object were newly constructed,
    except retaining its values.   It also resets the
    "deleted" flag on the state if this object
    had been explicitly deleted by its session.

    Attributes which were "expired" or deferred at the
    instance level are reverted to undefined, and
    will not trigger any loads.

    N(   R   R   R   R^   t	   callablesRr   R_   Rd   (   R(   R   Rm   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   make_transientM	  s    			c         C   s   t  j |   } | j s! | j r3 t j d   n  | j j |  | _ | j rZ | ` n  | j	 | j
  | j | j
 | j  d S(   s  Make the given transient instance 'detached'.

    All attribute history on the given instance
    will be reset as though the instance were freshly loaded
    from a query.  Missing attributes will be marked as expired.
    The primary key attributes of the object, which are required, will be made
    into the "key" of the instance.

    The object can then be added to a session, or merged
    possibly with the load=False flag, at which point it will look
    as if it were loaded that way, without emitting SQL.

    This is a special use case function that differs from a normal
    call to :meth:`.Session.merge` in that a given persistent state
    can be manufactured without any SQL calls.

    .. versionadded:: 0.9.5

    .. seealso::

        :func:`.make_transient`

    s   Given object must be transientN(   R   R   R   R_   R8   R9   R   R   Rd   R#  Rj   R   t   unloaded(   R(   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   make_transient_to_detachedj	  s    		c         C   sA   y t  t j |    SWn# t j k
 r< t j |    n Xd S(   sz   Return the ``Session`` to which instance belongs.

    If the instance is not a mapped instance, an error is raised.

    N(   R   R   R   R   R   R   (   R(   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyR'   	  s    (3   R+   RX   t    R    R   R   R   R8   R   R   R   R   R   R   R	   t
   inspectionR
   t   baseR   R   R   R   R   R   R   R   t
   unitofworkR   R   R   R   t   __all__t   WeakValueDictionaryR   R   t   objectR   t   symbolR.   R/   R0   R1   R2   R   R   R   Ri  Rk  R'   t   counterR   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/session.pyt   <module>   sB   ".:	        		#	