a
    •˜ëj  ã                   @  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 erÈ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dœdd„ZG dd„ deƒZeZdS )aÚ  

.. dialect:: mysql+pymysql
    :name: PyMySQL
    :dbapi: pymysql
    :connectstring: mysql+pymysql://<username>:<password>@<host>/<dbname>[?<options>]
    :url: https://pymysql.readthedocs.io/

Unicode
-------

Please see :ref:`mysql_unicode` for current recommendations on unicode
handling.

.. _pymysql_ssl:

SSL Connections
------------------

The PyMySQL DBAPI accepts the same SSL arguments as that of MySQLdb,
described at :ref:`mysqldb_ssl`.   See that section for additional examples.

If the server uses an automatically-generated certificate that is self-signed
or does not match the host name (as seen from the client), it may also be
necessary to indicate ``ssl_check_hostname=false`` in PyMySQL::

    connection_uri = (
        "mysql+pymysql://scott:tiger@192.168.0.134/test"
        "?ssl_ca=/home/gord/client-ssl/ca.pem"
        "&ssl_cert=/home/gord/client-ssl/client-cert.pem"
        "&ssl_key=/home/gord/client-ssl/client-key.pem"
        "&ssl_check_hostname=false"
    )

MySQL-Python Compatibility
--------------------------

The pymysql DBAPI is a pure Python port of the MySQL-python (MySQLdb) driver,
and targets 100% compatibility.   Most behavioral notes for MySQL-python apply
to the pymysql driver as well.

é    )Úannotations)ÚAny)ÚDict)ÚOptional)ÚType)ÚTYPE_CHECKING)ÚUnioné   )ÚMySQLDialect_mysqldbé   )Úlanghelpers)ÚLiteral)ÚConnectArgsType)ÚDBAPIConnection)ÚDBAPICursor)ÚDBAPIModule)ÚPoolProxiedConnection)ÚURLz	Type[Any]Úbool)Úconnection_clsÚreturnc                 C  sR   t  | j¡}z|jd }W n ty.   Y dS 0 |dkoL|j pL|jd duS dS )ax  Given a Connection class like pymysql.Connection, aiomysql.Connection,
    asyncmy.Connection, inspect the ping() method and determine if it
    has a "reconnect" parameter that either defaults to True, or is positional.

    a return value of True here means that when we call ``connection.ping()``,
    we **must** pass `reconnect=False`.  a return value of False means that
    we should call ``connection.ping()`` with **no arguments**.

    This routine originates from issue #10492 for pymysql, however arg
    signature mismatches in aiomysql/asyncmy tracked by issue #13306
    necessitated a more open ended function.

    r	   FZ	reconnectr   N)r   Zget_callable_argspecÚpingÚargsÚ
IndexErrorÚdefaults)r   ZinspZreconnect_arg© r   ú`/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/sqlalchemy/dialects/mysql/pymysql.pyÚ _connection_ping_reconnects_trueJ   s    ÿr   c                      s¦   e Zd ZdZdZdZejddœdd„ƒZe	ddœd	d
„ƒZ
ejddœdd„ƒZdddœdd„Zd#ddddœ‡ fdd„Zdddddœ‡ fdd„Zddd œd!d"„Z‡  ZS )$ÚMySQLDialect_pymysqlÚpymysqlTNr   )r   c              	   C  s6   zt dƒj}|j| _W dS  ttfy0   Y dS 0 d S )Nzpymysql.cursorsTF)Ú
__import__ÚcursorsZSSCursorZ	_sscursorÚImportErrorÚAttributeError)Úselfr!   r   r   r   Úsupports_server_side_cursorsi   s    
z1MySQLDialect_pymysql.supports_server_side_cursorsr   c                 C  s   t dƒS )Nr   )r    )Úclsr   r   r   Úimport_dbapir   s    z!MySQLDialect_pymysql.import_dbapic              	   C  s6   zt dƒjj}W n ttfy(   Y dS 0 t|ƒS dS )a4  determine if pymysql has deprecated, changed the default of,
        or removed the 'reconnect' argument of connection.ping().

        See #10492 and
        https://github.com/PyMySQL/mysqlclient/discussions/651#discussioncomment-7308971
        for background.

        Revised as part of #13306

        zpymysql.connectionsTN)r    ÚconnectionsÚ
Connectionr"   r#   r   )r$   r)   r   r   r   Ú_send_false_to_pingv   s    ÿz(MySQLDialect_pymysql._send_false_to_pingr   zLiteral[True])Údbapi_connectionr   c                 C  s   | j r| d¡ n| ¡  dS )NFT)r*   r   )r$   r+   r   r   r   Údo_pingŒ   s    zMySQLDialect_pymysql.do_pingr   zOptional[Dict[str, Any]]r   )ÚurlÚ_translate_argsr   c                   s"   |d u rt dd�}tƒ j||d�S )NÚuser)Úusername)r.   )ÚdictÚsuperÚcreate_connect_args)r$   r-   r.   ©Ú	__class__r   r   r3   ”   s
    
ÿz(MySQLDialect_pymysql.create_connect_argszDBAPIModule.Errorz7Optional[Union[PoolProxiedConnection, DBAPIConnection]]zOptional[DBAPICursor])ÚeÚ
connectionÚcursorr   c                   sF   t ƒ  |||¡rdS t|| jjƒr>t|ƒ ¡ }d|v p<d|v S dS d S )NTzalready closedzconnection was killedF)r2   Úis_disconnectÚ
isinstanceZloaded_dbapiÚErrorÚstrÚlower)r$   r6   r7   r8   Zstr_er4   r   r   r9   �   s    ÿz"MySQLDialect_pymysql.is_disconnectÚBaseExceptionr   )Ú	exceptionr   c                 C  s$   t |jd tƒr|jd }|jd S )Nr   )r:   r   Ú	Exception)r$   r?   r   r   r   Ú_extract_error_code­   s    
z(MySQLDialect_pymysql._extract_error_code)N)Ú__name__Ú
__module__Ú__qualname__ZdriverZsupports_statement_cacheZdescription_encodingr   Zmemoized_propertyr%   Úclassmethodr'   r*   r,   r3   r9   rA   Ú__classcell__r   r   r4   r   r   c   s   	 ÿ	r   N)Ú__doc__Ú
__future__r   Útypingr   r   r   r   r   r   Zmysqldbr
   Úutilr   Zutil.typingr   Zengine.interfacesr   r   r   r   r   Z
engine.urlr   r   r   Údialectr   r   r   r   Ú<module>   s(   +P