o
    Šågò  ã                   @   s4   d Z ddlmZ ddlm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.

é   )ÚMySQLDialect_mysqldbé   )Úlanghelpersc                       sn   e Zd ZdZdZdZejdd„ ƒZe	dd„ ƒZ
ejdd	„ ƒZd
d„ Zd‡ fdd„	Z‡ fdd„Zdd„ Z‡  ZS )ÚMySQLDialect_pymysqlÚpymysqlTNc              	   C   s2   zt dƒj}|j| _W dS  ttfy   Y dS w )Nzpymysql.cursorsTF)Ú
__import__ÚcursorsÚSSCursorÚ	_sscursorÚImportErrorÚAttributeError)Úselfr   © r   ú]/var/www/html/flaskapp/venv/lib/python3.10/site-packages/sqlalchemy/dialects/mysql/pymysql.pyÚsupports_server_side_cursors?   s   
ÿz1MySQLDialect_pymysql.supports_server_side_cursorsc                 C   s   t dƒS )Nr   )r   )Úclsr   r   r   Úimport_dbapiH   s   z!MySQLDialect_pymysql.import_dbapic              	   C   sx   zt dƒjj}W n ttfy   Y dS w t |j¡}z|jd }W n
 t	y,   Y dS w |dko;|j
 p;|j
d duS )a  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.

        zpymysql.connectionsTr   FÚ	reconnecté    )r   ÚconnectionsÚ
Connectionr   r   r   Úget_callable_argspecÚpingÚargsÚ
IndexErrorÚdefaults)r   r   ÚinspÚreconnect_argr   r   r   Ú_send_false_to_pingL   s$   ÿþÿÿÿz(MySQLDialect_pymysql._send_false_to_pingc                 C   s    | j r
| d¡ dS | ¡  dS )NFT)r   r   )r   Údbapi_connectionr   r   r   Údo_pingh   s
   
þzMySQLDialect_pymysql.do_pingc                    s"   |d u r	t dd�}tƒ j||d�S )NÚuser)Úusername)Ú_translate_args)ÚdictÚsuperÚcreate_connect_args)r   Úurlr#   ©Ú	__class__r   r   r&   p   s
   
ÿz(MySQLDialect_pymysql.create_connect_argsc                    sB   t ƒ  |||¡r
dS t|| jjƒrt|ƒ ¡ }d|v pd|v S dS )NTzalready closedzconnection was killedF)r%   Úis_disconnectÚ
isinstanceÚdbapiÚErrorÚstrÚlower)r   ÚeÚ
connectionÚcursorÚstr_er(   r   r   r*   w   s   ÿz"MySQLDialect_pymysql.is_disconnectc                 C   s$   t |jd tƒr|jd }|jd S )Nr   )r+   r   Ú	Exception)r   Ú	exceptionr   r   r   Ú_extract_error_code‚   s   

z(MySQLDialect_pymysql._extract_error_code)N)Ú__name__Ú
__module__Ú__qualname__ÚdriverÚsupports_statement_cacheÚdescription_encodingr   Úmemoized_propertyr   Úclassmethodr   r   r    r&   r*   r6   Ú__classcell__r   r   r(   r   r   9   s    


r   N)Ú__doc__Úmysqldbr   Úutilr   r   Údialectr   r   r   r   Ú<module>   s
   	+O