%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/enterprise/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/enterprise/__pycache__/adbapi.cpython-312.pyc

�

Ϫ�fA��~�dZddlmZddlmZmZGd�de�ZGd�d�ZGd�d	�Z	Gd
�d�Z
d	dgZy)
zg
An asynchronous mapping to U{DB-API
2.0<http://www.python.org/topics/database/DatabaseAPI-2.0.html>}.
�)�threads)�log�reflectc��eZdZdZy)�ConnectionLostzb
    This exception means that a db connection has been lost.  Client code may
    try again.
    N)�__name__�
__module__�__qualname__�__doc__���;/usr/lib/python3/dist-packages/twisted/enterprise/adbapi.pyrrs��r
rc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�
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.
    c�@�||_d|_|j�y�N)�_pool�_connection�	reconnect)�self�pools  r�__init__zConnection.__init__s����
�������r
c��yrr�rs r�closezConnection.close$s��	
r
c�l�|jjs|jj�y	|jj�|jj	�}|j|jj�|j�|jj�y#t$rtjdd�YnwxYw|jj|j�|jjrtjd�t��)N�Rollback failedzConnection lost.)rrr�rollback�cursor�execute�good_sqlr�commit�
BaseExceptionr�err�
disconnect�noisy�msgr)r�curss  rrzConnection.rollback.s����z�z�#�#����%�%�'��	-����%�%�'��#�#�*�*�,�D��L�L����,�,�-��J�J�L����#�#�%����	-��G�G�D�+�,�	-��	
�
�
���d�.�.�/��:�:����G�G�&�'���s�BB7�7C�Cc��|j�%|jj|j�|jj�|_yr)rrr%�connectrs rrzConnection.reconnectDs;�����'��J�J�!�!�$�"2�"2�3��:�:�-�-�/��r
c�.�t|j|�Sr)�getattrr�r�names  r�__getattr__zConnection.__getattr__Is���t�'�'��.�.r
N)	rr	r
rrrrrr/rr
rrrs ����

��,0�
/r
rc�2�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	y)�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.
    Nc�@�||_||_|j�yr)rr�reopen)rr�
connections   rrzTransaction.__init__Ys����
�%������
r
c�J�|j}d|_|j�yr)�_cursorr)rr6s  rrzTransaction.close^s���,�,������
�
�r
c��|j�|j�	|jj�|_y#t$r0|j
js�tjdd�YnwxYw|j
jrtjd�|j
�|jj�|_y)NzCursor creation failedzConnection lost, reconnecting)r6rrrr#rrrr$r&r'rs rr3zTransaction.reopencs����<�<�#��J�J�L�	8��+�+�2�2�4�D�L����	8��:�:�'�'������6�7�		8���:�:����G�G�3�4������'�'�.�.�0��s�>�6A7�6A7c�F�|jj�d|_yr)rrr6rs rrzTransaction.reconnectvs�����"�"�$���r
c�.�t|j|�Sr)r,r6r-s  rr/zTransaction.__getattr__zs���t�|�|�T�*�*r
)
rr	r
rr6rrr3rr/rr
rr1r1Ms'����G��
�
1�&�+r
r1c���eZdZdZdj	�ZdZdZdZdZ	dZ
dZdZdZ
eZeZdZd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$y)�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�:�||_tj|�|_t	|jdd�dk7rtjd�t	|jdd�dkrtjd�|jd	d�}|�dd
lm	}||_
||_||_|jD]}d|��}||vs�
t||||�||=�!t|j|j �|_t!|j|j �|_i|_ddlm}m}|j*|_|j/|j|j �|_|jj1|j2�|_y)
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'})

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

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

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

        @keyword 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.

        @keyword 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.

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

        @keyword cp_reactor: use this reactor instead of the global reactor
            (added in Twisted 10.2).
        @type cp_reactor: L{IReactorCore} provider
        �apilevelNz2.0z'DB API module not DB API 2.0 compliant.�threadsafetyr�z+DB API module not sufficiently thread-safe.�
cp_reactor)�reactor�cp_)�
threadable�
threadpool)�	dbapiNamer�namedModule�dbapir,rr'�pop�twisted.internetrC�_reactor�connargs�connkw�CP_ARGS�setattr�min�max�connections�twisted.pythonrErF�getThreadID�threadID�
ThreadPool�callWhenRunning�_start�startID)	rrGrMrNrC�arg�cpArgrErFs	         rrzConnectionPool.__init__�sK��F#����(�(��3��
��4�:�:�z�4�0�E�9��G�G�=�>��4�:�:�~�q�1�A�5��G�G�A�B��*�*�\�4�0���?�0���
� ��
�����<�<�	"�C��#��K�E������c�6�%�=�1��5�M�		"��t�x�x����*����t�x�x����*������	:�"�.�.��
�$�/�/����$�(�(�C����}�}�4�4�T�[�[�A��r
c�0�d|_|j�Sr)rZ�startrs rrYzConnectionPool._start�s������z�z�|�r
c��|jsN|jj�|jj	dd|j
�|_d|_yy)z�
        Start the connection pool.

        If you are using the reactor normally, this function does *not*
        need to be called.
        �during�shutdownTN)�runningrFr^rL�addSystemEventTrigger�
