U
    e,                      @   sb  U d Z ddlmZmZmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZm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 f
 Zeeeeeeeeeeeef Zi aeeef ed< d-eeeeeee f f  ee eeee f dd d!Z d.eee! ee! ee" ed#d$d%Z#e$ed&d'd(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f ed*< eeeeeeeed+Z'eeef ed,< dS )/zPython exceptions.    )DictMappingOptionalTupleTypeUnion   )get_client_error)
StrOrBytes)
read_bytesread_intc                       s^   e Zd ZdZd
ee ee eeeeef df  ee dd fddZ	eddd	Z
  ZS )Errorz;Exception that is base class for all other error exceptionsN.)msgerrnovaluessqlstatereturnc              
      s  t    || _| j| _|pd| _|| _| jsd| j  krDdk rn n^t| j| _|d k	rz| j| | _W q tk
r } z| j d| d| _W 5 d }~X Y qX n| jsd | _| _| jr| jdkr| j| jd}| jrd}| j|d	< nd
}|jf || _| j| j| jf| _	d S )Ni  i  z (Warning: )zUnknown error)r   r   z{errno} ({state}): {msg}statez{errno}: {msg})
super__init__r   	_full_msgr   r   r	   	TypeErrorformatargs)selfr   r   r   r   errfieldsfmt	__class__ W/var/www/html/assets/scripts/venv/lib/python3.8/site-packages/mysql/connector/errors.pyr   (   s,    

 (zError.__init__)r   c                 C   s   | j S )N)r   )r   r"   r"   r#   __str__J   s    zError.__str__)NNNN)__name__
__module____qualname____doc__r   strintr   r   r   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#   r,   N   s   r,   c                   @   s   e Zd ZdZdS )InterfaceErrorz-Exception for errors related to the interfaceNr-   r"   r"   r"   r#   r.   R   s   r.   c                   @   s   e Zd ZdZdS )DatabaseErrorz,Exception for errors related to the databaseNr-   r"   r"   r"   r#   r/   V   s   r/   c                   @   s   e Zd ZdZdS )InternalErrorz-Exception for errors internal database errorsNr-   r"   r"   r"   r#   r0   Z   s   r0   c                   @   s   e Zd ZdZdS )OperationalErrorz8Exception for errors related to the database's operationNr-   r"   r"   r"   r#   r1   ^   s   r1   c                   @   s   e Zd ZdZdS )ProgrammingErrorz'Exception for errors programming errorsNr-   r"   r"   r"   r#   r2   b   s   r2   c                   @   s   e Zd ZdZdS )IntegrityErrorz3Exception for errors regarding relational integrityNr-   r"   r"   r"   r#   r3   f   s   r3   c                   @   s   e Zd ZdZdS )	DataErrorz;Exception for errors reporting problems with processed dataNr-   r"   r"   r"   r#   r4   j   s   r4   c                   @   s   e Zd ZdZdS )NotSupportedErrorzBException for errors when an unsupported database feature was usedNr-   r"   r"   r"   r#   r5   n   s   r5   c                   @   s   e Zd ZdZdS )	PoolErrorz3Exception for errors relating to connection poolingNr-   r"   r"   r"   r#   r6   r   s   r6   _CUSTOM_ERROR_EXCEPTIONSN)error	exceptionr   c                 C   s   t | tr| si atS | s"|s"tS t | ttfs8tdt | trJ| |i} |  D ]j\}}t |tsltdz|dkst|tstW n, tk
r } ztd|W 5 d}~X Y nX |t|< qRt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 integerNz)Exception should be subclass of Exception)	
isinstancedictr7   r*   
ValueErroritems
issubclass	Exceptionr   )r8   r9   r   
_exceptionr   r"   r"   r#   custom_error_exception   s&    )


rA   F)r   r   r   warningr   c                 C   s   zt |  || |dW S  tk
r(   Y nX zt|  || |dW S  tk
rR   Y nX |sr|rft| |S t|| dS zt|dd  || |dW S  tk
r   t|| |d Y 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
    )r   r   r   )r   r   r      N)r7   KeyError_ERROR_EXCEPTIONSr,   r/   _SQLSTATE_CLASS_EXCEPTION)r   r   r   rB   r"   r"   r#   get_mysql_exception   s(    
  rG   )packetr   c              
   C   s  d }}z| d dkrt dW n6 tk
rV } ztd| d W Y S d}~X Y nX d}zt| dd } t| d\} }| d	 d
krt| ttfr| d}q| }n*t| dd d\} }|d}| d}W n< tt	fk
r } ztd| d W Y S d}~X Y 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      rC   r   #   utf8r   )r<   
IndexErrorr.   r   r:   bytes	bytearraydecoder   UnicodeErrorrG   )rH   r   errmsgr   r   r"   r"   r#   get_exception  s(    &
&rT   )Z02Z07Z08Z0A21Z22Z23Z24Z25Z2627Z28Z2AZ2BZ2CZ2DZ2EZ33Z34Z35Z37Z3CZ3DZ3FZ40Z42Z44ZHZZXAZ0KZHYrF   )i  i  i  i  i  i  i  i  rE   )NN)NNF)(r(   typingr   r   r   r   r   r   Zlocalesr	   typesr
   utilsr   r   r?   r   r,   r.   r/   r0   r1   r2   r3   r4   r5   r6   ZErrorClassTypesZ
ErrorTypesr7   r*   __annotations__rA   r)   boolrG   rO   rT   rF   rE   r"   r"   r"   r#   <module>   s    )  E   *%#