
    	i.-                     J    d dl Z d dlZd dlZd dlmZ dZ G d de          ZdS )    N)STATUS@   c                       e Zd ZdZd Zd Zd ZddZd Zd Z	d	 Z
d
 Zed             Zed             Zed             Zed             Zed             Zej        d             ZdS )ConnectionPoolaG  
    Class defining a pool of database connections

    MariaDB Connector/Python supports simple connection pooling.
    A connection pool holds a number of open connections and handles thread safety when providing connections to threads.

    The size of a connection pool is configurable at creation time, but cannot be changed afterward. The maximum size of a connection pool is limited to 64 connections.

    Keyword Arguments:

    - **`pool_name`** (``str``) - Name of connection pool
    - **`pool_size`** (``int``) - Size of pool. The Maximum allowed number is 64. Default to 5
    - **`pool_reset_connection`** (``bool``) - Will reset the connection before returning it to the pool. Default to True.
    - **`pool_validation_interval`** (``int``) - Specifies the validation interval in milliseconds after which the status of a connection requested from the pool is checked. A value of 0 means that the status will always be checked. Default to 500 (Added in version 1.1.6)
    - **\*\*kwargs** - Optional additional connection arguments, as described in mariadb.connect() method.

    c                 n   g | _         g | _        i | _        i | _        t	          j                    | _        d| _        g d}|r6d|v r2|d         t          j	        v rt          j
        d|d         z            nt          j
        d          |                    d          | j        d<   t          |                    dd                    | j        d	<   t          |                    d
d                    | j        d<   t          |                    dd                    | j        d<   d| j        d	         cxk     rt          k    sn t          j
        dt          z            |                                | _        |D ]}|| j        v r| j        |= t!          | j                  dk    r| j        5  t#          d| j        d	                   D ]}	 t          j        di | j        }n# t          j        $ rr t)          t#          dt!          | j                                       D ]@}	 | j         |                                          n# t          j        $ r Y nw xY w| j         |= A w xY w|                     |           	 ddd           n# 1 swxY w Y   | t          j	        | j        d         <   dS )a:  
        Creates a connection pool class

        :param str pool_name:
            Name of connection pool

        :param int pool_size:
            Size of pool. If not specified, the default value of 5 will be used.
            The Maximum allowed number is 64.

        :param bool pool_reset_connection:
            Will reset the connection before returning it to the pool.
            The Default value is True.

        :param **kwargs kwargs:
            Optional additional connection arguments, as described in
             mariadb.connect() method.
        r   )	pool_name	pool_sizepool_reset_connectionpool_validation_intervalr   zPool '%s' already existszNo pool name specifiednamer	      sizer
   Treset_connectionr   i  validation_intervalz&Pool size must be in range of 1 and %sN )_connections_free_connections_used
_pool_args
_conn_args_threadRLock
_lock_pool_ConnectionPool__closedmariadb_CONNECTION_POOLSProgrammingErrorgetintboolMAX_POOL_SIZEcopylenrange
ConnectionErrorreversedcloseadd_connection)selfargskwargs	key_wordskeyi
connectionjs           N/srv/django_bis/venv311/lib/python3.11/site-packages/mariadb/connectionpool.py__init__zConnectionPool.__init__0   sV   & "$!#!-//1 1 1	  	EkV++ k"g&???./I171D0E F F F @ *+CDDD #)**["9"9"%fjja&@&@"A"A3T::;; 	*+ 

5s;;<< 	-. DOF+<<<<}<<<<* ,68E,F G G G !++-- 	) 	)Cdo%%OC(t!## 4 4q$/&"9:: 4 4A%,%7%J%J$/%J%J

"=    "*%3t7M3N3N*O*O!P!P : :A% $ 6q 9 ? ? A A A A#*= % % % !%	%
 !% 6q 9 9 ''
3333!44 4 4 4 4 4 4 4 4 4 4 4 4 4 4* >B!$/&"9:::sO   3JG)(J)A I**I
	I*
II*II**JJJc                    |rr|| j         v r#| j                             |          }| j         |= n+|| j        v r"| j                            |          }| j        |= d|_        |                                 |                                 S )zI
        Removes the given connection and adds a new connection.
        N)r   indexr   _Connection__poolr'   r(   r)   r/   xs      r1   _replace_connectionz"ConnectionPool._replace_connection   s    
  		T333*00<<*1--t555*00<<*1-+/J(""$$$    c                     | j         r dt          t          |                     dS d| j        dt          t          |                     dS )Nz:<mariadb.connectionPool.ConnectionPool object (closed) at >z4<mariadb.connectionPool.ConnectionPool object (name=z) at )r   hexidr   r)   s    r1   __repr__zConnectionPool.__repr__   sZ    M 	> 	>"2d88}}}}/ /	>
  $~~~s2d88}}}}> >r9   Nc                    | j         s"t          j        d| j        d         z            |3t	          |t          j        j                  st          j        d          |:t          | j                   dk    r"t          j        d| j        d         z            t          | j	        | j
        z             }|| j        d         k    r&t          j        d| j        d         d	|d
          | j        5  |t          j        di | j         }| |_        t          j                    |_        | j	                            |           |cddd           S # 1 swxY w Y   dS )u   
        Adds a connection object to the connection pool.

        In case that the pool doesn’t have a free slot or is not configured,
        a PoolError exception will be raised.
        z&Couldn't get configuration for pool %sr   Nz+Passed parameter is not a connection objectr   z#Can't get configuration for pool %sr   zCan't add connection to pool z: No free slot available (z).r   )r   r   	PoolErrorr   
