U
    cc
                     @   s@   d Z ddlm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 examples.


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                       sd   e Zd ZdZdZdZdZdZej	dd Z
edd Zd fdd		Z fd
dZer\dd Z  ZS )MySQLDialect_pymysqlpymysqlTNc              	   C   s8   zt dj}|j| _W dS  ttfk
r2   Y dS X d S )Nzpymysql.cursorsTF)
__import__cursorsZSSCursorZ	_sscursorImportErrorAttributeError)selfr	    r   E/tmp/pip-unpacked-wheel-8u86ls_i/sqlalchemy/dialects/mysql/pymysql.pysupports_server_side_cursors9   s    
z1MySQLDialect_pymysql.supports_server_side_cursorsc                 C   s   t dS )Nr   )r   )clsr   r   r   dbapiB   s    zMySQLDialect_pymysql.dbapic                    s&   |d krt dd}tt| j||dS )Nuser)username)_translate_args)dictsuperr   create_connect_args)r   urlr   	__class__r   r   r   F   s    

 z(MySQLDialect_pymysql.create_connect_argsc                    sJ   t t| |||rdS t|| jjrBt| }d|kp@d|kS dS d S )NTzalready closedzconnection was killedF)r   r   is_disconnect
isinstancer   Errorstrlower)r   e
connectioncursorZstr_er   r   r   r   M   s    
  z"MySQLDialect_pymysql.is_disconnectc                 C   s$   t |jd tr|jd }|jd S )N    )r   args	Exception)r   	exceptionr   r   r   _extract_error_code\   s    
z(MySQLDialect_pymysql._extract_error_code)N)__name__
__module____qualname__ZdriverZsupports_statement_cacheZdescription_encodingZsupports_unicode_statementsZsupports_unicode_bindsr   Zmemoized_propertyr   classmethodr   r   r   r   r'   __classcell__r   r   r   r   r   -   s   

r   N)__doc__Zmysqldbr   utilr   r   r   dialectr   r   r   r   <module>   s
    5