g'dZddlmZddlmZddlmZiad4dZd4dZ dZ Gd d e Z Gd d e Z Gd de ZGdde ZGddeZGddeZGddeZGddeZGddeZGddeZGdde ZGdd e Zid!ed"ed#ed$ed%ed&ed'ed(ed)ed*ed+ed,ed-ed.ed/ed0ed1eeeeeeeeeeeeeeed2Zeeeeeeed3Zy)5zPython exceptions )utils)get_client_error)PY2Nct|trt|siatS|s|stSt|ttfs t dt|tr||i}|j D]A\}}t|ts t d t|tst |t|<CtS#t$r t dwxYw)ayDefine 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. zGet 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)rr)r KeyError_ERROR_EXCEPTIONS DatabaseError_SQLSTATE_CLASS_EXCEPTION)rrrs rget_mysql_exceptionres '.585 5      '585 5     E22F(!A7585 5 FEHEEFs, 4 AAA''BBcdx}} |ddk7r td d} |dd}tj|d\}}|dd k7r+t |t tfr|jd }nA|}n>tj|d dd\}}|jd }|jd }t|||S#t$r}td|zcYd}~Sd}~wwxYw#t$r}td|zcYd}~Sd}~wwxYw) 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 IndexErrorInterfaceErrorrread_intrbytes bytearraydecode read_bytesrr)packetrerrmsgerrrs r get_exceptionr0sEFM !9 <= =  H<..3 !9?&5)"45v.!&!1!1&*a!@ VXv.H]]6*F#5&(;;) MEKLLM" MEKLLMs;B9BC9 C CCC C>& C93C>9C>c*eZdZdZdfd ZdZxZS)Errorz;Exception that is base class for all other error exceptionscFtt| ||_|j|_|xsd|_||_|jsJd|j cxkrdkr5nn2t|j |_|0 |j|z|_n|jsdx|_|_|jr|j dk7rq|j tr|jjdn |jd}|j rd}|j |d <nd }|jd i||_|j |j|j f|_ y#t$r4}dj|jt||_Yd}~d}~wwxYw) Nii z{0} (Warning: {1})z Unknown errorr%)rrz{errno} ({state}): {msg}statez{errno}: {msg})superr2__init__r _full_msgrrrrformatstrrencodeargs) selfrrvaluesrr/fieldsfmt __class__s rr8zError.__init__sG eT#%[b   xxTTZZ6$6' 3DH!O#xx&0DH(7 7DNTX 88 b(25txxv.488F}}0"&--w&'SZZ1&1DNZZ? #!O3::488SXNDHHOs?E## F ,*FF c|jS)N)r9)r>s r__str__z Error.__str__s ~~)NNNN)__name__ __module__ __qualname____doc__r8rD __classcell__)rBs@rr2r2sE@>rEr2ceZdZdZy)Warningz Exception for important warningsNrFrGrHrIr6rErrLrLs*rErLceZdZdZy)r'z-Exception for errors related to the interfaceNrMr6rErr'r'7rEr'ceZdZdZy)rz,Exception for errors related to the databaseNrMr6rErrrs6rErceZdZdZy) InternalErrorz-Exception for errors internal database errorsNrMr6rErrRrRrOrErRceZdZdZy)OperationalErrorz8Exception for errors related to the database's operationNrMr6rErrTrTsBrErTceZdZdZy)ProgrammingErrorz'Exception for errors programming errorsNrMr6rErrVrVs1rErVceZdZdZy)IntegrityErrorz3Exception for errors regarding relational integrityNrMr6rErrXrX=rErXceZdZdZy) DataErrorz;Exception for errors reporting problems with processed dataNrMr6rErr[r[sErEr[ceZdZdZy)NotSupportedErrorzBException for errors when an unsupported database feature was usedNrMr6rErr]r]sLrEr]ceZdZdZy) PoolErrorz3Exception for errors relating to connection poolingNrMr6rErr_r_rYrEr_ceZdZdZy)MySQLFabricErrorz-Exception for errors relating to MySQL FabricNrMr6rErraras7rEra0207080A21222324252627282A2B2C2D2E)333435373C3D3F404244HZXA0KHY)iiiiiii )NN)rIrlocalesrcatch23rr rrr0rr2rLr'rrRrTrVrXr[r]r_rarrr6rErrs0% >$@!FF!