
    +h                     F    d Z ddlmZ ddlmZ ddlmZ  G d de      ZeZy)	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   )langhelpers)py3kc                        e Zd ZdZdZdZdZdZej                  d        Z
ed        Zd	 fd	Z fdZerd Z xZS  xZS )
MySQLDialect_pymysqlpymysqlTNc                 |    	 t        d      j                  }|j                  | _        y# t        t
        f$ r Y yw xY w)Nzpymysql.cursorsTF)
__import__cursorsSSCursor	_sscursorImportErrorAttributeError)selfr   s     T/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/dialects/mysql/pymysql.pysupports_server_side_cursorsz1MySQLDialect_pymysql.supports_server_side_cursorsE   s?    	 !23;;G$--DN^, 		s   &) ;;c                     t        d      S )Nr	   )r   )clss    r   dbapizMySQLDialect_pymysql.dbapiN   s    )$$    c                 J    |t        d      }t        t        |   ||      S )Nuser)username)_translate_args)dictsuperr   create_connect_args)r   urlr   	__class__s      r   r   z(MySQLDialect_pymysql.create_connect_argsR   s3    ""F3O)4D E 
 	
r   c                     t         t        |   |||      ryt        || j                  j
                        r#t        |      j                         }d|v xs d|v S y)NTzalready closedzconnection was killedF)r   r   is_disconnect
isinstancer   Errorstrlower)r   e
connectioncursorstr_er    s        r   r"   z"MySQLDialect_pymysql.is_disconnectY   s_    %t:z6
 4::++,FLLNE E)M-D-M r   c                 x    t        |j                  d   t              r|j                  d   }|j                  d   S )N    )r#   args	Exception)r   	exceptions     r   _extract_error_codez(MySQLDialect_pymysql._extract_error_codeh   s2    )..+Y7%NN1-	>>!$$r   )N)__name__
__module____qualname__driversupports_statement_cachedescription_encodingsupports_unicode_statementssupports_unicode_bindsr   memoized_propertyr   classmethodr   r   r"   r   r0   __classcell__)r    s   @r   r   r   9   sg    F#
 #'!"" # % %
 	% r   r   N)__doc__mysqldbr   utilr   r   r   dialect r   r   <module>rA      s+   *X *  2%/ 2%j r   