isinstanceconnectionsr$   r   r"   r   r   r   r5   timeperf_counter_ns_ConnectionPool__last_usedappend)r)   r/   totals      r1   r(   zConnectionPool.add_connection   s     	=#$L$(OF$;%< = = = "z7+>+IJJ #* ,? @ @ @ #do"6"6!";";#$I$(OF$;%< = = = D*T-CCDDDOF+++##%)_V%<%<%<%*UU%, - - -
 _ 	 	!$/BB$/BB
+/J(%)%9%;%;J""))*555	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   5AEEEc                 n   d}| j         5  t          dt          | j                            D ]}| j        |         }t	          j                    |j        z
  dz  }|| j        d         k    rD	 |                                 n.# t          j
        $ r |                     |          }|sY |Y nw xY w|xj        dz  c_        | j                            |           | j                            |          }| j        |= |c cddd           S 	 ddd           n# 1 swxY w Y   t          j        d          )z
        Returns a connection from the connection pool or raises a PoolError
        exception if a connection is not available.
        Nr   i@B r      zNo connection available)r   r#   r"   r   rD   rE   rF   r   pingr   r%   r8   _usedr   rG   r4   rA   )r)   connr.   dtidxs        r1   get_connectionzConnectionPool.get_connection   s    _ 	 	1c$"899::  -a0*,,t/??7J(=>>>%		"= % % %#77==# %$H% %%
 

a

&--d333,22488*3/!	 	 	 	 	 	 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	$  9:::s7   A!D,B D&B,'D+B,,ADDDc                    | j         5  	 | j        d         r|                                 n(|j        t          j        z  r|                                 n*# t          j        $ r | 	                    |           Y nw xY w|r]|| j
        v rT| j
                            |          }| j
        |= t          j                    |_        | j                            |           ddd           dS # 1 swxY w Y   dS )z_
        Returns connection to the pool. Internally used
        by connection object.
        r   N)r   r   resetserver_statusr   IN_TRANSrollbackr   r%   r8   r   r4   rD   rE   rF   r   rG   r6   s      r1   _close_connectionz ConnectionPool._close_connection   sW   
 _ 	> 	>5?#56 *$$&&&&-? *'')))= 5 5 5((444445  >!777.44Z@@A.q1-1-A-C-CJ**11*===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s6   C+A
AC+$A<9C+;A<<A"C++C/2C/c                     || _         dS )u  
        Sets the connection configuration for the connection pool.
        For valid connection arguments, check the mariadb.connect() method.

        Note: This method doesn't create connections in the pool.
        To fill the pool, one has to use add_connection() ḿethod.
        N)r   )r)   r+   s     r1   
set_configzConnectionPool.set_config   s     !r9   c                    	 | j         | j        z   D ]}d|_        |                                 	 d| _         d| _        t          j        | j        d         = dS # d| _         d| _        t          j        | j        d         = w xY w)z+Closes connection pool and all connections.Nr   )r   r   r5   r'   r   r   r   )r)   cs     r1   r'   zConnectionPool.close   s    	C,t/EE  &*#				 &*D"%)D")$/&*ABBB &*D"%)D")$/&*ABBBBBs   -A (B c                     | j         d         S )z(Returns the name of the connection pool.r   r   r>   s    r1   r   zConnectionPool.pool_name       v&&r9   c                     | j         d         S )z(Returns the size of the connection pool.r   r\   r>   s    r1   r	   zConnectionPool.pool_size  r]   r9   c                     t           S )z.Returns the maximum size for connection pools.)r    r>   s    r1   max_sizezConnectionPool.max_size  s
     r9   c                 ^    	 t          | j        | j        z             S # t          $ r Y dS w xY w)z5Returns the number of connections in connection pool.r   )r"   r   r   	Exceptionr>   s    r1   connection_countzConnectionPool.connection_count  sB    	t-0FFGGG 	 	 	11	s    
,,c                     | j         d         S )z
        If set to true, the connection will be reset on both client and server
        side after .close() method was called
        r   r\   r>   s    r1   r
   z$ConnectionPool.pool_reset_connection#  s     122r9   c                     || j         d<   d S )Nr   r\   )r)   rR   s     r1   r
   z$ConnectionPool.pool_reset_connection+  s    .3*+++r9   )N)__name__
__module____qualname____doc__r2   r8   r?   r(   rP   rV   rX   r'   propertyr   r	   r`   rc   r
   setterr   r9   r1   r   r      sL        $PB PB PBd% % %"> > ># # # #J; ; ;8> > >,	! 	! 	!	C 	C 	C ' ' X'
 ' ' X'
   X
   X 3 3 X3 !4 4 "!4 4 4r9   r   )r   r   rD   mariadb.constantsr   r    objectr   r   r9   r1   <module>rn      sw   (    $ $ $ $ $ $P4 P4 P4 P4 P4V P4 P4 P4 P4 P4r9   