
H`Tc           @   s  d  Z  d d l Z d d l Z d d l Z d d l m Z m Z m Z m Z m	 Z	 d d l	 m
 Z d d l	 m Z m Z m Z d d l m Z i  Z d   Z d	   Z e	 j d
  Z e	 j d  Z e	 j d  Z d e f d     YZ d e j f d     YZ d e f d     YZ e d  Z e   Z  d e f d     YZ! d e f d     YZ" d e f d     YZ# d e f d     YZ$ d e f d     YZ% d e f d     YZ& d  e f d!     YZ' d S("   s{  Connection pooling for DB-API connections.

Provides a number of connection pool implementations for a variety of
usage scenarios and thread behavior requirements imposed by the
application, DB-API or database itself.

Also provides a DB-API 2.0 connection proxying mechanism allowing
regular DB-API connect() methods to be transparently managed by a
SQLAlchemy connection pool.
iNi   (   t   exct   logt   eventt
   interfacest   util(   t   queue(   t	   threadingt   memoized_propertyt   chop_traceback(   t   dequec         K   s:   y t  |  SWn' t k
 r5 t  j |  t |  |   SXd S(   sI  Return a proxy for a DB-API module that automatically
    pools connections.

    Given a DB-API 2.0 module and pool management parameters, returns
    a proxy for the module that will automatically pool connections,
    creating new connection pools for each distinct set of connection
    arguments sent to the decorated module's connect() function.

    :param module: a DB-API 2.0 database module

    :param poolclass: the class used by the pool module to provide
      pooling.  Defaults to :class:`.QueuePool`.

    :param \*\*params: will be passed through to *poolclass*

    N(   t   proxiest   KeyErrort
   setdefaultt   _DBProxy(   t   modulet   params(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   manage!   s    c          C   s/   x t  j   D] }  |  j   q Wt  j   d S(   sY   Remove all current DB-API 2.0 managers.

    All pools and connections are disposed.
    N(   R
   t   valuest   closet   clear(   t   manager(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   clear_managers8   s    t   reset_rollbackt   reset_committ
   reset_nonet   _ConnDialectc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s   partial implementation of :class:`.Dialect`
    which provides DBAPI connection methods.

    When a :class:`.Pool` is combined with an :class:`.Engine`,
    the :class:`.Engine` replaces this with its own
    :class:`.Dialect`.

    c         C   s   | j    d  S(   N(   t   rollback(   t   selft   dbapi_connection(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   do_rollbackR   s    c         C   s   | j    d  S(   N(   t   commit(   R   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt	   do_commitU   s    c         C   s   | j    d  S(   N(   R   (   R   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   do_closeX   s    (   t   __name__t
   __module__t   __doc__R   R   R    (    (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR   G   s   			t   Poolc        
   B   s   e  Z d  Z e   Z d d e d e d d d d d 	 Z d   Z	 e
 j d d  d    Z d   Z d   Z d d	  Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s)   Abstract base class for connection pools.ic         C   s  | r | |  _  |  _ n	 d |  _ t j |  d | t j   |  _ | |  _ | |  _	 d |  _
 | |  _ | d t t f k r t |  _ nR | d t t f k r t |  _ n1 | d t f k r t |  _ n t j d |   | |  _ |	 r|  j j |	 d t n  |
 r|
 |  _ n  | rHx* | D] \ } } t j |  | |  q"Wn  | r|t j d  x | D] } |  j |  qbWn  d S(	   s{  
        Construct a Pool.

        :param creator: a callable function that returns a DB-API
          connection object.  The function will be called with
          parameters.

        :param recycle: If set to non -1, number of seconds between
          connection recycling, which means upon checkout, if this
          timeout is surpassed the connection will be closed and
          replaced with a newly opened connection. Defaults to -1.

        :param logging_name:  String identifier which will be used within
          the "name" field of logging records generated within the
          "sqlalchemy.pool" logger. Defaults to a hexstring of the object's
          id.

        :param echo: If True, connections being pulled and retrieved
          from the pool will be logged to the standard output, as well
          as pool sizing information.  Echoing can also be achieved by
          enabling logging for the "sqlalchemy.pool"
          namespace. Defaults to False.

        :param use_threadlocal: If set to True, repeated calls to
          :meth:`connect` within the same application thread will be
          guaranteed to return the same connection object, if one has
          already been retrieved from the pool and has not been
          returned yet.  Offers a slight performance advantage at the
          cost of individual transactions by default.  The
          :meth:`.Pool.unique_connection` method is provided to return
          a consistenty unique connection to bypass this behavior
          when the flag is set.

          .. warning::  The :paramref:`.Pool.use_threadlocal` flag
             **does not affect the behavior** of :meth:`.Engine.connect`.
             :meth:`.Engine.connect` makes use of the
             :meth:`.Pool.unique_connection` method which **does not use thread
             local context**.  To produce a :class:`.Connection` which refers
             to the :meth:`.Pool.connect` method, use
             :meth:`.Engine.contextual_connect`.

             Note that other SQLAlchemy connectivity systems such as
             :meth:`.Engine.execute` as well as the orm
             :class:`.Session` make use of
             :meth:`.Engine.contextual_connect` internally, so these functions
             are compatible with the :paramref:`.Pool.use_threadlocal` setting.

          .. seealso::

            :ref:`threadlocal_strategy` - contains detail on the
            "threadlocal" engine strategy, which provides a more comprehensive
            approach to "threadlocal" connectivity for the specific
            use case of using :class:`.Engine` and :class:`.Connection` objects
            directly.

        :param reset_on_return: Determine steps to take on
          connections as they are returned to the pool.
          reset_on_return can have any of these values:

          * ``"rollback"`` - call rollback() on the connection,
            to release locks and transaction resources.
            This is the default value.  The vast majority
            of use cases should leave this value set.
          * ``True`` - same as 'rollback', this is here for
            backwards compatibility.
          * ``"commit"`` - call commit() on the connection,
            to release locks and transaction resources.
            A commit here may be desirable for databases that
            cache query plans if a commit is emitted,
            such as Microsoft SQL Server.  However, this
            value is more dangerous than 'rollback' because
            any data changes present on the transaction
            are committed unconditionally.
          * ``None`` - don't do anything on the connection.
            This setting should only be made on a database
            that has no transaction support at all,
            namely MySQL MyISAM.   By not doing anything,
            performance can be improved.   This
            setting should **never be selected** for a
            database that supports transactions,
            as it will lead to deadlocks and stale
            state.
          * ``False`` - same as None, this is here for
            backwards compatibility.

          .. versionchanged:: 0.7.6
              :paramref:`.Pool.reset_on_return` accepts ``"rollback"``
              and ``"commit"`` arguments.

        :param events: a list of 2-tuples, each of the form
         ``(callable, target)`` which will be passed to :func:`.event.listen`
         upon construction.   Provided here so that event listeners
         can be assigned via :func:`.create_engine` before dialect-level
         listeners are applied.

        :param listeners: Deprecated.  A list of
          :class:`~sqlalchemy.interfaces.PoolListener`-like objects or
          dictionaries of callables that receive events when DB-API
          connections are created, checked out and checked in to the
          pool.  This has been superseded by
          :func:`~sqlalchemy.event.listen`.

        t   echoflagi    R   R   s'   Invalid value for 'reset_on_return': %rt   only_propagatesZ   The 'listeners' argument to Pool (and create_engine()) is deprecated.  Use event.listen().N(   t   logging_namet   _orig_logging_namet   NoneR   t   instance_loggerR   t   localt   _threadconnst   _creatort   _recyclet   _invalidate_timet   _use_threadlocalt   TrueR   t   _reset_on_returnt   FalseR   R   R    t   ArgumentErrort   echot   dispatcht   _updatet   _dialectR   t   listenR   t   warn_deprecatedt   add_listener(   R   t   creatort   recycleR5   t   use_threadlocalR'   t   reset_on_returnt	   listenerst   eventst	   _dispatchR8   t   fnt   targett   l(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   __init__b   s>    p					
	c         C   sg   |  j  j d |  y |  j j |  Wn9 t t f k
 rC   n  |  j  j d | d t n Xd  S(   Ns   Closing connection %rs   Exception closing connection %rt   exc_info(   t   loggert   debugR8   R    t
   SystemExitt   KeyboardInterruptt   errorR1   (   R   t
   connection(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   _close_connection   s    g@s4   Pool.add_listener is deprecated.  Use event.listen()c         C   s   t  j j |  |  d S(   s  Add a :class:`.PoolListener`-like object to this pool.

        ``listener`` may be an object that implements some or all of
        PoolListener, or a dictionary of callables containing implementations
        of some or all of the named methods in PoolListener.

        N(   R   t   PoolListenert   _adapt_listener(   R   t   listener(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR;     s    
c         C   s   t  j |   S(   s  Produce a DBAPI connection that is not referenced by any
        thread-local context.

        This method is equivalent to :meth:`.Pool.connect` when the
        :paramref:`.Pool.use_threadlocal` flag is not set to True.
        When :paramref:`.Pool.use_threadlocal` is True, the
        :meth:`.Pool.unique_connection` method provides a means of bypassing
        the threadlocal context.

        (   t   _ConnectionFairyt	   _checkout(   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   unique_connection  s    c         C   s
   t  |   S(   s6   Called by subclasses to create a new ConnectionRecord.(   t   _ConnectionRecord(   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   _create_connection  s    c         C   sc   t  | d d  } | s+ |  j | j k  r= t j   |  _ n  t  | d t  r_ | j |  n  d S(   s  Mark all connections established within the generation
        of the given connection as invalidated.

        If this pool's last invalidate time is before when the given
        connection was created, update the timestamp til now.  Otherwise,
        no action is performed.

        Connections with a start time prior to this pool's invalidation
        time will be recycled upon next checkout.
        t   _connection_recordt   is_validN(   t   getattrR)   R/   t	   starttimet   timeR3   t
   invalidate(   R   RM   t	   exceptiont   rec(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   _invalidate  s
    c         C   s   t     d S(   s  Return a new :class:`.Pool`, of the same class as this one
        and configured with identical creation arguments.

        This method is used in conjunction with :meth:`dispose`
        to close out an entire :class:`.Pool` and create a new one in
        its place.

        N(   t   NotImplementedError(   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   recreate0  s    
c         C   s   t     d S(   s   Dispose of this pool.

        This method leaves the possibility of checked-out connections
        remaining open, as it only affects connections that are
        idle in the pool.

        See also the :meth:`Pool.recreate` method.

        N(   R`   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   dispose<  s    c         C   sf   |  j  s t j |   Sy |  j j   } Wn t k
 r< n X| d k	 rS | j   St j |  |  j  S(   s   Return a DBAPI connection from the pool.

        The connection is instrumented such that when its
        ``close()`` method is called, the connection will be returned to
        the pool.

        N(   R0   RR   RS   R,   t   currentt   AttributeErrorR)   t   _checkout_existing(   R   R^   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   connectI  s    	
c         C   s>   |  j  r- y |  j ` Wq- t k
 r) q- Xn  |  j |  d S(   s   Given a _ConnectionRecord, return it to the :class:`.Pool`.

        This method is called when an instrumented DBAPI connection
        has its ``close()`` method called.

        N(   R0   R,   Rc   Rd   t   _do_return_conn(   R   t   record(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   _return_conn^  s    	c         C   s   t     d S(   s7   Implementation for :meth:`get`, supplied by subclasses.N(   R`   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   _do_getl  s    c         C   s   t     d S(   s?   Implementation for :meth:`return_conn`, supplied by subclasses.N(   R`   (   R   t   conn(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRg   q  s    c         C   s   t     d  S(   N(   R`   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   statusv  s    N(   R!   R"   R#   R   R8   R)   R3   R1   RF   RN   R   t
   deprecatedR;   RT   RV   R_   Ra   Rb   Rf   Ri   Rj   Rg   Rl   (    (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR$   \   s.   		
								RU   c           B   sw   e  Z d  Z d   Z d
 Z e j d    Z e	 d    Z
 d   Z d   Z d
 d  Z d   Z d   Z d	   Z RS(   s  Internal object which maintains an individual DBAPI connection
    referenced by a :class:`.Pool`.

    The :class:`._ConnectionRecord` object always exists for any particular
    DBAPI connection whether or not that DBAPI connection has been
    "checked out".  This is in contrast to the :class:`._ConnectionFairy`
    which is only a public facade to the DBAPI connection while it is checked
    out.

    A :class:`._ConnectionRecord` may exist for a span longer than that
    of a single DBAPI connection.  For example, if the
    :meth:`._ConnectionRecord.invalidate`
    method is called, the DBAPI connection associated with this
    :class:`._ConnectionRecord`
    will be discarded, but the :class:`._ConnectionRecord` may be used again,
    in which case a new DBAPI connection is produced when the :class:`.Pool`
    next uses this record.

    The :class:`._ConnectionRecord` is delivered along with connection
    pool events, including :meth:`.PoolEvents.connect` and
    :meth:`.PoolEvents.checkout`, however :class:`._ConnectionRecord` still
    remains an internal object whose API and internals may change.

    .. seealso::

        :class:`._ConnectionFairy`

    c         C   sc   | |  _  |  j   |  _ t   |  _ | j j j | j  j |  j |   | j j	 |  j |   d  S(   N(
   t   _ConnectionRecord__poolt   _ConnectionRecord__connectRM   R	   t   finalize_callbackR6   t   first_connectt
   for_modifyt	   exec_onceRf   (   R   t   pool(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRF     s    	c         C   s   i  S(   s   The ``.info`` dictionary associated with the DBAPI connection.

        This dictionary is shared among the :attr:`._ConnectionFairy.info`
        and :attr:`.Connection.info` accessors.

        (    (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   info  s    c            s    j     y  j     Wn  j     n X j    t      } t j |      f d     _ t j	    r  j
 j d    n  | S(   Nc            s   t  o t      |    S(   N(   t   _finalize_fairy(   t   ref(   R   R5   R^   Rt   (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   <lambda>  s   s#   Connection %r checked out from pool(   Rj   t   get_connectiont   checkint   _should_log_debugRR   t   weakrefRw   t	   fairy_reft   _refst   addRH   RI   (   t   clsRt   t   fairy(    (   R   R5   R^   Rt   sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   checkout  s     

c         C   sw   d  |  _ |  j } |  j } x& |  j rC |  j j   } | |  q W| j j rf | j j | |   n  | j |   d  S(   N(	   R)   R}   RM   Rn   Rp   t   popR6   Rz   Ri   (   R   RM   Rt   t	   finalizer(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRz     s    			c         C   s    |  j  d  k	 r |  j   n  d  S(   N(   RM   R)   t   _ConnectionRecord__close(   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s    c         C   s   |  j  d k r d S|  j j j |  j  |  |  | d k	 rc |  j j j d |  j  | j j |  n |  j j j d |  j   |  j	   d |  _  d S(   s  Invalidate the DBAPI connection held by this :class:`._ConnectionRecord`.

        This method is called for all connection invalidations, including
        when the :meth:`._ConnectionFairy.invalidate` or
        :meth:`.Connection.invalidate` methods are called, as well as when any
        so-called "automatic invalidation" condition occurs.

        .. seealso::

            :ref:`pool_connection_invalidation`

        Ns(   Invalidate connection %r (reason: %s:%s)s   Invalidate connection %r(
   RM   R)   Rn   R6   R\   RH   Ru   t	   __class__R!   R   (   R   t   e(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR\     s    
c         C   sN  t  } |  j d  k r_ |  j   |  _ |  j j   |  j j j r |  j j j |  j |   q n |  j j	 d k r t
 j
   |  j |  j j	 k r |  j j j d |  j  t } n; |  j j |  j k r |  j j j d d |  j  t } n  | rG|  j   |  j   |  _ |  j j   |  j j j rG|  j j j |  j |   qGn  |  j S(   Nis)   Connection %r exceeded timeout; recyclings4   Connection %r invalidated due to pool invalidation; t	   recycling(   R3   RM   R)   Ro   Ru   R   Rn   R6   Rf   R.   R[   RZ   RH   R1   R/   R   (   R   R=   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRy     s2    
	
	
c         C   s   |  j  j |  j  d  S(   N(   Rn   RN   RM   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   __close  s    c         C   so   y< t  j    |  _ |  j j   } |  j j j d |  | SWn, t k
 rj } |  j j j d |    n Xd  S(   Ns   Created new connection %rs   Error on connect(): %s(   R[   RZ   Rn   R-   RH   RI   t	   Exception(   R   RM   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt	   __connect  s    N(   R!   R"   R#   RF   R)   RM   R   R   Ru   t   classmethodR   Rz   R   R\   Ry   R   Ro   (    (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRU   z  s   	
	
				c         C   s(  t  j |  | d k	 r, | j | k	 r, d S|  d k	 r| rZ | rZ | j j d |   n  yT | pr t |  | |  } | j |  k s t  | j	 |  | s | j
 |   n  Wqt k
 r} | j j d d t | r | j d |  n  t | t t f  r  qqXn  | r$| j   n  d S(   sf   Cleanup for a :class:`._ConnectionFairy` whether or not it's already
    been garbage collected.

    Ns$   Connection %r being returned to pools!   Exception during reset or similarRG   R   (   R~   t   discardR)   R}   RH   RI   RR   RM   t   AssertionErrort   _resetRN   R   RL   R1   R\   t
   isinstanceRJ   RK   Rz   (   RM   t   connection_recordRt   Rw   R5   R   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRv   "  s0    
		RR   c           B   s   e  Z d  Z d   Z d Z d Z d Z e d d d   Z	 d   Z
 d   Z e Z d   Z e d    Z e d    Z e j d    Z d d	  Z d
   Z d   Z d   Z d   Z RS(   sX  Proxies a DBAPI connection and provides return-on-dereference
    support.

    This is an internal object used by the :class:`.Pool` implementation
    to provide context management to a DBAPI connection delivered by
    that :class:`.Pool`.

    The name "fairy" is inspired by the fact that the
    :class:`._ConnectionFairy` object's lifespan is transitory, as it lasts
    only for the length of a specific DBAPI connection being checked out from
    the pool, and additionally that as a transparent proxy, it is mostly
    invisible.

    .. seealso::

        :class:`._ConnectionRecord`

    c         C   s   | |  _  | |  _ | |  _ d  S(   N(   RM   RW   t   _echo(   R   R   R   R5   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRF   `  s    		c         C   s]  | sK t  j |  } | | _ d | _ | d  k	 rK t j |  | _ qK n  | j d  k rl t	 j
 d   n  | j d 7_ | j j s | j d k r | Sd } x | d k r/y$ | j j | j | j |  | SWq t	 j k
 r+} | j j d |  | j j |  | j j   | _ | d 8} q Xq W| j j d  | j   t	 j
 d   d  S(   Ni    s   This connection is closedi   i   s&   Disconnection detected on checkout: %ss+   Reconnection attempts exhausted on checkout(   RU   R   t   _poolt   _counterR)   R|   Rw   Rc   RM   R    t   InvalidRequestErrorR6   RW   t   DisconnectionErrorRH   Ru   R\   Ry   (   R   Rt   t   threadconnsR   t   attemptsR   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRS     s6    			

c         C   s   t  j |  j d |  S(   NR   (   RR   RS   R   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRe     s    c         C   s>   t  |  j |  j |  j d  |  j d |  d  |  _ d  |  _ d  S(   NR   (   Rv   RM   RW   R   R)   R   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   _checkin  s    	c         C   s  | j  j r% | j  j |  |  j  n  | j t k r |  j rh | j j d |  j |  j	 r^ d n d  n  |  j	 r |  j	 j
   q| j j |   no | j t k r|  j r | j j d |  j |  j	 r d n d  n  |  j	 r |  j	 j   q| j j |   n  d  S(   Ns"   Connection %s rollback-on-return%ss   , via agentt    s    Connection %s commit-on-return%s(   R6   t   resetRW   R2   R   R   RH   RI   RM   t   _reset_agentR   R8   R   R   R   R   (   R   Rt   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s$    				c         C   s
   |  j  j S(   N(   R   RH   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   _logger  s    c         C   s   |  j  d k	 S(   sb   Return True if this :class:`._ConnectionFairy` still refers
        to an active DBAPI connection.N(   RM   R)   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRX     s    c         C   s
   |  j  j S(   s  Info dictionary associated with the underlying DBAPI connection
        referred to by this :class:`.ConnectionFairy`, allowing user-defined
        data to be associated with the connection.

        The data here will follow along with the DBAPI connection including
        after it is returned to the connection pool and used again
        in subsequent instances of :class:`._ConnectionFairy`.  It is shared
        with the :attr:`._ConnectionRecord.info` and :attr:`.Connection.info`
        accessors.

        (   RW   Ru   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRu     s    c         C   sV   |  j  d k r  t j d  d S|  j r? |  j j d |  n  d |  _  |  j   d S(   s  Mark this connection as invalidated.

        This method can be called directly, and is also called as a result
        of the :meth:`.Connection.invalidate` method.   When invoked,
        the DBAPI connection is immediately closed and discarded from
        further use by the pool.  The invalidation mechanism proceeds
        via the :meth:`._ConnectionRecord.invalidate` internal method.

        .. seealso::

            :ref:`pool_connection_invalidation`

        s.   Can't invalidate an already-closed connection.NR   (   RM   R)   R   t   warnRW   R\   R   (   R   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR\     s    		c         O   s   |  j  j | |   S(   s   Return a new DBAPI cursor for the underlying connection.

        This method is a proxy for the ``connection.cursor()`` DBAPI
        method.

        (   RM   t   cursor(   R   t   argst   kwargs(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s    c         C   s   t  |  j |  S(   N(   RY   RM   (   R   t   key(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   __getattr__  s    c         C   sl   |  j  d k	 rh t j |  j   d |  j  _ d |  j  _ |  j j |  j   |  j j	   |  _ d |  _  n  d S(   s"  Separate this connection from its Pool.

        This means that the connection will no longer be returned to the
        pool when closed, and will instead be literally closed.  The
        containing ConnectionRecord is separated from the DB-API connection,
        and will create a new connection when next used.

        Note that any overall connection limiting constraints imposed by a
        Pool implementation may be violated after a detach, as the detached
        connection is removed from the pool's knowledge and control.
        N(
   RW   R)   R~   t   removeR}   RM   R   Rg   Ru   t   copy(   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   detach  s    c         C   s/   |  j  d 8_  |  j  d k r+ |  j   n  d  S(   Ni   i    (   R   R   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s    N(   R!   R"   R#   RF   R)   RM   RW   R   R   RS   Re   R   t   _closeR   t   propertyR   RX   R   R   Ru   R\   R   R   R   R   (    (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRR   K  s&   	$							t   SingletonThreadPoolc           B   sP   e  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(	   s  A Pool that maintains one connection per thread.

    Maintains one connection per each thread, never moving a connection to a
    thread other than the one which it was created in.

    Options are the same as those of :class:`.Pool`, as well as:

    :param pool_size: The number of threads in which to maintain connections
        at once.  Defaults to five.

    :class:`.SingletonThreadPool` is used by the SQLite dialect
    automatically when a memory-based database is used.
    See :ref:`sqlite_toplevel`.

    i   c         K   sE   t  | d <t j |  | |  t j   |  _ t   |  _ | |  _ d  S(   NR>   (	   R1   R$   RF   R   R+   t   _connt   sett
   _all_connst   size(   R   R<   t	   pool_sizet   kw(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRF   4  s
    
c         C   sh   |  j  j d  |  j |  j d |  j d |  j d |  j d |  j d |  j d |  j	 d |  j
 d	 |  j S(
   Ns   Pool recreatingR   R=   R5   R'   R>   R?   RB   R8   (   RH   Ru   R   R-   R   R.   R5   R(   R0   R2   R6   R8   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRa   ;  s    							c         C   sV   xB |  j  D]7 } y | j   Wq
 t t f k
 r:   q
 q
 Xq
 W|  j  j   d S(   s   Dispose of this pool.N(   R   R   RJ   RK   R   (   R   Rk   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRb   G  s    c         C   s<   x5 t  |  j  |  j k r7 |  j j   } | j   q Wd  S(   N(   t   lenR   R   R   R   (   R   t   c(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   _cleanupV  s    c         C   s   d t  |   t |  j  f S(   Ns"   SingletonThreadPool id:%d size: %d(   t   idR   R   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRl   [  s    c         C   s   d  S(   N(    (   R   Rk   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRg   _  s    c         C   s   y |  j  j   } | r | SWn t k
 r0 n X|  j   } t j |  |  j  _ t |  j  |  j k rw |  j	   n  |  j j
 |  | S(   N(   R   Rc   Rd   RV   R|   Rw   R   R   R   R   R   (   R   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRj   b  s    (
   R!   R"   R#   RF   Ra   Rb   R   Rl   Rg   Rj   (    (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR   "  s   					t	   QueuePoolc           B   s   e  Z d  Z d d d d  Z d   Z d   Z d   Z d   Z d	   Z d
   Z	 d   Z
 d   Z d   Z d   Z d   Z RS(   s   A :class:`.Pool` that imposes a limit on the number of open connections.

    :class:`.QueuePool` is the default pooling implementation used for
    all :class:`.Engine` objects, unless the SQLite dialect is in use.

    i   i
   i   c         K   sW   t  j |  | |  t j |  |  _ d | |  _ | |  _ | |  _ t j	   |  _
 d S(   s  
        Construct a QueuePool.

        :param creator: a callable function that returns a DB-API
          connection object, same as that of :paramref:`.Pool.creator`.

        :param pool_size: The size of the pool to be maintained,
          defaults to 5. This is the largest number of connections that
          will be kept persistently in the pool. Note that the pool
          begins with no connections; once this number of connections
          is requested, that number of connections will remain.
          ``pool_size`` can be set to 0 to indicate no size limit; to
          disable pooling, use a :class:`~sqlalchemy.pool.NullPool`
          instead.

        :param max_overflow: The maximum overflow size of the
          pool. When the number of checked-out connections reaches the
          size set in pool_size, additional connections will be
          returned up to this limit. When those additional connections
          are returned to the pool, they are disconnected and
          discarded. It follows then that the total number of
          simultaneous connections the pool will allow is pool_size +
          `max_overflow`, and the total number of "sleeping"
          connections the pool will allow is pool_size. `max_overflow`
          can be set to -1 to indicate no overflow limit; no limit
          will be placed on the total number of concurrent
          connections. Defaults to 10.

        :param timeout: The number of seconds to wait before giving up
          on returning a connection. Defaults to 30.

        :param \**kw: Other keyword arguments including
        :paramref:`.Pool.recycle`, :paramref:`.Pool.echo`,
        :paramref:`.Pool.reset_on_return` and others are passed to the
        :class:`.Pool` constructor.

        i    N(   R$   RF   t
   sqla_queuet   QueueR   t	   _overflowt   _max_overflowt   _timeoutR   t   Lockt   _overflow_lock(   R   R<   R   t   max_overflowt   timeoutR   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRF   z  s    '		c         C   sN   y |  j  j | t  Wn0 t j k
 rI z | j   Wd  |  j   Xn Xd  S(   N(   R   t   putR3   R   t   FullR   t   _dec_overflow(   R   Rk   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRg     s    c         C   s   |  j  d k } y2 | o' |  j |  j  k } |  j j | |  j  SWn t j k
 r | r |  j |  j  k r | s| |  j   St j	 d |  j
   |  j   |  j f   n  |  j   r y |  j   SWq |  j     q Xq |  j   Sn Xd  S(   NisP   QueuePool limit of size %d overflow %d reached, connection timed out, timeout %d(   R   R   R   t   getR   R   t   EmptyRj   R    t   TimeoutErrorR   t   overflowt   _inc_overflowRV   R   (   R   t   use_overflowt   wait(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRj     s$    
%

c         C   s_   |  j  d k r" |  j d 7_ t S|  j . |  j |  j  k  rQ |  j d 7_ t St SWd  QXd  S(   Nii   (   R   R   R1   R   R3   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s    
c         C   sI   |  j  d k r" |  j d 8_ t S|  j  |  j d 8_ t SWd  QXd  S(   Nii   (   R   R   R1   R   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s    
c         C   s}   |  j  j d  |  j |  j d |  j j d |  j d |  j d |  j d |  j	 d |  j
 d |  j d	 |  j d
 |  j d |  j 
S(   Ns   Pool recreatingR   R   R   R=   R5   R'   R>   R?   RB   R8   (   RH   Ru   R   R-   R   t   maxsizeR   R   R.   R5   R(   R0   R2   R6   R8   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRa     s    						c         C   su   xB t  rD y  |  j j t  } | j   Wq t j k
 r@ Pq Xq Wd |  j   |  _ |  j	 j
 d |  j    d  S(   Ni    s   Pool disposed. %s(   R1   R   R   R3   R   R   R   R   R   RH   Ru   Rl   (   R   Rk   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRb     s    		c         C   s,   d |  j    |  j   |  j   |  j   f S(   Ns_   Pool size: %d  Connections in pool: %d Current Overflow: %d Current Checked out connections: %d(   R   t	   checkedinR   t
   checkedout(   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRl     s
    			c         C   s
   |  j  j S(   N(   R   R   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s    c         C   s   |  j  j   S(   N(   R   t   qsize(   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s    c         C   s   |  j  S(   N(   R   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s    c         C   s   |  j  j |  j  j   |  j S(   N(   R   R   R   R   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s    (   R!   R"   R#   RF   Rg   Rj   R   R   Ra   Rb   Rl   R   R   R   R   (    (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR   q  s   .											t   NullPoolc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s  A Pool which does not pool connections.

    Instead it literally opens and closes the underlying DB-API connection
    per each connection open/close.

    Reconnect-related functions such as ``recycle`` and connection
    invalidation are not supported by this Pool implementation, since
    no connections are held persistently.

    .. versionchanged:: 0.7
        :class:`.NullPool` is used by the SQlite dialect automatically
        when a file-based database is used. See :ref:`sqlite_toplevel`.

    c         C   s   d S(   NR   (    (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRl     s    c         C   s   | j    d  S(   N(   R   (   R   Rk   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRg     s    c         C   s
   |  j    S(   N(   RV   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRj      s    c         C   s_   |  j  j d  |  j |  j d |  j d |  j d |  j d |  j d |  j d |  j	 d |  j
 S(	   Ns   Pool recreatingR=   R5   R'   R>   R?   RB   R8   (   RH   Ru   R   R-   R.   R5   R(   R0   R2   R6   R8   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRa   #  s    						c         C   s   d  S(   N(    (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRb   /  s    (   R!   R"   R#   Rl   Rg   Rj   Ra   Rb   (    (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR   	  s   				t
   StaticPoolc           B   sb   e  Z d  Z e d    Z e d    Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z RS(	   s.  A Pool of exactly one connection, used for all requests.

    Reconnect-related functions such as ``recycle`` and connection
    invalidation (which is also used to support auto-reconnect) are not
    currently supported by this Pool implementation but may be implemented
    in a future release.

    c         C   s
   |  j    S(   N(   R-   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR   >  s    c         C   s
   t  |   S(   N(   RU   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRM   B  s    c         C   s   d S(   NR   (    (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRl   F  s    c         C   s,   d |  j  k r( |  j j   d  |  _ n  d  S(   NR   (   t   __dict__R   R   R)   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRb   I  s    c         C   sb   |  j  j d  |  j d |  j d |  j d |  j d |  j d |  j d |  j d |  j	 d	 |  j
  S(
   Ns   Pool recreatingR<   R=   R>   R?   R5   R'   RB   R8   (   RH   Ru   R   R-   R.   R0   R2   R5   R(   R6   R8   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRa   N  s    						c         C   s   |  j  S(   N(   R   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRV   Y  s    c         C   s   d  S(   N(    (   R   Rk   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRg   \  s    c         C   s   |  j  S(   N(   RM   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRj   _  s    (   R!   R"   R#   R   R   RM   Rl   Rb   Ra   RV   Rg   Rj   (    (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR   3  s   						t   AssertionPoolc           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s  A :class:`.Pool` that allows at most one checked out connection at
    any given time.

    This will raise an exception if more than one connection is checked out
    at a time.  Useful for debugging code that is using more connections
    than desired.

    .. versionchanged:: 0.7
        :class:`.AssertionPool` also logs a traceback of where
        the original connection was checked out, and reports
        this in the assertion error raised.

    c         O   sG   d  |  _ t |  _ | j d t  |  _ d  |  _ t j	 |  | |  d  S(   Nt   store_traceback(
   R)   R   R3   t   _checked_outR   R1   t   _store_tracebackt   _checkout_tracebackR$   RF   (   R   R   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRF   s  s
    			c         C   s   d S(   NR   (    (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRl   z  s    c         C   s:   |  j  s t d   n  t |  _  | |  j k s6 t  d  S(   Ns   connection is not checked out(   R   R   R3   R   (   R   Rk   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRg   }  s    		c         C   s&   t  |  _ |  j r" |  j j   n  d  S(   N(   R3   R   R   R   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRb     s    		c      
   C   sD   |  j  j d  |  j |  j d |  j d |  j d |  j d |  j S(   Ns   Pool recreatingR5   R'   RB   R8   (   RH   Ru   R   R-   R5   R(   R6   R8   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRa     s
    		c         C   s   |  j  rJ |  j r1 d d j t |  j   } n d } t d |   n  |  j se |  j   |  _ n  t |  _  |  j r t	 j
   |  _ n  |  j S(   Ns    at:
%sR   s!   connection is already checked out(   R   R   t   joinR   R   R   RV   R1   R   t	   tracebackt   format_stack(   R   t   suffix(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRj     s    						(	   R!   R"   R#   RF   Rl   Rg   Rb   Ra   Rj   (    (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR   c  s   					R   c           B   sY   e  Z d  Z e d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z RS(	   s	  Layers connection pooling behavior on top of a standard DB-API module.

    Proxies a DB-API 2.0 connect() call to a connection pool keyed to the
    specific connect parameters. Other functions and attributes are delegated
    to the underlying DB-API module.
    c         K   s7   | |  _  | |  _ | |  _ i  |  _ t j   |  _ d S(   s   Initializes a new proxy.

        module
          a DB-API 2.0 module

        poolclass
          a Pool class, defaulting to QueuePool

        Other parameters are sent to the Pool object's constructor.

        N(   R   R   t	   poolclasst   poolsR   R   t   _create_pool_mutex(   R   R   R   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRF     s
    				c         C   s(   x! t  |  j  D] } |  j | =q Wd  S(   N(   t   listR   (   R   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s    c         C   s   |  j    d  S(   N(   R   (   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   __del__  s    c         C   s   t  |  j |  S(   N(   RY   R   (   R   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s    c            s     j      } y   j | SWn t k
 r   j j   zc |   j k r  j d d     j     f d     j  } |   j | <| S  j | SWd    j j	   Xn Xd  S(   Nt   sa_pool_keyc              s     j  j     S(   N(   R   Rf   (    (   R   R   R   (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRx     s    (
   t
   _serializeR   R   R   t   acquireR   R)   R   R   t   release(   R   R   R   R   Rt   (    (   R   R   R   sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   get_pool  s    c         O   s   |  j  | |   j   S(   s,  Activate a connection to the database.

        Connect to the database using this DBProxy's module and the given
        connect arguments.  If the arguments match an existing pool, the
        connection will be returned from the pool's current thread-local
        connection instance, or if there is no thread-local connection
        instance it will be checked out from the set of pooled connections.

        If the pool has no available connections and allows new connections
        to be created, a new database connection will be made.

        (   R   Rf   (   R   R   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRf     s    c         O   s8   |  j  | |   } y |  j | =Wn t k
 r3 n Xd S(   s;   Dispose the pool referenced by the given connect arguments.N(   R   R   R   (   R   R   R   R   (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyRb     s
    c         O   sK   d | k r | d St  t |  g  t |  D] } | | | f ^ q-  S(   NR   (   t   tupleR   t   sorted(   R   R   R   t   k(    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s
    	(   R!   R"   R#   R   RF   R   R   R   R   Rf   Rb   R   (    (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyR     s   							((   R#   R[   R   R|   R   R    R   R   R   R   R   R   R   R   R   t   collectionsR	   R
   R   R   t   symbolR   R   R   t   objectR   t
   IdentifiedR$   RU   R)   Rv   R   R~   RR   R   R   R   R   R   R   (    (    (    sU   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/pool.pyt   <module>   s4   (		
 %	O*0>