3
(h(                  @   sV  d Z ddlmZ ddlmZ ddlmZ i ad$ddZd%dd	Z	d
d Z
G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed"Zeeeeeeeed#ZdS )&zPython exceptions
   )utils)get_client_error)PY2Nc             C   s   t | tr|  ri atS |  r(| r(tS t | ttfs>tdt | trP| |i} x^| j D ]R\}}t |tsttdyt|tstW n tk
r   tdY nX |t|< qZW tS )ay  Define custom exceptions for MySQL server errors

    This function defines custom exceptions for MySQL server errors and
    returns the current set customizations.

    If error is a MySQL Server error number, then you have to pass also the
    exception class.

    The error argument can also be a dictionary in which case the key is
    the server error number, and value the exception to be raised.

    If none of the arguments are given, then custom_error_exception() will
    simply return the current set customizations.

    To reset the customizations, simply supply an empty dictionary.

    Examples:
        import mysql.connector
        from mysql.connector import errorcode

        # Server error 1028 should raise a DatabaseError
        mysql.connector.custom_error_exception(
            1028, mysql.connector.DatabaseError)

        # Or using a dictionary:
        mysql.connector.custom_error_exception({
            1028: mysql.connector.DatabaseError,
            1029: mysql.connector.OperationalError,
            })

        # Reset
        mysql.connector.custom_error_exception({})

    Returns a dictionary.
    z<The error argument should be either an integer or dictionaryz!error number should be an integerz)exception should be subclass of Exception)	
isinstancedict_CUSTOM_ERROR_EXCEPTIONSint
ValueErroritems
issubclass	Exception	TypeError)error	exceptionerrno
_exception r   J/tmp/pip-install-q3hcpn_q/mysql-connector-python/mysql/connector/errors.pycustom_error_exception*   s(    &


r   c             C   s   yt |  || |dS  tk
r&   Y nX yt|  || |dS  tk
rN   Y nX |s`t|| dS yt|dd  || |dS  tk
r   t|| |dS X dS )a>  Get the exception matching the MySQL error

    This function will return an exception based on the SQLState. The given
    message will be passed on in the returned exception.

    The exception returned can be customized using the
    mysql.connector.custom_error_exception() function.

    Returns an Exception
    )msgr   sqlstate)r   r          N)r   KeyError_ERROR_EXCEPTIONSDatabaseError_SQLSTATE_CLASS_EXCEPTION)r   r   r   r   r   r   get_mysql_exceptionj   s"    r   c             C   s   d }}y| d dkrt dW n( tk
rH } ztd| S d}~X nX d}yx| dd } tj| d\} }| d d	krt| ttfr| jd
}q| }n,tj	| dd d\} }|jd
}| jd
}W n( t
k
r } ztd| S d}~X nX t|||S dS )zReturns an exception object based on the MySQL error

    Returns an exception object based on the MySQL error in the given
    packet.

    Returns an Error-Object.
    N      zPacket is not an error packetz%Failed getting Error information (%r)   r   r   #   utf8r   )r	   
IndexErrorInterfaceErrorr   Zread_intr   bytes	bytearraydecode
read_bytesr   r   )packetr   errmsgerrr   r   r   r   get_exception   s(    
r,   c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )Errorz;Exception that is base class for all other error exceptionsNc                s.  t t| j  || _| j| _|p"d| _|| _| j rd| j  koHdk n  rt| j| _|d k	ry| j| | _W q tk
r } zdj	| jt
|| _W Y d d }~X qX n| jsd | _| _| jo| jdkr| jtr| jjdn| jd}| jrd}| j|d	< nd
}|j	f || _| j| j| jf| _d S )Nr   i  i  z{0} (Warning: {1})zUnknown errorr"   )r   r   z{errno} ({state}): {msg}statez{errno}: {msg}r/   )superr-   __init__r   	_full_msgr   r   r   r   formatstrr   encodeargs)selfr   r   valuesr   r+   fieldsfmt)	__class__r   r   r1      s.    
"(zError.__init__c             C   s   | j S )N)r2   )r7   r   r   r   __str__   s    zError.__str__)NNNN)__name__
__module____qualname____doc__r1   r<   __classcell__r   r   )r;   r   r-      s   r-   c               @   s   e Zd ZdZdS )Warningz Exception for important warningsN)r=   r>   r?   r@   r   r   r   r   rB      s   rB   c               @   s   e Zd ZdZdS )r$   z-Exception for errors related to the interfaceN)r=   r>   r?   r@   r   r   r   r   r$      s   r$   c               @   s   e Zd ZdZdS )r   z,Exception for errors related to the databaseN)r=   r>   r?   r@   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdS )InternalErrorz-Exception for errors internal database errorsN)r=   r>   r?   r@   r   r   r   r   rC      s   rC   c               @   s   e Zd ZdZdS )OperationalErrorz8Exception for errors related to the database's operationN)r=   r>   r?   r@   r   r   r   r   rD      s   rD   c               @   s   e Zd ZdZdS )ProgrammingErrorz'Exception for errors programming errorsN)r=   r>   r?   r@   r   r   r   r   rE      s   rE   c               @   s   e Zd ZdZdS )IntegrityErrorz3Exception for errors regarding relational integrityN)r=   r>   r?   r@   r   r   r   r   rF      s   rF   c               @   s   e Zd ZdZdS )	DataErrorz;Exception for errors reporting problems with processed dataN)r=   r>   r?   r@   r   r   r   r   rG      s   rG   c               @   s   e Zd ZdZdS )NotSupportedErrorzBException for errors when an unsupported database feature was usedN)r=   r>   r?   r@   r   r   r   r   rH      s   rH   c               @   s   e Zd ZdZdS )	PoolErrorz3Exception for errors relating to connection poolingN)r=   r>   r?   r@   r   r   r   r   rI     s   rI   )02Z07Z08Z0AZ21Z22Z23Z24Z25Z26Z27Z28Z2AZ2BZ2CZ2DZ2EZ33Z34Z35Z37Z3CZ3DZ3FZ40Z42Z44ZHZZXAZ0KZHY)i  i  i  i  i  i  i  i  )NN)NN)r@    r   Zlocalesr   Zcatch23r   r   r   r   r,   r   r-   rB   r$   r   rC   rD   rE   rF   rG   rH   rI   r   r   r   r   r   r   <module>   sr   
@
#$%