finalClose�
shutdownIDrs rr^zConnectionPool.start�sJ���|�|��O�O�!�!�#�"�m�m�A�A��*�d�o�o��D�O� �D�L�r
c�v�tj|j|j|j|g|��i|��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�deferToThreadPoolrLrF�_runWithConnection)r�func�args�kws    r�runWithConnectionz ConnectionPool.runWithConnection�s>��,�(�(��M�M�4�?�?�D�,C�,C�T�
�LP�
�TV�
�	
r
c���|j|�}	||g|��i|��}|j�|S#t$r8	|j��#t$rt	j
dd�Y�wxYwwxYw�Nr)�connectionFactoryr"r#rrr$)rrirjrk�conn�results      rrhz!ConnectionPool._runWithConnections~���%�%�d�+��		��$�,��,��,�F��K�K�M��M���	�
1��
�
��
��!�
1�����/�0��
1��	�s,�1�	A2�A�A2�A.�+A2�-A.�.A2c�v�tj|j|j|j|g|��i|��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}.
        )rrgrLrF�_runInteraction)r�interactionrjrks    r�runInteractionzConnectionPool.runInteraction$sE��8�(�(��M�M��O�O�� � ��	
�
�
��

�	
r
c�B�|j|jg|��i|��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}.
        )ru�	_runQuery�rrjrks   r�runQueryzConnectionPool.runQueryIs%��$#�t�"�"�4�>�>�?�D�?�B�?�?r
c�B�|j|jg|��i|��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}.
        )ru�
_runOperationrxs   r�runOperationzConnectionPool.runOperation]s'��&#�t�"�"�4�#5�#5�C��C��C�Cr
c��|jr,|jj|j�d|_|jr,|jj|j�d|_|j	�y)zC
        Close all pool connections and shutdown the pool.
        N)rerL�removeSystemEventTriggerrZrdrs rrzConnectionPool.closersV���?�?��M�M�2�2�4�?�?�C�"�D�O��<�<��M�M�2�2�4�<�<�@��D�L����r
c���d|_|jj�d|_|jj�D]}|j
|��|jj�y)zE
        This should only be called by the shutdown trigger.
        NF)rerF�stoprbrS�values�_close�clear�rrps  rrdzConnectionPool.finalClose~s^���������������$�$�+�+�-�	�D��K�K���	������ r
c�t�|j�}|jj|�}|��|jr"t	j
d|j���|jj|ji|j��}|j�|j|�||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.
        zadbapi connecting: )rVrS�getr&rr'rGrIr*rMrN�openfun)r�tidrps   rr*zConnectionPool.connect�s����m�m�o�����#�#�C�(���<��z�z����-�d�n�n�-=�>�?�%�4�:�:�%�%�t�}�}�D����D�D��|�|�'����T�"�$(�D���S�!��r
c��|j�}||jj|�urtd��|�|j	|�|j|=yy)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)rVrSr��	Exceptionr�)rrpr�s   rr%zConnectionPool.disconnect�sY���m�m�o���t�'�'�+�+�C�0�0��9�:�:����K�K���� � ��%�r
c���|jr"tjd|j���	|j	�y#t
$rtjdd�YywxYw)Nzadbapi closing: zConnection close failed)r&rr'rGrr#r$r�s  rr�zConnectionPool._close�sN���:�:��G�G�&�t�~�~�&6�7�8�	5��J�J�L���	5��G�G�D�3�4�	5�s�A�A#�"A#c�.�|j|�}|j||�}	||g|��i|��}|j�|j�|S#t$r8	|j��#t$rt
jdd�Y�wxYwwxYwrn)ro�transactionFactoryrr"r#rrr$)rrtrjrkrp�transrqs       rrszConnectionPool._runInteraction�s����%�%�d�+���'�'��d�3��
	� ��4��4��4�F��K�K�M��K�K�M��M���	�
1��
�
��
��!�
1�����/�0��
1��	�s/�-A�	B�A.�-B�.B�
B�B�Bc�F�|j|i|��|j�Sr)r �fetchall�rr�rjrks    rrwzConnectionPool._runQuery�s"����
�
�t�"�r�"��~�~��r
c�(�|j|i|��yr)r r�s    rr{zConnectionPool._runOperation�s����
�
�t�"�r�"r
c	��|j|j|j|j|j|j
|j|jd�S)N�rGrQrRr&rr!rMrNr�rs r�__getstate__zConnectionPool.__getstate__�sD������8�8��8�8��Z�Z�����
�
��
�
��k�k�	
�		
r
c�z�||_|j|jg|j��i|j��yr)�__dict__rrGrMrN)r�states  r�__setstate__zConnectionPool.__setstate__�s-����
���
�
�d�n�n�D�t�}�}�D����Dr
)%rr	r
r�splitrOr&rQrRr.r�rr!rbrror1r�rerrYr^rlrhruryr|rrdr*r%r�rsrwr{r�r�rr
rr;r;~s����&>�C�C�E�G��E�
�C�
�C��D��G��I��H��G�"��$���J�EB�N� �
�4�#
�J@�(D�*
�	!��.
&�5�
� �#�

�Er
r;N)rrKrrTrrr�rrr1r;�__all__rr
r�<module>r�sP��
�%�'��Y��4/�4/�n.+�.+�b]E�]E�@�*�
+�r

Zerion Mini Shell 1.0