
    Zj                        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Z G 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)URLconnection_cls	Type[Any]returnboolc                    t          j        | j                  }	 |j        d         }|dk    o|j         p|j        d         duS # t
          $ r Y dS w xY w)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
   	reconnectr   F)r   get_callable_argspecpingargsdefaults
IndexError)r   inspreconnect_args      e/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/sqlalchemy/dialects/mysql/pymysql.py _connection_ping_reconnects_truer#   J   sx     +N,?@@D
	! + 
>q!1!>	
    uus   A 
AAc                       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pymysqlTNr   r   c                x    	 t          d          j        }|j        | _        dS # t          t
          f$ r Y dS w xY w)Nzpymysql.cursorsTF)
__import__cursorsSSCursor	_sscursorImportErrorAttributeError)selfr)   s     r"   supports_server_side_cursorsz1MySQLDialect_pymysql.supports_server_side_cursorsi   sN    	 !233;G$-DN4^, 	 	 	55	s    $ 99r   c                     t          d          S )Nr&   )r(   )clss    r"   import_dbapiz!MySQLDialect_pymysql.import_dbapir   s    )$$$    c                    	 t          d          j        j        }t          |          S # t          t
          f$ r Y dS w xY w)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.connectionsT)r(   connections
Connectionr#   r,   r-   )r.   r6   s     r"   _send_false_to_pingz(MySQLDialect_pymysql._send_false_to_pingv   s[    	@#% *  4J??? ^, 	 	 	44	s   * ??dbapi_connectionr   Literal[True]c                h    | j         r|                    d           n|                                 dS )NFT)r7   r   )r.   r8   s     r"   do_pingzMySQLDialect_pymysql.do_ping   s;    # 	$!!%((((!!###tr3   urlr   _translate_argsOptional[Dict[str, Any]]r   c                n    |t          d          }t                                          ||          S )Nuser)username)r=   )dictsupercreate_connect_args)r.   r<   r=   	__class__s      r"   rD   z(MySQLDialect_pymysql.create_connect_args   sA     ""F333Oww** + 
 
 	
r3   eDBAPIModule.Error
connection7Optional[Union[PoolProxiedConnection, DBAPIConnection]]cursorOptional[DBAPICursor]c                    t                                          |||          rdS t          || j        j                  r)t          |                                          }d|v pd|v S dS )NTzalready closedzconnection was killedF)rC   is_disconnect
isinstanceloaded_dbapiErrorstrlower)r.   rF   rH   rJ   str_erE   s        r"   rM   z"MySQLDialect_pymysql.is_disconnect   sr     77  J77 	44,233 	FFLLNNE E)M-D-M 5r3   	exceptionBaseExceptionr   c                v    t          |j        d         t                    r|j        d         }|j        d         S )Nr   )rN   r   	Exception)r.   rT   s     r"   _extract_error_codez(MySQLDialect_pymysql._extract_error_code   s4    inQ'33 	*!q)I~a  r3   )r   r   )r   r   )r8   r   r   r9   )N)r<   r   r=   r>   r   r   )rF   rG   rH   rI   rJ   rK   r   r   )rT   rU   r   r   )__name__
__module____qualname__driversupports_statement_cachedescription_encodingr   memoized_propertyr/   classmethodr2   r7   r;   rD   rM   rX   __classcell__)rE   s   @r"   r%   r%   c   s
       F#"   #" % % % [% "@ @ @ #"@*    EI
 
 
 
 
 
 
      ! ! ! ! ! ! ! !r3   r%   N)r   r   r   r   )__doc__
__future__r   typingr   r   r   r   r   r	   mysqldbr   utilr   util.typingr   engine.interfacesr   r   r   r   r   
engine.urlr   r#   r%   dialect r3   r"   <module>rl      s  ) )V # " " " " "                                           ) ) ) ) ) )       " " " " " " "444444444444000000000000::::::!!!!!!
 
 
 
2M! M! M! M! M!/ M! M! M!` r3   