home *** CD-ROM | disk | FTP | other *** search
- import exceptions
- import types
-
- # The following classes are original CCP products
-
-
- #---------------------------------------------------------------------------------
- class UserError(Exception):
- """User information"""
- __guid__ = 'exceptions.UserError'
- __persistvars__ = ['args','dict','msg']
-
-
- #---------------------------------------------------------------------------------
- def __init__(self, msg = None, *args):
- if type(msg) == types.InstanceType and msg.__class__ == UserError:
- self.msg = msg.msg
- self.dict = msg.dict
- self.args = (self.msg, self.dict)
- return
-
- if type(msg) not in [types.StringType, types.NoneType]:
- raise RuntimeError("Invalid argument, msg must be a string", msg)
-
- self.msg = msg
- if len(args) and type(args[0]) == type({}):
- self.dict = args[0]
- self.args = (self.msg, self.dict)
- else:
- self.dict = None
- self.args = (self.msg, ) + args
-
-
- #---------------------------------------------------------------------------------
- def __str__(self):
- try:
- msg = cfg.GetMessage(self.msg, self.dict)
- return "[%s] %s - %s" % (msg.type, msg.title, msg.text)
- except:
- return "User error, msg=%s, dict=%s" % (self.msg, self.dict)
-
-
-
- #---------------------------------------------------------------------------------
- class SQLError(Exception):
- __guid__ = 'exceptions.SQLError'
-
-
- #---------------------------------------------------------------------------------
- def __init__(self, source, server, sql, procname, lineno, paramErrors, colErrors, errorRecords):
- self.source = source
- self.server = server
- self.sql = sql
- self.procname = procname
- self.lineno = lineno
- self.paramErrors = paramErrors # [colidx, colname, status, statusStr, type, typeStr]
- self.colErrors = colErrors # [colidx, colname, status, statusStr]
- self.errorRecords = errorRecords # [descr, ansicode, nativecode, state, class]
- self.procParams = []
-
-
- #---------------------------------------------------------------------------------
- def __str__(self):
- return """
- Source: %s
- Server: %s
- SQL: %s
- Proc.: %s(%s)
-
- ParamErrors: %s
- ColErrors: %s
- ErrorRecs: %s
- Parameters: %s""" % (
- self.source,
- self.server,
- self.sql,
- self.procname,
- self.lineno,
- self.paramErrors,
- self.colErrors,
- self.errorRecords,
- self.procParams
- )
-
-
- #---------------------------------------------------------------------------------
- class UnmarshalError(Exception):
- __guid__ = 'exceptions.SQLError'
-
-
- #---------------------------------------------------------------------------------
- def __init__(self, exception, size, pos, crc):
- self.exception = exception
- self.size = size
- self.pos = pos
- self.crc = crc
-
-
- #---------------------------------------------------------------------------------
- def __str__(self):
- return """
- Exception: %s
- Pikl size: %s
- Pikl pos.: %s
- CRC: %s""" % (self.exception, self.size, self.pos, self.crc)
-
-
-
-
- # Put the custom exceptions into builtins
- import __builtin__
- __builtin__.UserError = UserError
- __builtin__.SQLError = SQLError
- __builtin__.UnmarshalError = UnmarshalError
-
-
-
-