def _ToDbApiException(sql_exception):
 exception = _ERROR_CODE_TO_EXCEPTION.get(sql_exception.code)
 if (not exception):
  if (sql_exception.code < 1000):
   exception = InternalError
  else:
   exception = OperationalError
 return exception(sql_exception.code, sql_exception.message)

def _ToDbApiException ( sql_exception ) : exception = _ERROR_CODE_TO_EXCEPTION . get ( sql_exception . code ) if ( not exception ) : if ( sql_exception . code < 1000 ) : exception = InternalError else : exception = OperationalError return exception ( sql_exception . code , sql_exception . message )
returns a db-api exception type appropriate for the given sql_exception .