o
    `^h                     @   s   d dl mZ d dlZdd Zdd ZG dd deZG d	d
 d
eZG dd deZG dd deZG dd deZ	G dd deZ
G dd dZdS )    )	CoroutineNc                 C   s   t d| d d S )N<I   )structpack)n r   L/home/air/shanriGPT/back/venv/lib/python3.10/site-packages/aiomysql/utils.py_pack_int24   s   r
   c                 C   s   | dk r
t d|  | dk rt| gS | dk rdtd|  S | dk r/dtd	| d d
  S | dk r;dtd|  S t d| df )Nr   zFEncoding %d is less than 0 - no representation in LengthEncodedInteger   i      z<Hi      r   r   l               z<QzIEncoding %x is larger than %x - no representation in LengthEncodedInteger)
ValueErrorbytesr   r   )ir   r   r	   _lenenc_int
   s"   
r   c                   @   s~   e Zd ZdZdd Zdd ZdddZd	d
 Zedd Z	edd Z
edd Zdd Zdd Zdd Zdd Zdd ZdS )_ContextManager_coro_objc                 C   s   || _ d | _d S Nr   )selfcoror   r   r	   __init__"      
z_ContextManager.__init__c                 C   s   | j |S r   )r   send)r   valuer   r   r	   r   &   s   z_ContextManager.sendNc                 C   s:   |d u r
| j |S |d u r| j ||S | j |||S r   )r   throw)r   typvaltbr   r   r	   r   )   s
   z_ContextManager.throwc                 C   
   | j  S r   )r   closer   r   r   r	   r#   1      
z_ContextManager.closec                 C      | j jS r   )r   gi_framer$   r   r   r	   r'   4      z_ContextManager.gi_framec                 C   r&   r   )r   
gi_runningr$   r   r   r	   r)   8   r(   z_ContextManager.gi_runningc                 C   r&   r   )r   gi_coder$   r   r   r	   r*   <   r(   z_ContextManager.gi_codec                 C   s
   |  d S r   )r   r$   r   r   r	   __next__@   r%   z_ContextManager.__next__c                 C   r"   r   r   	__await__r$   r   r   r	   __iter__C   r%   z_ContextManager.__iter__c                 C   r"   r   r,   r$   r   r   r	   r-   F   r%   z_ContextManager.__await__c                       | j I d H | _| jS r   r   r$   r   r   r	   
__aenter__I      z_ContextManager.__aenter__c                    s   | j  I d H  d | _ d S r   )r   r#   r   exc_typeexcr!   r   r   r	   	__aexit__M   s   
z_ContextManager.__aexit__)NN)__name__
__module____qualname__	__slots__r   r   r   r#   propertyr'   r)   r*   r+   r.   r-   r0   r5   r   r   r   r	   r      s"    



r   c                   @      e Zd Zdd ZdS )_ConnectionContextManagerc                    s0   |d ur| j   n| j  I d H  d | _ d S r   )r   r#   ensure_closedr2   r   r   r	   r5   S   s
   
z#_ConnectionContextManager.__aexit__Nr6   r7   r8   r5   r   r   r   r	   r<   R       r<   c                   @   r;   )_PoolContextManagerc                    s&   | j   | j  I d H  d | _ d S r   )r   r#   wait_closedr2   r   r   r	   r5   \   s   

z_PoolContextManager.__aexit__Nr>   r   r   r   r	   r@   [   r?   r@   c                   @   s   e Zd Zdd Zdd ZdS )_SAConnectionContextManagerc                 C   s   | S r   r   r$   r   r   r	   	__aiter__c   s   z%_SAConnectionContextManager.__aiter__c                    sT   | j d u r| jI d H | _ z	| j  I d H W S  ty)   | j  I d H  d | _  w r   )r   r   	__anext__StopAsyncIterationr#   r$   r   r   r	   rD   f   s   
z%_SAConnectionContextManager.__anext__N)r6   r7   r8   rC   rD   r   r   r   r	   rB   b   s    rB   c                   @   r;   )_TransactionContextManagerc                    s:   |r| j  I d H  n| j jr| j  I d H  d | _ d S r   )r   rollback	is_activecommitr2   r   r   r	   r5   s   s   
z$_TransactionContextManager.__aexit__Nr>   r   r   r   r	   rF   r   r?   rF   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_PoolAcquireContextManagerr   _conn_poolc                 C   s   || _ d | _|| _d S r   rK   )r   r   poolr   r   r	   r      s   
z#_PoolAcquireContextManager.__init__c                    r/   r   )r   rL   r$   r   r   r	   r0      r1   z%_PoolAcquireContextManager.__aenter__c                    8   z| j | jI d H  W d | _ d | _d S d | _ d | _w r   rM   releaserL   r2   r   r   r	   r5         
z$_PoolAcquireContextManager.__aexit__N)r6   r7   r8   r9   r   r0   r5   r   r   r   r	   rJ   |   s
    rJ   c                   @   s<   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dS )_PoolConnectionContextManagera'  Context manager.

    This enables the following idiom for acquiring and releasing a
    connection around a block:

        with (yield from pool) as conn:
            cur = yield from conn.cursor()

    while failing loudly when accidentally using:

        with pool:
            <block>
    rM   rL   c                 C   s   || _ || _d S r   rT   )r   rN   connr   r   r	   r      r   z&_PoolConnectionContextManager.__init__c                 C   s   | j sJ | j S r   )rL   r$   r   r   r	   	__enter__   s   
z'_PoolConnectionContextManager.__enter__c                 C   s0   z| j | j W d | _ d | _d S d | _ d | _w r   rP   r   r3   exc_valexc_tbr   r   r	   __exit__   s   
z&_PoolConnectionContextManager.__exit__c                    s$   | j rJ | j I d H | _ | j S r   )rL   rM   acquirer$   r   r   r	   r0      s   
z(_PoolConnectionContextManager.__aenter__c                    rO   r   rP   rW   r   r   r	   r5      rR   z'_PoolConnectionContextManager.__aexit__N)
r6   r7   r8   __doc__r9   r   rV   rZ   r0   r5   r   r   r   r	   rS      s    rS   )collections.abcr   r   r
   r   r   r<   r@   rB   rF   rJ   rS   r   r   r   r	   <module>   s    4	
