HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/enterprise/__pycache__/adbapi.cpython-38.pyc
U

��W[�B�@stdZddlZddlmZddlmZmZmZGdd�de�Z	Gdd�de
�ZGd	d
�d
�ZGdd�d�Z
d
dgZdS)
zg
An asynchronous mapping to U{DB-API
2.0<http://www.python.org/topics/database/DatabaseAPI-2.0.html>}.
�N)�threads)�reflect�log�compatc@seZdZdZdS)�ConnectionLostzb
    This exception means that a db connection has been lost.  Client code may
    try again.
    N)�__name__�
__module__�__qualname__�__doc__�rr�;/usr/lib/python3/dist-packages/twisted/enterprise/adbapi.pyrsrc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�
Connectiona

    A wrapper for a DB-API connection instance.

    The wrapper passes almost everything to the wrapped connection and so has
    the same API. However, the L{Connection} knows about its pool and also
    handle reconnecting should when the real connection dies.
    cCs||_d|_|��dS�N)�_pool�_connection�	reconnect)�self�poolrrr�__init__!szConnection.__init__cCsdSrr�rrrr�close'szConnection.closecCs�|jjs|j��dSz:|j��|j��}|�|jj�|��|j��WdSt	�
dd�YnX|j�|j�|jjr�t	�
d�t��dS)N�Rollback failedzConnection lost.)rrr�rollback�cursor�execute�good_sqlr�commitr�err�
disconnect�noisy�msgr)rZcursrrrr2s 




zConnection.rollbackcCs(|jdk	r|j�|j�|j��|_dSr)rrr�connectrrrrrIs
zConnection.reconnectcCst|j|�Sr)�getattrr�r�namerrr�__getattr__OszConnection.__getattr__N)	rrr	r
rrrrr%rrrrr
sr
c@s<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	dS)
�Transactiona
    A lightweight wrapper for a DB-API 'cursor' object.

    Relays attribute access to the DB cursor. That is, you can call
    C{execute()}, C{fetchall()}, etc., and they will be called on the
    underlying DB-API cursor object. Attributes will also be retrieved from
    there.
    NcCs||_||_|��dSr)rr�reopen)rrZ
connectionrrrr_szTransaction.__init__cCs|j}d|_|��dSr)�_cursorr)rr(rrrreszTransaction.closecCst|jdk	r|��z|j��|_WdS|jjs8�nt�dd�YnX|jjr\t�	d�|��|j��|_dS)NzCursor creation failedzConnection lost, reconnecting)
r(rrrrrrrrr rrrrr'ks

zTransaction.reopencCs|j��d|_dSr)rrr(rrrrrs
zTransaction.reconnectcCst|j|�Sr)r"r(r#rrrr%�szTransaction.__getattr__)
rrr	r
r(rrr'rr%rrrrr&Tsr&c@s�eZdZdZd��ZdZdZdZdZ	dZ
dZdZdZ
eZeZdZdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Z d$d%�Z!d&d'�Z"d(d)�Z#d*d+�Z$dS),�ConnectionPoola�
    Represent a pool of connections to a DB-API 2.0 compliant database.

    @ivar connectionFactory: factory for connections, default to L{Connection}.
    @type connectionFactory: any callable.

    @ivar transactionFactory: factory for transactions, default to
        L{Transaction}.
    @type transactionFactory: any callable

    @ivar shutdownID: L{None} or a handle on the shutdown event trigger which
        will be used to stop the connection pool workers when the reactor
        stops.

    @ivar _reactor: The reactor which will be used to schedule startup and
        shutdown events.
    @type _reactor: L{IReactorCore} provider
    z-min max name noisy openfun reconnect good_sqlF��Nzselect 1c	Os||_t�|�|_t|jdd�dkr.t�d�t|jdd�dkrJt�d�|�d	d�}|dkrjdd
