Exemple #1
0
 def _get_error_str(self, err):
     # RETURN ERROR STRING FOR OPC OR COMM ERROR CODE
     hr, msg, exc, arg = err
     if exc == None:
         error_str = str(msg)
     else:
         scode = exc[5]
         try:
             opc_err_str = unicode(
                 self._opc.GetErrorString(scode)).strip('\r\n')
         except:
             opc_err_str = None
         try:
             com_err_str = unicode(
                 pythoncom.GetScodeString(scode)).strip('\r\n')
         except:
             com_err_str = None
         # OPC ERROR AND COMM ERROR OVERLAP, SO WE COMBINE INTO SINGLE
         # ERROR MESSAGE
         if opc_err_str == None and com_err_str == None:
             error_str = str(scode)
         elif opc_err_str == com_err_str:
             error_str = opc_err_str
         elif opc_err_str == None:
             error_str = com_err_str
         elif com_err_str == None:
             error_str = opc_err_str
         else:
             error_str = '%s (%s)' % (opc_err_str, com_err_str)
     return error_str
Exemple #2
0
    def _get_error_str(self, err):
        """Return the error string for a OPC or COM error code"""

        hr, msg, exc, arg = err.args
        if exc == None:
            error_str = str(msg)
        else:
            scode = exc[5]

            try:
                opc_err_str = str(
                    self._opc.GetErrorString(scode)).strip('\r\n')
            except:
                opc_err_str = None

            try:
                com_err_str = str(
                    pythoncom.GetScodeString(scode)).strip('\r\n')
            except:
                com_err_str = None

            # OPC error codes and COM error codes are overlapping concepts,
            # so we combine them together into a single error message.
            if opc_err_str == None and com_err_str == None:
                error_str = str(scode)
            elif opc_err_str == com_err_str:
                error_str = opc_err_str
            elif opc_err_str == None:
                error_str = com_err_str
            elif com_err_str == None:
                error_str = opc_err_str
            else:
                error_str = '%s (%s)' % (opc_err_str, com_err_str)
        return error_str
Exemple #3
0
    def __init__(
        self,
        description=None,
        scode=None,
        source=None,
        helpfile=None,
        helpContext=None,
        desc=None,
        hresult=None,
    ):
        """Initialize an exception
        **Params**

        description -- A string description for the exception.
        scode -- An integer scode to be returned to the server, if necessary.
        The pythoncom framework defaults this to be DISP_E_EXCEPTION if not specified otherwise.
        source -- A string which identifies the source of the error.
        helpfile -- A string which points to a help file which contains details on the error.
        helpContext -- An integer context in the help file.
        desc -- A short-cut for description.
        hresult -- A short-cut for scode.
        """

        # convert a WIN32 error into an HRESULT
        scode = scode or hresult
        if scode and scode != 1:  # We dont want S_FALSE mapped!
            if scode >= -32768 and scode < 32768:
                # this is HRESULT_FROM_WIN32()
                scode = -2147024896 | (scode & 0x0000FFFF)
        self.scode = scode

        self.description = description or desc
        if scode == 1 and not self.description:
            self.description = "S_FALSE"
        elif scode and not self.description:
            self.description = pythoncom.GetScodeString(scode)

        self.source = source
        self.helpfile = helpfile
        self.helpcontext = helpContext

        # todo - fill in the exception value
        pythoncom.com_error.__init__(self, scode, self.description, None, -1)
Exemple #4
0
def GetScodeString(hr):
    if not mapiErrorTable:
        for name, value in mapi.__dict__.items():
            if name[:7] in ['MAPI_E_', 'MAPI_W_']:
                mapiErrorTable[value] = name
    return mapiErrorTable.get(hr, pythoncom.GetScodeString(hr))