
    h                        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 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  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.

    )annotations)Any)Dict)Optional)TYPE_CHECKING)Union   )MySQLDialect_mysqldb   )langhelpers)Literal)ConnectArgsType)DBAPIConnection)DBAPICursor)DBAPIModule)PoolProxiedConnection)URLc                       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	 	 	 	 	 d fdZ	 	 	 	 	 	 	 	 d fd	Zdd
Z 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     _/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/sqlalchemy/dialects/mysql/pymysql.pysupports_server_side_cursorsz1MySQLDialect_pymysql.supports_server_side_cursorsN   s?    	 !23;;G$--DN^, 		s   &) ;;c                    t        d      S )Nr   )r   )clss    r   import_dbapiz!MySQLDialect_pymysql.import_dbapiW   s    )$$    c                6   	 t        d      j                  j                  }t        j                  |j
                        }	 |j                  d   }|dk(  xr  |j                   xs |j                  d   duS # t        $ r Y yw xY w# t        t        f$ r Y yw xY w)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.connectionsr	   	reconnectr   FT)r   connections
Connectionr   get_callable_argspecpingargsdefaults
IndexErrorr   r   )r   r(   inspreconnect_args       r   _send_false_to_pingz(MySQLDialect_pymysql._send_false_to_ping[   s    	#%k**  33JOODD $		! %3 %Fq)9)F   ^, 		s#   B A7 7	BBBBc                `    | j                   r|j                  d       y|j                          y)NFT)r0   r*   )r   dbapi_connections     r   do_pingzMySQLDialect_pymysql.do_pingw   s/    ##!!%(  !!#r$   c                B    |t        d      }t        | 	  ||      S )Nuser)username)_translate_args)dictsupercreate_connect_args)r   urlr7   	__class__s      r   r:   z(MySQLDialect_pymysql.create_connect_args   s1     ""F3Ow* + 
 	
r$   c                    t         |   |||      ryt        || j                  j                        r#t        |      j                         }d|v xs d|v S y)NTzalready closedzconnection was killedF)r9   is_disconnect
isinstanceloaded_dbapiErrorstrlower)r   e
connectioncursorstr_er<   s        r   r>   z"MySQLDialect_pymysql.is_disconnect   s[     7 J74,,223FLLNE E)M-D-M r$   c                x    t        |j                  d   t              r|j                  d   }|j                  d   S )Nr   )r?   r+   	Exception)r   	exceptions     r   _extract_error_codez(MySQLDialect_pymysql._extract_error_code   s2    innQ'3!q)I~~a  r$   )returnbool)rL   r   )r2   r   rL   zLiteral[True])N)r;   r   r7   zOptional[Dict[str, Any]]rL   r   )rD   zDBAPIModule.ErrorrE   z7Optional[Union[PoolProxiedConnection, DBAPIConnection]]rF   zOptional[DBAPICursor]rL   rM   )rJ   BaseExceptionrL   r   )__name__
__module____qualname__driversupports_statement_cachedescription_encodingr   memoized_propertyr    classmethodr#   r0   r3   r:   r>   rK   __classcell__)r<   s   @r   r   r   H   s    F#"" # % % "" #6 EI

)A
	
 L &	
 
 !r$   r   N)__doc__
__future__r   typingr   r   r   r   r   mysqldbr
   utilr   util.typingr   engine.interfacesr   r   r   r   r   
engine.urlr   r   dialect r$   r   <module>rb      sT   )T #       )  "4400:!S!/ S!l r$   