U e' @sddZddlmZddlmZddlmZiad&ddZd'dd Z d d Z Gd d d e Z Gddde Z Gddde ZGddde ZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGd d!d!e ZGd"d#d#e Zeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed$Zeeeeeeed%ZdS)(zPython exceptions )utils)get_client_error)PY2Nc Cst|trt|siatS|s&|s&tSt|ttfsGet 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 )msgrsqlstate)rrN)rKeyError_ERROR_EXCEPTIONS DatabaseError_SQLSTATE_CLASS_EXCEPTION)rrrrrrget_mysql_exceptiones4  rc Csd}}z|ddkrtdWn2tk rR}ztd|WYSd}~XYnXd}zx|dd}t|d\}}|dd krt|ttfr|d }q|}n,t |d dd\}}|d }|d }Wn4t k r}ztd|WYSd}~XYnXt |||SdS) 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. NzPacket is not an error packetz%Failed getting Error information (%r)rr#utf8r) r IndexErrorInterfaceErrorrZread_intrbytes bytearraydecode read_bytesr r)packetrerrmsgerrrrrr get_exceptions(  "    "r,cs*eZdZdZdfdd ZddZZS)Errorz;Exception that is base class for all other error exceptionsNc s.tt|||_|j|_|p"d|_||_|jsd|jkrHdkrnn^t|j|_|dk rz|j||_Wqtk r}zd |jt ||_W5d}~XYqXn|jsd|_|_|jr|jdkr|jt r|j dn|jd}|jrd}|j|d <nd }|j f||_|j|j|jf|_ dS) Nii z{0} (Warning: {1})z Unknown errorr")rrz{errno} ({state}): {msg}statez{errno}: {msg})superr-__init__r _full_msgrrrrformatstrrencodeargs)selfrrvaluesrr+fieldsfmt __class__rrr1s0   (  zError.__init__cCs|jS)N)r2)r7rrr__str__sz Error.__str__)NNNN)__name__ __module__ __qualname____doc__r1r= __classcell__rrr;rr-sr-c@seZdZdZdS)Warningz Exception for important warningsNr>r?r@rArrrrrCsrCc@seZdZdZdS)r$z-Exception for errors related to the interfaceNrDrrrrr$sr$c@seZdZdZdS)rz,Exception for errors related to the databaseNrDrrrrrsrc@seZdZdZdS) InternalErrorz-Exception for errors internal database errorsNrDrrrrrEsrEc@seZdZdZdS)OperationalErrorz8Exception for errors related to the database's operationNrDrrrrrFsrFc@seZdZdZdS)ProgrammingErrorz'Exception for errors programming errorsNrDrrrrrGsrGc@seZdZdZdS)IntegrityErrorz3Exception for errors regarding relational integrityNrDrrrrrHsrHc@seZdZdZdS) DataErrorz;Exception for errors reporting problems with processed dataNrDrrrrrIsrIc@seZdZdZdS)NotSupportedErrorzBException for errors when an unsupported database feature was usedNrDrrrrrJsrJc@seZdZdZdS) PoolErrorz3Exception for errors relating to connection poolingNrDrrrrrKsrKc@seZdZdZdS)MySQLFabricErrorz-Exception for errors relating to MySQL FabricNrDrrrrrLsrL)Z02Z07Z08Z0A21Z22Z23Z24Z25Z2627Z28Z2AZ2BZ2CZ2DZ2EZ33Z34Z35Z37Z3CZ3DZ3FZ40Z42Z44ZHZZXAZ0KZHY)iiiiiii )NN)NN)rArZlocalesrZcatch23rrrrr,r r-rCr$rrErFrGrHrIrJrKrLrrrrrrsv    @ #$%#