lm	}||_
||_||_|j
D],}d|f}||kr�t||||�||=q�t|j|j�|_t|j|j�|_i|_ddlm}dd
lm}|j|_|�|j|j�|_|j
�|j�|_dS)a�
        Create a new L{ConnectionPool}.

        Any positional or keyword arguments other than those documented here
        are passed to the DB-API object when connecting. Use these arguments to
        pass database names, usernames, passwords, etc.

        @param dbapiName: an import string to use to obtain a DB-API compatible
            module (e.g. C{'pyPgSQL.PgSQL'})

        @param cp_min: the minimum number of connections in pool (default 3)

        @param cp_max: the maximum number of connections in pool (default 5)

        @param cp_noisy: generate informational log messages during operation
            (default C{False})

        @param cp_openfun: a callback invoked after every C{connect()} on the
            underlying DB-API object. The callback is passed a new DB-API
            connection object. This callback can setup per-connection state
            such as charset, timezone, etc.

        @param cp_reconnect: detect connections which have failed and reconnect
            (default C{False}). Failed connections may result in
            L{ConnectionLost} exceptions, which indicate the query may need to
            be re-sent.

        @param cp_good_sql: an sql query which should always succeed and change
            no state (default C{'select 1'})

        @param cp_reactor: use this reactor instead of the global reactor
            (added in Twisted 10.2).
        @type cp_reactor: L{IReactorCore} provider
        ZapilevelNz2.0z'DB API module not DB API 2.0 compliant.Zthreadsafetyr�z+DB API module not sufficiently thread-safe.Z
cp_reactor)�reactorzcp_%s)�
threadpool)�
threadable)�	dbapiNamerZnamedModule�dbapir"rr �pop�twisted.internetr-�_reactor�connargs�connkw�CP_ARGS�setattr�min�max�connections�twisted.pythonr.r/ZgetThreadID�threadIDZ
ThreadPoolZcallWhenRunning�_start�startID)	rr0r5r6r-�argZcpArgr.r/rrrr�s2#



zConnectionPool.__init__cCsd|_|��Sr)r?�startrrrrr>�szConnectionPool._startcCs.|js*|j��|j�dd|j�|_d|_dS)z�
        Start the connection pool.

        If you are using the reactor normally, this function does *not*
        need to be called.
        ZduringZshutdownTN)�runningr.rAr4ZaddSystemEventTrigger�
finalClose�
shutdownIDrrrrrA�s
�zConnectionPool.startcOstj|j|j|j|f|�|�S)a
        Execute a function with a database connection and return the result.

        @param func: A callable object of one argument which will be executed
            in a thread with a connection from the pool. It will be passed as
            its first argument a L{Connection} instance (whose interface is
            mostly identical to that of a connection object for your DB-API
            module of choice), and its results will be returned as a
            L{Deferred}. If the method raises an exception the transaction will
            be rolled back. Otherwise, the transaction will be committed.
            B{Note} that this function is B{not} run in the main thread: it
            must be threadsafe.

        @param *args: positional arguments to be passed to func

        @param **kw: keyword arguments to be passed to func

        @return: a L{Deferred} which will fire the return value of
            C{func(Transaction(...), *args, **kw)}, or a
            L{twisted.python.failure.Failure}.
        )r�deferToThreadPoolr4r.�_runWithConnection)r�func�args�kwrrr�runWithConnections���z ConnectionPool.runWithConnectionc	
Osz|�|�}z||f|�|�}|��|WSt��\}}}z|��Wnt�dd�YnXt�||�YnXdS�Nr)	�connectionFactoryr�sys�exc_inforrrr�reraise)	rrGrHrI�conn�result�excType�excValue�excTracebackrrrrF&s
z!ConnectionPool._runWithConnectioncOstj|j|j|j|f|�|�S)a�
        Interact with the database and return the result.

        The 'interaction' is a callable object which will be executed in a
        thread using a pooled connection. It will be passed an L{Transaction}
        object as an argument (whose interface is identical to that of the
        database cursor for your DB-API module of choice), and its results will
        be returned as a L{Deferred}. If running the method raises an
        exception, the transaction will be rolled back. If the method returns a
        value, the transaction will be committed.

        NOTE that the function you pass is *not* run in the main thread: you
        may have to worry about thread-safety in the function you pass to this
        if it tries to use non-local objects.

        @param interaction: a callable object whose first argument is an
            L{adbapi.Transaction}.

        @param *args: additional positional arguments to be passed to
            interaction

        @param **kw: keyword arguments to be passed to interaction

        @return: a Deferred which will fire the return value of
            C{interaction(Transaction(...), *args, **kw)}, or a
            L{twisted.python.failure.Failure}.
        )rrEr4r.�_runInteraction)r�interactionrHrIrrr�runInteraction5s���zConnectionPool.runInteractioncOs|j|jf|�|�S)aY
        Execute an SQL query and return the result.

        A DB-API cursor which will be invoked with C{cursor.execute(*args,
        **kw)}. The exact nature of the arguments will depend on the specific
        flavor of DB-API being used, but the first argument in C{*args} be an
        SQL statement. The result of a subsequent C{cursor.fetchall()} will be
        fired to the L{Deferred} which is returned. If either the 'execute' or
        'fetchall' methods raise an exception, the transaction will be rolled
        back and a L{twisted.python.failure.Failure} returned.

        The C{*args} and C{**kw} arguments will be passed to the DB-API
        cursor's 'execute' method.

        @return: a L{Deferred} which will fire the return value of a DB-API
            cursor's 'fetchall' method, or a L{twisted.python.failure.Failure}.
        )rW�	_runQuery�rrHrIrrr�runQueryVszConnectionPool.runQuerycOs|j|jf|�|�S)aK
        Execute an SQL query and return L{None}.

        A DB-API cursor which will be invoked with C{cursor.execute(*args,
        **kw)}. The exact nature of the arguments will depend on the specific
        flavor of DB-API being used, but the first argument in C{*args} will be
        an SQL statement. This method will not attempt to fetch any results
        from the query and is thus suitable for C{INSERT}, C{DELETE}, and other
        SQL statements which do not return values. If the 'execute' method
        raises an exception, the transaction will be rolled back and a
        L{Failure} returned.

        The C{*args} and C{*kw} arguments will be passed to the DB-API cursor's
        'execute' method.

        @return: a L{Deferred} which will fire with L{None} or a
            L{twisted.python.failure.Failure}.
        )rW�
