o
    L)jt                     @  s  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 d	d
lmZ d	dlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ e	rddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlm"Z" ddl#m$Z$ G dd  d eZ%G d!d" d"ee%Z&G d#d$ d$eeZ'G d%d& d&e'Z(G d'd( d(eZ)G d)d* d*eZ*e*Z+d+S ),a  
.. dialect:: mysql+asyncmy
    :name: asyncmy
    :dbapi: asyncmy
    :connectstring: mysql+asyncmy://user:password@host:port/dbname[?key=value&key=value...]
    :url: https://github.com/long2ice/asyncmy

Using a special asyncio mediation layer, the asyncmy dialect is usable
as the backend for the :ref:`SQLAlchemy asyncio <asyncio_toplevel>`
extension package.

This dialect should normally be used only with the
:func:`_asyncio.create_async_engine` engine creation function::

    from sqlalchemy.ext.asyncio import create_async_engine

    engine = create_async_engine(
        "mysql+asyncmy://user:pass@hostname/dbname?charset=utf8mb4"
    )

    )annotations)
ModuleType)Any)NoReturn)Optional)TYPE_CHECKING)Union   ) _connection_ping_reconnects_true)MySQLDialect_pymysql   )pool)util)AsyncAdapt_dbapi_connection)AsyncAdapt_dbapi_cursor)AsyncAdapt_dbapi_module)AsyncAdapt_dbapi_ss_cursor)AsyncAdapt_terminate)langhelpers)await_fallback)
await_only)AsyncIODBAPIConnection)AsyncIODBAPICursor)ConnectArgsType)DBAPIConnection)DBAPICursor)DBAPIModule)PoolProxiedConnection)URLc                   @  s   e Zd ZdZdS )AsyncAdapt_asyncmy_cursor N)__name__
__module____qualname__	__slots__r    r    r    /var/www/html/finance-dev.cargoinsureonline.com/_shared/backend-venv/lib/python3.10/site-packages/sqlalchemy/dialects/mysql/asyncmy.pyr   ?   s    r   c                   @  s   e Zd ZdZd	ddZdS )
AsyncAdapt_asyncmy_ss_cursorr    
connectionr   returnr   c                 C  s   | | jjjjjS N)cursor_adapt_connectiondbapiasyncmycursorsSSCursorselfr'   r    r    r%   _make_new_cursorH   s   z-AsyncAdapt_asyncmy_ss_cursor._make_new_cursorN)r'   r   r(   r   )r!   r"   r#   r$   r2   r    r    r    r%   r&   C   s    r&   c                   @  st   e Zd ZdZeZeZd ddZd!d"ddZ	d#ddZ
d$ddZd%ddZd&ddZd#ddZd#ddZd#ddZdS )'AsyncAdapt_asyncmy_connectionr    error	Exceptionr(   r   c                 C  s   t |tr| jd||)Nz7network operation failed due to asyncmy attribute error)
isinstanceAttributeErrorr,   InternalErrorr1   r4   r    r    r%   _handle_exceptionX   s   
z/AsyncAdapt_asyncmy_connection._handle_exceptionF	reconnectboolNonec                 C  s   |rJ |  |  S r)   )await__do_ping)r1   r;   r    r    r%   ping`   s   z"AsyncAdapt_asyncmy_connection.pingc              
     s   zE| j 4 I d H 0 | jjr| jjddI d H  n| j I d H  W d   I d H  W d S W d   I d H  W d S 1 I d H s?w   Y  W d S  ty^ } z| | W Y d }~d S d }~ww )NF)r;   )_execute_mutexr,   _send_false_to_ping_connectionr@   r5   r:   r9   r    r    r%   r?   d   s   2z&AsyncAdapt_asyncmy_connection._do_pingOptional[str]c                 C  
   | j  S r)   )rC   character_set_namer1   r    r    r%   rF   n      
z0AsyncAdapt_asyncmy_connection.character_set_namevaluer   c                 C  s   |  | j| d S r)   )r>   rC   
autocommit)r1   rI   r    r    r%   rJ   q   s   z(AsyncAdapt_asyncmy_connection.autocommitc                 C  rE   r)   )rC   get_autocommitrG   r    r    r%   rK   t   rH   z,AsyncAdapt_asyncmy_connection.get_autocommitc                 C  s   |  | j  d S r)   )r>   rC   ensure_closedrG   r    r    r%   closew   s   z#AsyncAdapt_asyncmy_connection.closec                   s   | j  I d H  d S r)   )rC   rL   rG   r    r    r%   _terminate_graceful_closez   s   z7AsyncAdapt_asyncmy_connection._terminate_graceful_closec                 C  s   | j   d S r)   )rC   rM   rG   r    r    r%   _terminate_force_close}   s   z4AsyncAdapt_asyncmy_connection._terminate_force_closeN)r4   r5   r(   r   )F)r;   r<   r(   r=   r(   r=   )r(   rD   )rI   r   r(   r=   r(   r<   )r!   r"   r#   r$   r   _cursor_clsr&   _ss_cursor_clsr:   r@   r?   rF   rJ   rK   rM   rN   rO   r    r    r    r%   r3   P   s    







r3   c                   @  s   e Zd ZdZeeZdS )%AsyncAdaptFallback_asyncmy_connectionr    N)r!   r"   r#   r$   staticmethodr   r>   r    r    r    r%   rT      s    rT   c                   @  st   e Zd ZdddZdddZed	Zed
ZedZ	edZ
edZeeZdddZejdddZdS )AsyncAdapt_asyncmy_dbapir-   r   c                 C  s   || _ d| _|   d S )Nformat)r-   
paramstyle_init_dbapi_attributes)r1   r-   r    r    r%   __init__   s   z!AsyncAdapt_asyncmy_dbapi.__init__r(   r=   c                 C  s$   dD ]}t | |t| jj| qd S )N)WarningErrorInterfaceError	DataErrorDatabaseErrorOperationalErrorr]   IntegrityErrorProgrammingErrorr8   NotSupportedError)setattrgetattrr-   errors)r1   namer    r    r%   rY      s   z/AsyncAdapt_asyncmy_dbapi._init_dbapi_attributesSTRINGNUMBERBINARYDATETIME	TIMESTAMPargr   kwr3   c                 O  sV   | dd}| d| jj}t|rt| t||i |S t| t||i |S )Nasync_fallbackFasync_creator_fn)	popr-   connectr   asboolrT   r   r3   r   )r1   rm   rn   ro   
creator_fnr    r    r%   rr      s   
z AsyncAdapt_asyncmy_dbapi.connectr<   c              	   C  s0   zt djj}W t|S  ttfy   Y dS w )zdetermine if asyncmy has deprecated, changed the default of,
        or removed the 'reconnect' argument of connection.ping().

        See #13306 and #10492

        zasyncmy.connectionT)
__import__r'   
ConnectionImportErrorr7   r
   )r1   rv   r    r    r%   rB      s   	z,AsyncAdapt_asyncmy_dbapi._send_false_to_pingN)r-   r   rP   )rm   r   rn   r   r(   r3   rQ   )r!   r"   r#   rZ   rY   r   symbolrh   ri   rj   rk   rl   rU   bytesBinaryrr   r   memoized_propertyrB   r    r    r    r%   rV      s    







rV   c                      s~   e Zd ZdZdZdZeZdZdZ	e
d#ddZe
d$d
dZd%ddZd& fddZd' fddZd(ddZd)d!d"Z  ZS )*MySQLDialect_asyncmyr-   Tr(   r   c                 C  s   t tdS )Nr-   )rV   ru   )clsr    r    r%   import_dbapi   s   z!MySQLDialect_asyncmy.import_dbapiurlr   typec                 C  s$   |j dd}t|rtjS tjS )Nro   F)querygetr   rs   r   FallbackAsyncAdaptedQueuePoolAsyncAdaptedQueuePool)r}   r   ro   r    r    r%   get_pool_class   s   
z#MySQLDialect_asyncmy.get_pool_classdbapi_connectionr   r=   c                 C  s   |   d S r)   )	terminate)r1   r   r    r    r%   do_terminate   s   z!MySQLDialect_asyncmy.do_terminater   c                   s   t  j|tddddS )Nuserdb)usernamedatabase)_translate_args)supercreate_connect_argsdict)r1   r   	__class__r    r%   r      s   z(MySQLDialect_asyncmy.create_connect_argseDBAPIModule.Errorr'   7Optional[Union[PoolProxiedConnection, DBAPIConnection]]r*   Optional[DBAPICursor]r<   c                   s0   t  |||r
dS t| }d|v pd|v S )NTznot connectedznetwork operation failed)r   is_disconnectstrlower)r1   r   r'   r*   str_er   r    r%   r      s
   z"MySQLDialect_asyncmy.is_disconnectintc                 C  s   ddl m} |jS )Nr   )CLIENT)asyncmy.constantsr   
FOUND_ROWS)r1   r   r    r    r%   _found_rows_client_flag   s   z,MySQLDialect_asyncmy._found_rows_client_flagr   c                 C  s   |j S r)   )rC   r0   r    r    r%   get_driver_connection   s   z*MySQLDialect_asyncmy.get_driver_connection)r(   r   )r   r   r(   r   )r   r   r(   r=   )r   r   r(   r   )r   r   r'   r   r*   r   r(   r<   )r(   r   )r'   r   r(   r   )r!   r"   r#   driversupports_statement_cachesupports_server_side_cursorsr&   	_sscursoris_asynchas_terminateclassmethodr~   r   r   r   r   r   r   __classcell__r    r    r   r%   r|      s     

r|   N),__doc__
__future__r   typesr   typingr   r   r   r   r   pymysqlr
   r    r   r   connectors.asyncior   r   r   r   r   r   util.concurrencyr   r   r   r   engine.interfacesr   r   r   r   r   
engine.urlr   r   r&   r3   rT   rV   r|   dialectr    r    r    r%   <module>   sP   

2=8