From 134030337d7d30480b1f04dc3d1ef05d605bb7ce Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 3 Nov 2023 12:04:25 -0400 Subject: [PATCH] remove deprecated win32com.server.exception.Exception --- com/win32com/demos/excelAddin.py | 1 - com/win32com/demos/outlookAddin.py | 1 - com/win32com/demos/trybag.py | 9 ++-- com/win32com/server/connect.py | 12 ++--- com/win32com/server/exception.py | 14 ++---- com/win32com/server/policy.py | 6 +-- com/win32com/servers/interp.py | 10 ++-- com/win32com/servers/perfmon.py | 7 +-- com/win32com/test/testDynamic.py | 8 ++-- com/win32comext/axdebug/Test/host.py | 14 +++--- com/win32comext/axdebug/codecontainer.py | 10 ++-- com/win32comext/axdebug/gateways.py | 10 ++-- com/win32comext/axdebug/util.py | 6 +-- com/win32comext/axscript/client/error.py | 9 ++-- com/win32comext/axscript/client/framework.py | 48 +++++++++---------- com/win32comext/axscript/client/pydumper.py | 2 +- com/win32comext/axscript/client/pyscript.py | 4 +- com/win32comext/axscript/server/axsite.py | 5 +- com/win32comext/axscript/server/error.py | 2 +- com/win32comext/axscript/test/leakTest.py | 1 - com/win32comext/axscript/test/testHost.py | 2 - com/win32comext/axscript/test/testHost4Dbg.py | 1 - 22 files changed, 88 insertions(+), 94 deletions(-) diff --git a/com/win32com/demos/excelAddin.py b/com/win32com/demos/excelAddin.py index 8229477a8c..18a76eb8be 100644 --- a/com/win32com/demos/excelAddin.py +++ b/com/win32com/demos/excelAddin.py @@ -51,7 +51,6 @@ import pythoncom from win32com import universal from win32com.client import Dispatch, DispatchWithEvents, constants, gencache -from win32com.server.exception import COMException # Support for COM objects we use. gencache.EnsureModule( diff --git a/com/win32com/demos/outlookAddin.py b/com/win32com/demos/outlookAddin.py index 58f2f69878..244d5b325e 100644 --- a/com/win32com/demos/outlookAddin.py +++ b/com/win32com/demos/outlookAddin.py @@ -30,7 +30,6 @@ import pythoncom from win32com import universal from win32com.client import DispatchWithEvents, constants, gencache -from win32com.server.exception import COMException # Support for COM objects we use. gencache.EnsureModule( diff --git a/com/win32com/demos/trybag.py b/com/win32com/demos/trybag.py index 3d3918b6c2..07f0672fcb 100644 --- a/com/win32com/demos/trybag.py +++ b/com/win32com/demos/trybag.py @@ -1,5 +1,6 @@ import pythoncom -from win32com.server import exception, util +from win32com.server import util +from win32com.server.exception import COMException VT_EMPTY = pythoncom.VT_EMPTY @@ -18,7 +19,7 @@ def Read(self, propName, varType, errorLog): hr = 0x80070057 exc = pythoncom.com_error(0, "Bag.Read", "no such item", None, 0, hr) errorLog.AddError(propName, exc) - raise exception.Exception(scode=hr) + raise COMException(scode=hr) return self.data[propName] def Write(self, propName, value): @@ -31,7 +32,7 @@ class Target: _com_interfaces_ = [pythoncom.IID_IPersist, pythoncom.IID_IPersistPropertyBag] def GetClassID(self): - raise exception.Exception(scode=0x80004005) # E_FAIL + raise COMException(scode=0x80004005) # E_FAIL def InitNew(self): pass @@ -41,7 +42,7 @@ def Load(self, bag, log): print(bag.Read("prop2", VT_EMPTY, log)) try: print(bag.Read("prop3", VT_EMPTY, log)) - except exception.Exception: + except COMException: pass def Save(self, bag, clearDirty, saveAllProps): diff --git a/com/win32com/server/connect.py b/com/win32com/server/connect.py index 5c9a2dfe4a..a24bb75bca 100644 --- a/com/win32com/server/connect.py +++ b/com/win32com/server/connect.py @@ -7,7 +7,7 @@ import winerror from win32com import olectl -from .exception import Exception +from .exception import COMException # Methods implemented by the interfaces. IConnectionPointContainer_methods = ["EnumConnectionPoints", "FindConnectionPoint"] @@ -34,10 +34,10 @@ def __init__(self): # IConnectionPoint interfaces def EnumConnections(self): - raise Exception(winerror.E_NOTIMPL) + raise COMException(winerror.E_NOTIMPL) def GetConnectionInterface(self): - raise Exception(winerror.E_NOTIMPL) + raise COMException(winerror.E_NOTIMPL) def GetConnectionPointContainer(self): return win32com.server.util.wrap(self) @@ -50,7 +50,7 @@ def Advise(self, pUnk): self._connect_interfaces_[0], pythoncom.IID_IDispatch ) except pythoncom.com_error: - raise Exception(scode=olectl.CONNECT_E_NOCONNECTION) + raise COMException(scode=olectl.CONNECT_E_NOCONNECTION) self.cookieNo = self.cookieNo + 1 self.connections[self.cookieNo] = interface return self.cookieNo @@ -60,11 +60,11 @@ def Unadvise(self, cookie): try: del self.connections[cookie] except KeyError: - raise Exception(scode=winerror.E_UNEXPECTED) + raise COMException(scode=winerror.E_UNEXPECTED) # IConnectionPointContainer interfaces def EnumConnectionPoints(self): - raise Exception(winerror.E_NOTIMPL) + raise COMException(winerror.E_NOTIMPL) def FindConnectionPoint(self, iid): # Find a connection we support. Only support the single event interface. diff --git a/com/win32com/server/exception.py b/com/win32com/server/exception.py index 599636e730..7c9463bf41 100644 --- a/com/win32com/server/exception.py +++ b/com/win32com/server/exception.py @@ -17,7 +17,7 @@ import pythoncom -# Note that we derive from com_error, which derives from exceptions.Exception +# Note that we derive from com_error, which derives from builtin Exception # Also note that we dont support "self.args", as we dont support tuple-unpacking class COMException(pythoncom.com_error): """An Exception object that is understood by the framework. @@ -81,19 +81,13 @@ def __repr__(self): return f"" -# Old name for the COMException class. -# Do NOT use the name Exception, as it is now a built-in -# COMException is the new, official name. -Exception = COMException - - def IsCOMException(t=None): if t is None: t = sys.exc_info()[0] try: return issubclass(t, pythoncom.com_error) - except TypeError: # 1.5 in -X mode? - return t is pythoncon.com_error + except TypeError: # t is not a class (likely None or a str) + return t is pythoncom.com_error def IsCOMServerException(t=None): @@ -101,5 +95,5 @@ def IsCOMServerException(t=None): t = sys.exc_info()[0] try: return issubclass(t, COMException) - except TypeError: # String exception + except TypeError: # t is not a class (likely None or a str) return 0 diff --git a/com/win32com/server/policy.py b/com/win32com/server/policy.py index 7d46d83d02..e583eb6a83 100644 --- a/com/win32com/server/policy.py +++ b/com/win32com/server/policy.py @@ -46,13 +46,13 @@ not be Python. Therefore, general Python exceptions and tracebacks aren't much use. - In general, there is an Exception class that should be raised, to allow + In general, there is an COMException class that should be raised, to allow the framework to extract rich COM type error information. The general rule is that the **only** exception returned from Python COM - Server code should be an Exception instance. Any other Python exception + Server code should be an COMException instance. Any other Python exception should be considered an implementation bug in the server (if not, it - should be handled, and an appropriate Exception instance raised). Any + should be handled, and an appropriate COMException instance raised). Any other exception is considered "unexpected", and a dispatcher may take special action (see Dispatchers above) diff --git a/com/win32com/servers/interp.py b/com/win32com/servers/interp.py index 9636837b85..37d83bd497 100644 --- a/com/win32com/servers/interp.py +++ b/com/win32com/servers/interp.py @@ -12,7 +12,7 @@ """ import winerror -from win32com.server.exception import Exception +from win32com.server.exception import COMException # Expose the Python interpreter. @@ -33,14 +33,18 @@ def __init__(self): def Eval(self, exp): """Evaluate an expression.""" if not isinstance(exp, str): - raise Exception(desc="Must be a string", scode=winerror.DISP_E_TYPEMISMATCH) + raise COMException( + desc="Must be a string", scode=winerror.DISP_E_TYPEMISMATCH + ) return eval(str(exp), self.dict) def Exec(self, exp): """Execute a statement.""" if not isinstance(exp, str): - raise Exception(desc="Must be a string", scode=winerror.DISP_E_TYPEMISMATCH) + raise COMException( + desc="Must be a string", scode=winerror.DISP_E_TYPEMISMATCH + ) exec(str(exp), self.dict) diff --git a/com/win32com/servers/perfmon.py b/com/win32com/servers/perfmon.py index 861c694097..f57ae1f55a 100644 --- a/com/win32com/servers/perfmon.py +++ b/com/win32com/servers/perfmon.py @@ -7,7 +7,8 @@ import pythoncom import win32pdhutil import winerror -from win32com.server import exception, register +from win32com.server import register +from win32com.server.exception import COMException class PerfMonQuery: @@ -24,9 +25,9 @@ def Query(self, object, counter, instance=None, machine=None): object, counter, instance, machine=machine ) except win32pdhutil.error as exc: - raise exception.Exception(desc=exc.strerror) + raise COMException(desc=exc.strerror) except TypeError as desc: - raise exception.Exception(desc=desc, scode=winerror.DISP_E_TYPEMISMATCH) + raise COMException(desc=desc, scode=winerror.DISP_E_TYPEMISMATCH) if __name__ == "__main__": diff --git a/com/win32com/test/testDynamic.py b/com/win32com/test/testDynamic.py index ed0c5d1ddf..0d073c4a87 100644 --- a/com/win32com/test/testDynamic.py +++ b/com/win32com/test/testDynamic.py @@ -2,7 +2,7 @@ import pythoncom import winerror -from win32com.server.exception import Exception +from win32com.server.exception import COMException error = "testDynamic error" @@ -22,7 +22,7 @@ def _dynamic_(self, name, lcid, wFlags, args): ret = list(ret) return ret except KeyError: # Probably a method request. - raise Exception(scode=winerror.DISP_E_MEMBERNOTFOUND) + raise COMException(scode=winerror.DISP_E_MEMBERNOTFOUND) if wFlags & ( pythoncom.DISPATCH_PROPERTYPUT | pythoncom.DISPATCH_PROPERTYPUTREF @@ -30,11 +30,11 @@ def _dynamic_(self, name, lcid, wFlags, args): setattr(self, name, args[0]) return - raise Exception(scode=winerror.E_INVALIDARG, desc="invalid wFlags") + raise COMException(scode=winerror.E_INVALIDARG, desc="invalid wFlags") def write(self, *args): if len(args) == 0: - raise Exception( + raise COMException( scode=winerror.DISP_E_BADPARAMCOUNT ) # Probably call as PROPGET. diff --git a/com/win32comext/axdebug/Test/host.py b/com/win32comext/axdebug/Test/host.py index b3d1317462..44b6f9a7c7 100644 --- a/com/win32comext/axdebug/Test/host.py +++ b/com/win32comext/axdebug/Test/host.py @@ -6,7 +6,7 @@ import winerror from win32com.axdebug import codecontainer, gateways from win32com.axdebug.util import _wrap, trace -from win32com.server.exception import Exception +from win32com.server.exception import COMException class ExternalConnection: @@ -57,7 +57,7 @@ def _GetCodeContainer(self): try: codeText = open(self.module.__file__, "rt").read() except OSError as details: - codeText = f"# Exception opening file\n# {details}" + codeText = f"# COMException opening file\n# {details}" self.codeContainer = codecontainer.SourceCodeContainer( codeText, self.module.__file__ @@ -79,23 +79,23 @@ def GetDeferredText(self, dwTextStartCookie, maxChars, bWantAttr): def GetScriptTextAttributes(self, codeText, delimterText, flags): # Result must be an attribute sequence of same "length" as the code. trace("GetScriptTextAttributes", delimterText, flags) - raise Exception(scode=winerror.E_NOTIMPL) + raise COMException(scode=winerror.E_NOTIMPL) def OnCreateDocumentContext(self): # Result must be a PyIUnknown trace("OnCreateDocumentContext") - raise Exception(scode=winerror.E_NOTIMPL) + raise COMException(scode=winerror.E_NOTIMPL) def GetPathName(self): # Result must be (string, int) where the int is a BOOL # - TRUE if the path refers to the original file for the document. # - FALSE if the path refers to a newly created temporary file. - # - raise Exception(scode=E_FAIL) if no source file can be created/determined. + # - raise COMException(scode=E_FAIL) if no source file can be created/determined. trace("GetPathName") try: return win32api.GetFullPathName(self.module.__file__), 1 except (AttributeError, win32api.error): - raise Exception(scode=winerror.E_FAIL) + raise COMException(scode=winerror.E_FAIL) def GetFileName(self): # Result is a string with just the name of the document, no path information. @@ -104,7 +104,7 @@ def GetFileName(self): def NotifyChanged(): trace("NotifyChanged") - raise Exception(scode=winerror.E_NOTIMPL) + raise COMException(scode=winerror.E_NOTIMPL) def TestSmartProvider(): diff --git a/com/win32comext/axdebug/codecontainer.py b/com/win32comext/axdebug/codecontainer.py index 69a9f8e458..2030cf6954 100644 --- a/com/win32comext/axdebug/codecontainer.py +++ b/com/win32comext/axdebug/codecontainer.py @@ -12,7 +12,7 @@ import winerror from win32com.axdebug import axdebug, contexts from win32com.axdebug.util import _wrap -from win32com.server.exception import Exception +from win32com.server.exception import COMException _keywords = {} # set of Python keywords for name in """ @@ -65,7 +65,7 @@ def GetPositionOfLine(self, cLineNumber): try: return self.lineOffsets[cLineNumber] except IndexError: - raise Exception(scode=winerror.S_FALSE) + raise COMException(scode=winerror.S_FALSE) def GetLineOfPosition(self, charPos): self.GetText() # Prime us. @@ -78,7 +78,7 @@ def GetLineOfPosition(self, charPos): lineNo = lineNo + 1 else: # for not broken. # print("Cant find", charPos, "in", self.lineOffsets) - raise Exception(scode=winerror.S_FALSE) + raise COMException(scode=winerror.S_FALSE) # print("GLOP ret=", lineNo, (charPos - lastOffset)) return lineNo, (charPos - lastOffset) @@ -225,7 +225,7 @@ def GetText(self): try: self.text = open(fname, "r").read() except OSError as details: - self.text = f"# Exception opening file\n# {repr(details)}" + self.text = f"# COMException opening file\n# {repr(details)}" else: self.text = f"# No file available for module '{self.module}'" self._buildlines() @@ -248,7 +248,7 @@ def GetName(self, dnt): elif dnt == axdebug.DOCUMENTNAMETYPE_URL: return f"file:{fname}" else: - raise Exception(scode=winerror.E_UNEXPECTED) + raise COMException(scode=winerror.E_UNEXPECTED) if __name__ == "__main__": diff --git a/com/win32comext/axdebug/gateways.py b/com/win32comext/axdebug/gateways.py index d87e85b335..19f803eaf6 100644 --- a/com/win32comext/axdebug/gateways.py +++ b/com/win32comext/axdebug/gateways.py @@ -5,7 +5,7 @@ import winerror from win32com.axdebug import axdebug from win32com.axdebug.util import RaiseNotImpl, _wrap -from win32com.server.exception import Exception +from win32com.server.exception import COMException from win32com.server.util import ListEnumeratorGateway @@ -233,7 +233,7 @@ def GetPathName(self): - if fIsOriginalPath is TRUE if the path refers to the original file for the document. - if fIsOriginalPath is FALSE if the path refers to a newly created temporary file. - raise Exception(winerror.E_FAIL) if no source file can be created/determined. + raise COMException(winerror.E_FAIL) if no source file can be created/determined. """ RaiseNotImpl("GetPathName") @@ -398,7 +398,7 @@ def GetPathName(self): # Result must be (string, int) where the int is a BOOL # - TRUE if the path refers to the original file for the document. # - FALSE if the path refers to a newly created temporary file. - # - raise Exception(scode=E_FAIL) if no source file can be created/determined. + # - raise COMException(scode=E_FAIL) if no source file can be created/determined. RaiseNotImpl("GetPathName") def GetFileName(self): @@ -449,7 +449,7 @@ def Unadvise(self, cookie): try: del self.connections[cookie] except KeyError: - return Exception(scode=winerror.E_UNEXPECTED) + return COMException(scode=winerror.E_UNEXPECTED) # IConnectionPointContainer interfaces def EnumConnectionPoints(self): @@ -459,7 +459,7 @@ def FindConnectionPoint(self, iid): # Find a connection we support. Only support the single event interface. if iid == axdebug.IID_IDebugDocumentTextEvents: return _wrap(self) - raise Exception(scode=winerror.E_NOINTERFACE) # ?? + raise COMException(scode=winerror.E_NOINTERFACE) # ?? class RemoteDebugApplicationEvents: diff --git a/com/win32comext/axdebug/util.py b/com/win32comext/axdebug/util.py index 805d21b28b..46806ae547 100644 --- a/com/win32comext/axdebug/util.py +++ b/com/win32comext/axdebug/util.py @@ -7,7 +7,7 @@ import win32api import win32com.server.util import winerror -from win32com.server.exception import Exception +from win32com.server.exception import COMException try: os.environ["DEBUG_AXDEBUG"] @@ -66,7 +66,7 @@ def RaiseNotImpl(who=None): frame = frame.f_back # and raise the exception for COM - raise Exception(scode=winerror.E_NOTIMPL) + raise COMException(scode=winerror.E_NOTIMPL) import win32com.server.policy @@ -101,7 +101,7 @@ def _Invoke_(self, dispid, lcid, wFlags, args): ) # print("Invoke of", dispid, "returning", rc) return rc - except Exception: + except COMException: t, v, tb = sys.exc_info() tb = None # A cycle scode = v.scode diff --git a/com/win32comext/axscript/client/error.py b/com/win32comext/axscript/client/error.py index c4d24db9de..f10c6db574 100644 --- a/com/win32comext/axscript/client/error.py +++ b/com/win32comext/axscript/client/error.py @@ -8,10 +8,10 @@ import traceback import pythoncom -import win32com.server.exception import win32com.server.util import winerror from win32com.axscript import axscript +from win32com.server.exception import COMException debugging = 0 @@ -64,7 +64,7 @@ def GetExceptionInfo(self): return self.exception -class AXScriptException(win32com.server.exception.COMException): +class AXScriptException(COMException): """A class used as a COM exception. Note this has attributes which conform to the standard attributes @@ -74,8 +74,7 @@ class AXScriptException(win32com.server.exception.COMException): def __init__(self, site, codeBlock, exc_type, exc_value, exc_traceback): # set properties base class shares via base ctor... - win32com.server.exception.COMException.__init__( - self, + super().__init__( description="Unknown Exception", scode=winerror.DISP_E_EXCEPTION, source="Python ActiveX Scripting Engine", @@ -248,7 +247,7 @@ def ProcessAXScriptException(scriptingSite, debugManager, exceptionInstance): if result == winerror.S_OK: # If the above returns NOERROR, it is assumed the error has been # correctly registered and the value SCRIPT_E_REPORTED is returned. - ret = win32com.server.exception.COMException(scode=axscript.SCRIPT_E_REPORTED) + ret = COMException(scode=axscript.SCRIPT_E_REPORTED) return ret else: # The error is taken to be unreported and is propagated up the call stack diff --git a/com/win32comext/axscript/client/framework.py b/com/win32comext/axscript/client/framework.py index 93f9d53741..f6593686e4 100644 --- a/com/win32comext/axscript/client/framework.py +++ b/com/win32comext/axscript/client/framework.py @@ -28,7 +28,7 @@ def RemoveCR(text): SCRIPTTEXT_ISEXPRESSION = 0x00000020 SCRIPTTEXT_ISPERSISTENT = 0x00000040 -from win32com.server.exception import Exception, IsCOMServerException +from win32com.server.exception import COMException, IsCOMServerException from . import error # ax.client.error @@ -113,7 +113,7 @@ def RaiseAssert(scode, desc): """A debugging function that raises an exception considered an "Assertion".""" print("**************** ASSERTION FAILED *******************") print(desc) - raise Exception(desc, scode) + raise COMException(desc, scode) class AXScriptCodeBlock: @@ -206,7 +206,7 @@ def _invoke_(self, dispid, lcid, wFlags, args): try: event = self.events[dispid] except: - raise Exception(scode=winerror.DISP_E_MEMBERNOTFOUND) + raise COMException(scode=winerror.DISP_E_MEMBERNOTFOUND) # print("Invoke for ", event, "on", self.myScriptItem, " - calling", self.myInvokeMethod) return self.myInvokeMethod(self.myScriptItem, event, lcid, wFlags, args) @@ -403,10 +403,10 @@ def GetCreateSubItem(self, parentItem, name, dispatch, flags): rc = self.subItems[keyName] # No changes allowed to existing flags. if not rc.flags is None and not flags is None and rc.flags != flags: - raise Exception(scode=winerror.E_INVALIDARG) + raise COMException(scode=winerror.E_INVALIDARG) # Existing item must not have a dispatch. if not rc.dispatch is None and not dispatch is None: - raise Exception(scode=winerror.E_INVALIDARG) + raise COMException(scode=winerror.E_INVALIDARG) rc.flags = flags # Setup the real flags. rc.dispatch = dispatch except KeyError: @@ -769,7 +769,7 @@ def SetScriptSite(self, site): def GetScriptSite(self, iid): if self.scriptSite is None: - raise Exception(scode=winerror.S_FALSE) + raise COMException(scode=winerror.S_FALSE) return self.scriptSite.QueryInterface(iid) def SetScriptState(self, state): @@ -778,7 +778,7 @@ def SetScriptState(self, state): return # If closed, allow no other state transitions if self.scriptState == axscript.SCRIPTSTATE_CLOSED: - raise Exception(scode=winerror.E_INVALIDARG) + raise COMException(scode=winerror.E_INVALIDARG) if state == axscript.SCRIPTSTATE_INITIALIZED: # Re-initialize - shutdown then reset. @@ -820,7 +820,7 @@ def SetScriptState(self, state): self.Reset() self.ChangeScriptState(state) else: - raise Exception(scode=winerror.E_INVALIDARG) + raise COMException(scode=winerror.E_INVALIDARG) def GetScriptState(self): return self.scriptState @@ -861,12 +861,12 @@ def Close(self): def AddNamedItem(self, name, flags): if self.scriptSite is None: - raise Exception(scode=winerror.E_INVALIDARG) + raise COMException(scode=winerror.E_INVALIDARG) try: unknown = self.scriptSite.GetItemInfo(name, axscript.SCRIPTINFO_IUNKNOWN)[0] dispatch = unknown.QueryInterface(pythoncom.IID_IDispatch) except pythoncom.com_error: - raise Exception( + raise COMException( scode=winerror.E_NOINTERFACE, desc="Object has no dispatch interface available.", ) @@ -878,23 +878,23 @@ def AddNamedItem(self, name, flags): def GetScriptDispatch(self, name): # Base classes should override. - raise Exception(scode=winerror.E_NOTIMPL) + raise COMException(scode=winerror.E_NOTIMPL) def GetCurrentScriptThreadID(self): return self.baseThreadId def GetScriptThreadID(self, win32ThreadId): if self.baseThreadId == -1: - raise Exception(scode=winerror.E_UNEXPECTED) + raise COMException(scode=winerror.E_UNEXPECTED) if self.baseThreadId != win32ThreadId: - raise Exception(scode=winerror.E_INVALIDARG) + raise COMException(scode=winerror.E_INVALIDARG) return self.baseThreadId def GetScriptThreadState(self, scriptThreadId): if self.baseThreadId == -1: - raise Exception(scode=winerror.E_UNEXPECTED) + raise COMException(scode=winerror.E_UNEXPECTED) if scriptThreadId != self.baseThreadId: - raise Exception(scode=winerror.E_INVALIDARG) + raise COMException(scode=winerror.E_INVALIDARG) return self.threadState def AddTypeLib(self, uuid, major, minor, flags): @@ -906,10 +906,10 @@ def AddTypeLib(self, uuid, major, minor, flags): # This is never called by the C++ framework - it does magic. # See PyGActiveScript.cpp # def InterruptScriptThread(self, stidThread, exc_info, flags): - # raise Exception("Not Implemented", scode=winerror.E_NOTIMPL) + # raise COMException("Not Implemented", scode=winerror.E_NOTIMPL) def Clone(self): - raise Exception("Not Implemented", scode=winerror.E_NOTIMPL) + raise COMException("Not Implemented", scode=winerror.E_NOTIMPL) # # IObjectSafety @@ -939,7 +939,7 @@ def SetInterfaceSafetyOptions(self, iid, optionsMask, enabledOptions): supported = self._GetSupportedInterfaceSafetyOptions() self.safetyOptions = supported & optionsMask & enabledOptions else: - raise Exception(scode=winerror.E_NOINTERFACE) + raise COMException(scode=winerror.E_NOINTERFACE) def _GetSupportedInterfaceSafetyOptions(self): return 0 @@ -955,7 +955,7 @@ def GetInterfaceSafetyOptions(self, iid): supported = self._GetSupportedInterfaceSafetyOptions() return supported, self.safetyOptions else: - raise Exception(scode=winerror.E_NOINTERFACE) + raise COMException(scode=winerror.E_NOINTERFACE) # # Other helpers. @@ -1021,7 +1021,7 @@ def Run(self): self.scriptState != axscript.SCRIPTSTATE_INITIALIZED and self.scriptState != axscript.SCRIPTSTATE_STARTED ): - raise Exception(scode=winerror.E_UNEXPECTED) + raise COMException(scode=winerror.E_UNEXPECTED) # self._DumpNamedItems_() self.ExecutePendingScripts() self.DoRun() @@ -1199,7 +1199,7 @@ def HandleException(self, codeBlock): ): # Ensure the traceback doesnt cause a cycle. exc_traceback = None - raise Exception(scode=exc_value.hresult) + raise COMException(scode=exc_value.hresult) exception = error.AXScriptException( self, codeBlock, exc_type, exc_value, exc_traceback @@ -1226,12 +1226,12 @@ def HandleException(self, codeBlock): def BeginScriptedSection(self): if self.scriptSite is None: - raise Exception(scode=winerror.E_UNEXPECTED) + raise COMException(scode=winerror.E_UNEXPECTED) self.scriptSite.OnEnterScript() def EndScriptedSection(self): if self.scriptSite is None: - raise Exception(scode=winerror.E_UNEXPECTED) + raise COMException(scode=winerror.E_UNEXPECTED) self.scriptSite.OnLeaveScript() def DisableInterrupts(self): @@ -1244,7 +1244,7 @@ def GetNamedItem(self, name): try: return self.subItems[name] except KeyError: - raise Exception(scode=winerror.E_INVALIDARG) + raise COMException(scode=winerror.E_INVALIDARG) def GetNamedItemClass(self): return ScriptItem diff --git a/com/win32comext/axscript/client/pydumper.py b/com/win32comext/axscript/client/pydumper.py index 3d0725aeff..39bf892845 100644 --- a/com/win32comext/axscript/client/pydumper.py +++ b/com/win32comext/axscript/client/pydumper.py @@ -16,7 +16,7 @@ from win32com.axscript import axscript from . import pyscript -from .pyscript import SCRIPTTEXT_FORCEEXECUTION, Exception, RaiseAssert, trace +from .pyscript import SCRIPTTEXT_FORCEEXECUTION, RaiseAssert, trace PyDump_CLSID = "{ac527e60-c693-11d0-9c25-00aa00125a98}" diff --git a/com/win32comext/axscript/client/pyscript.py b/com/win32comext/axscript/client/pyscript.py index 0ce08fc35e..1594d46373 100644 --- a/com/win32comext/axscript/client/pyscript.py +++ b/com/win32comext/axscript/client/pyscript.py @@ -22,10 +22,10 @@ SCRIPTTEXT_FORCEEXECUTION, SCRIPTTEXT_ISEXPRESSION, SCRIPTTEXT_ISPERSISTENT, - Exception, RaiseAssert, trace, ) +from win32com.server.exception import COMException PyScript_CLSID = "{DF630910-1C1D-11d0-AE36-8C0F5E000000}" @@ -366,7 +366,7 @@ def DoProcessScriptItemEvent(self, item, event, lcid, wFlags, args): item.scriptlets[funcName] = function if function is None: - raise Exception(scode=winerror.DISP_E_MEMBERNOTFOUND) + raise COMException(scode=winerror.DISP_E_MEMBERNOTFOUND) return self.ApplyInScriptedSection(codeBlock, function, args) def DoParseScriptText( diff --git a/com/win32comext/axscript/server/axsite.py b/com/win32comext/axscript/server/axsite.py index 29fa0ebe93..f907789397 100644 --- a/com/win32comext/axscript/server/axsite.py +++ b/com/win32comext/axscript/server/axsite.py @@ -2,7 +2,8 @@ import win32com.axscript.axscript import winerror from win32com.axscript import axscript -from win32com.server import exception, util +from win32com.server import util +from win32com.server.exception import COMException class AXEngine: @@ -115,7 +116,7 @@ def GetLCID(self): def GetItemInfo(self, name, returnMask): if name not in self.objModel: - raise exception.Exception( + raise COMException( scode=winerror.TYPE_E_ELEMENTNOTFOUND, desc="item not found" ) diff --git a/com/win32comext/axscript/server/error.py b/com/win32comext/axscript/server/error.py index 82491a6ebe..4ae196a96a 100644 --- a/com/win32comext/axscript/server/error.py +++ b/com/win32comext/axscript/server/error.py @@ -8,7 +8,7 @@ """ -class Exception: +class Exception: # unused and shadows builtin Exception def __init__(self, activeScriptError): self.activeScriptError = activeScriptError diff --git a/com/win32comext/axscript/test/leakTest.py b/com/win32comext/axscript/test/leakTest.py index b75948eaed..98a589d3ef 100644 --- a/com/win32comext/axscript/test/leakTest.py +++ b/com/win32comext/axscript/test/leakTest.py @@ -4,7 +4,6 @@ import win32com.server.policy from win32com.axscript import axscript from win32com.axscript.server import axsite -from win32com.axscript.server.error import Exception from win32com.server import connect, util diff --git a/com/win32comext/axscript/test/testHost.py b/com/win32comext/axscript/test/testHost.py index ee6210fa65..e0b9995acb 100644 --- a/com/win32comext/axscript/test/testHost.py +++ b/com/win32comext/axscript/test/testHost.py @@ -6,10 +6,8 @@ import win32com.test.util from win32com.axscript import axscript from win32com.axscript.server import axsite -from win32com.axscript.server.error import Exception from win32com.client.dynamic import Dispatch from win32com.server import connect, util -from win32com.server.exception import COMException verbose = "-v" in sys.argv diff --git a/com/win32comext/axscript/test/testHost4Dbg.py b/com/win32comext/axscript/test/testHost4Dbg.py index 2092b045c0..c618a41206 100644 --- a/com/win32comext/axscript/test/testHost4Dbg.py +++ b/com/win32comext/axscript/test/testHost4Dbg.py @@ -6,7 +6,6 @@ import win32ui from win32com.axscript import axscript from win32com.axscript.server import axsite -from win32com.axscript.server.error import Exception from win32com.server import util version = "0.0.1"