_runOperationrYrrr�runOperationkszConnectionPool.runOperationcCs@|jr|j�|j�d|_|jr4|j�|j�d|_|��dS)zC
        Close all pool connections and shutdown the pool.
        N)rDr4ZremoveSystemEventTriggerr?rCrrrrr�szConnectionPool.closecCs>d|_|j��d|_|j��D]}|�|�q |j��dS)zE
        This should only be called by the shutdown trigger.
        NF)rDr.�stoprBr;�values�_close�clear�rrPrrrrC�s
zConnectionPool.finalClosecCsx|��}|j�|�}|dkrt|jrDt�d|j|jp4d|jp<df�|j	j
|j|j�}|jdkrj|�|�||j|<|S)a�
        Return a database connection when one becomes available.

        This method blocks and should be run in a thread from the internal
        threadpool. Don't call this method directly from non-threaded code.
        Using this method outside the external threadpool may exceed the
        maximum number of connections in the pool.

        @return: a database connection from the pool.
        Nzadbapi connecting: %s %s%s�)r=r;�getrrr r0r5r6r1r!�openfun)r�tidrPrrrr!�s
�


zConnectionPool.connectcCs>|��}||j�|�k	r td��|dk	r:|�|�|j|=dS)a
        Disconnect a database connection associated with this pool.

        Note: This function should only be used by the same thread which called
        L{ConnectionPool.connect}. As with C{connect}, this function is not
        used in normal non-threaded Twisted code.
        zwrong connection for threadN)r=r;rc�	Exceptionr_)rrPrerrrr�s
zConnectionPool.disconnectcCsB|jrt�d|jf�z|��Wnt�dd�YnXdS)Nzadbapi closing: %szConnection close failed)rrr r0rrrarrrr_�szConnectionPool._closec

Os�|�|�}|�||�}z&||f|�|�}|��|��|WSt��\}}}	z|��Wnt�dd�YnXt	�
||	�YnXdSrK)rL�transactionFactoryrrrMrNrrrrrO)
rrVrHrIrP�transrQrRrSrTrrrrU�s
zConnectionPool._runInteractioncOs|j||�|��Sr)rZfetchall�rrhrHrIrrrrX�szConnectionPool._runQuerycOs|j||�dSr)rrirrrr[�szConnectionPool._runOperationc	Cs&|j|j|j|j|j|j|j|jd�S)N�r0r9r:rrrr5r6rjrrrr�__getstate__�s�zConnectionPool.__getstate__cCs"||_|j|jf|j�|j�dSr)�__dict__rr0r5r6)r�staterrr�__setstate__�szConnectionPool.__setstate__)%rrr	r
�splitr7rr9r:r$rdrrrBr
rLr&rgrDrr>rArJrFrWrZr\rrCr!rr_rUrXr[rkrnrrrrr)�s>I!
	r))r
rMr3rr<rrrrfr�objectr
r&r)�__all__rrrr�<module>s<5q