From cae38cd56336282bdb0fa4d96315219c5b5fcc9b Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 21 Sep 2023 20:06:45 -0400 Subject: [PATCH 1/4] Cleanup win32comext.axdebug --- com/win32comext/axdebug/Test/host.py | 75 +++---------------- com/win32comext/axdebug/adb.py | 39 +++++----- com/win32comext/axdebug/codecontainer.py | 26 +++---- com/win32comext/axdebug/contexts.py | 5 +- com/win32comext/axdebug/debugger.py | 30 +++----- com/win32comext/axdebug/documents.py | 17 ++--- com/win32comext/axdebug/dump.py | 2 +- com/win32comext/axdebug/expressions.py | 15 ++-- com/win32comext/axdebug/stackframe.py | 39 +++++----- com/win32comext/axdebug/util.py | 28 +------ com/win32comext/axscript/client/debug.py | 6 +- com/win32comext/axscript/test/testHost4Dbg.py | 1 - 12 files changed, 92 insertions(+), 191 deletions(-) diff --git a/com/win32comext/axdebug/Test/host.py b/com/win32comext/axdebug/Test/host.py index da99b1b2fe..e28622f6b0 100644 --- a/com/win32comext/axdebug/Test/host.py +++ b/com/win32comext/axdebug/Test/host.py @@ -3,12 +3,9 @@ import pythoncom import win32api -import win32com.server.util import winerror -from win32com.axdebug import adb, axdebug, codecontainer, contexts, documents, gateways -from win32com.axdebug.util import _wrap, _wrap_remove, trace -from win32com.axscript import axscript -from win32com.client.util import Enumerator +from win32com.axdebug import codecontainer, gateways +from win32com.axdebug.util import _wrap, trace from win32com.server.exception import Exception @@ -26,8 +23,10 @@ def ReleaseConnection(self, extconn, reserved, fLastReleaseCloses): return self.numExtRefs -# externalConnectionManager = ExternalConnection() -# wrappedExternalConnectionManager = _wrap(externalConnectionManager, pythoncom.IID_IExternalConnection) +externalConnectionManager = ExternalConnection() +wrappedExternalConnectionManager = _wrap( + externalConnectionManager, pythoncom.IID_IExternalConnection +) def DelegatedExternalConnectionQI(iid): @@ -97,71 +96,25 @@ def GetPathName(self): try: return win32api.GetFullPathName(self.module.__file__), 1 except (AttributeError, win32api.error): - raise Exception(scode == E_FAIL) + raise Exception(scode=winerror.E_FAIL) def GetFileName(self): # Result is a string with just the name of the document, no path information. trace("GetFileName") - return os.path.split(module.__file__) + return os.path.split(self.module.__file__) def NotifyChanged(): trace("NotifyChanged") raise Exception(scode=winerror.E_NOTIMPL) -def TestSmartHelper(): - pdm = pythoncom.CoCreateInstance( - axdebug.CLSID_ProcessDebugManager, - None, - pythoncom.CLSCTX_ALL, - axdebug.IID_IProcessDebugManager, - ) - app = pdm.CreateApplication() - app.SetName("Python Process") - - pydebugger = adb.Debugger() - - nodes = BuildModuleTree() - - all_real_nodes = CreateDebugDocumentHelperNodes(pdm, app, nodes) - root = app.GetRootNode() - AttachParentNodes(root, nodes, all_real_nodes) - - pydebugger.AttachApp(app) - cookie = pdm.AddApplication(app) - input("Waiting...") - ttest.test() - - pdm.RemoveApplication(cookie) - print("Done") - - -def testdumb(): - pdm = pythoncom.CoCreateInstance( - axdebug.CLSID_ProcessDebugManager, - None, - pythoncom.CLSCTX_ALL, - axdebug.IID_IProcessDebugManager, - ) - app = pdm.GetDefaultApplication() - - nodes = BuildModuleTree() - all_real_nodes = CreateDebugDocumentHelperNodes(pdm, app, nodes) - AttachParentNodes(None, nodes, all_real_nodes) - - parentNode = None - all_real_nodes = {} - input("Waiting...") - print("Done") - - def TestSmartProvider(): import ttest from win32com.axdebug import debugger d = debugger.AXDebugger() - # d.StartDebugger() - # d.Attach() + # d.StartDebugger() + # d.Attach() d.Break() input("Waiting...") ttest.test() @@ -171,21 +124,13 @@ def TestSmartProvider(): def test(): try: - # app = TestSmartHelper() app = TestSmartProvider() - # app = testdumb() except: traceback.print_exc() -# _wrap_remove(externalConnectionManager) -# wrappedExternalConnectionManager = None - if __name__ == "__main__": test() - import win32com.axdebug.util - - win32com.axdebug.util._dump_wrapped() print( " %d/%d com objects still alive" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) diff --git a/com/win32comext/axdebug/adb.py b/com/win32comext/axdebug/adb.py index 812c23e62a..432fdb8b85 100644 --- a/com/win32comext/axdebug/adb.py +++ b/com/win32comext/axdebug/adb.py @@ -9,8 +9,7 @@ import pythoncom import win32api import win32com.client.connect -from win32com.axdebug.util import _wrap, _wrap_remove, trace -from win32com.server.util import unwrap +from win32com.axdebug.util import _wrap, trace from . import axdebug, gateways, stackframe @@ -118,8 +117,8 @@ def __xxxxx__set_break(self, filename, lineno, cond=None): def stop_here(self, frame): traceenter("stop_here", _dumpf(frame), _dumpf(self.stopframe)) # As per bdb.stop_here, except for logicalbotframe - ## if self.stopframe is None: - ## return 1 + # if self.stopframe is None: + # return 1 if frame is self.stopframe: return 1 @@ -157,13 +156,13 @@ def dispatch_return(self, frame, arg): tracev("dispatch_return resetting sys.trace") sys.settrace(None) return - # self.bSetTrace = 0 + # self.bSetTrace = 0 self.currentframe = frame.f_back return bdb.Bdb.dispatch_return(self, frame, arg) def dispatch_line(self, frame): traceenter("dispatch_line", _dumpf(frame), _dumpf(self.botframe)) - # trace("logbotframe is", _dumpf(self.logicalbotframe), "botframe is", self.botframe) + # trace("logbotframe is", _dumpf(self.logicalbotframe), "botframe is", self.botframe) if frame is self.logicalbotframe: trace("dispatch_line", _dumpf(frame), "for bottom frame returing tracer") # The next code executed in the frame above may be a builtin (eg, apply()) @@ -195,13 +194,13 @@ def dispatch_call(self, frame, arg): trace( "dispatch_call has no document for", _dumpf(frame), "- skipping trace!" ) - ## sys.settrace(None) + # sys.settrace(None) return None return self.trace_dispatch - # rc = bdb.Bdb.dispatch_call(self, frame, arg) - # trace("dispatch_call", _dumpf(frame),"returned",rc) - # return rc + # rc = bdb.Bdb.dispatch_call(self, frame, arg) + # trace("dispatch_call", _dumpf(frame),"returned",rc) + # return rc def trace_dispatch(self, frame, event, arg): traceenter("trace_dispatch", _dumpf(frame), event, arg) @@ -213,8 +212,8 @@ def trace_dispatch(self, frame, event, arg): # # The user functions do bugger all! # - # def user_call(self, frame, argument_list): - # traceenter("user_call",_dumpf(frame)) + # def user_call(self, frame, argument_list): + # traceenter("user_call",_dumpf(frame)) def user_line(self, frame): traceenter("user_line", _dumpf(frame)) @@ -226,11 +225,11 @@ def user_line(self, frame): self._HandleBreakPoint(frame, None, breakReason) def user_return(self, frame, return_value): - # traceenter("user_return",_dumpf(frame),return_value) + # traceenter("user_return",_dumpf(frame),return_value) bdb.Bdb.user_return(self, frame, return_value) def user_exception(self, frame, exc_info): - # traceenter("user_exception") + # traceenter("user_exception") bdb.Bdb.user_exception(self, frame, exc_info) def _HandleBreakPoint(self, frame, tb, reason): @@ -284,8 +283,6 @@ def CloseApp(self): "*** Could not RemoveStackFrameSniffer %d" % (self.stackSnifferCookie) ) - if self.stackSniffer: - _wrap_remove(self.stackSniffer) self.stackSnifferCookie = self.stackSniffer = None if self.appEventConnection is not None: @@ -298,7 +295,7 @@ def CloseApp(self): self.codeContainerProvider = None def AttachApp(self, debugApplication, codeContainerProvider): - # traceenter("AttachApp", debugApplication, codeContainerProvider) + # traceenter("AttachApp", debugApplication, codeContainerProvider) self.codeContainerProvider = codeContainerProvider self.debugApplication = debugApplication self.stackSniffer = _wrap( @@ -307,7 +304,7 @@ def AttachApp(self, debugApplication, codeContainerProvider): self.stackSnifferCookie = debugApplication.AddStackFrameSniffer( self.stackSniffer ) - # trace("StackFrameSniffer added (%d)" % self.stackSnifferCookie) + # trace("StackFrameSniffer added (%d)" % self.stackSnifferCookie) # Connect to the application events. self.appEventConnection = win32com.client.connect.SimpleConnection( @@ -321,7 +318,7 @@ def ResetAXDebugging(self): return if len(self.recursiveData) == 0: - # print "ResetAXDebugging called for final time." + # print("ResetAXDebugging called for final time.") self.logicalbotframe = None self.debuggingThread = None self.currentframe = None @@ -432,8 +429,8 @@ def _BreakFlagsChanged(self): ) trace("_BreakFlagsChanged has breaks", self.breaks) # If a request comes on our debugging thread, then do it now! - # if self.debuggingThread!=win32api.GetCurrentThreadId(): - # return + # if self.debuggingThread!=win32api.GetCurrentThreadId(): + # return if len(self.breaks) or self.breakFlags: if self.logicalbotframe: diff --git a/com/win32comext/axdebug/codecontainer.py b/com/win32comext/axdebug/codecontainer.py index be20a2d394..fa5d27c24c 100644 --- a/com/win32comext/axdebug/codecontainer.py +++ b/com/win32comext/axdebug/codecontainer.py @@ -4,17 +4,16 @@ to color the text, and also how to translate lines into offsets, and back. """ +import os import sys import tokenize import win32api import winerror -from win32com.axdebug import axdebug +from win32com.axdebug import axdebug, contexts +from win32com.axdebug.util import _wrap from win32com.server.exception import Exception -from . import contexts -from .util import RaiseNotImpl, _wrap - _keywords = {} # set of Python keywords for name in """ and assert break class continue def del elif else except exec @@ -43,7 +42,7 @@ def __init__( self.codeContexts = {} self.site = site self.startLineNumber = startLineNumber - self.debugDocument = None + self.debugDocument = debugDocument def _Close(self): self.text = self.lines = self.lineOffsets = None @@ -78,9 +77,9 @@ def GetLineOfPosition(self, charPos): lastOffset = lineOffset lineNo = lineNo + 1 else: # for not broken. - # print "Cant find", charPos, "in", self.lineOffsets + # print("Cant find", charPos, "in", self.lineOffsets) raise Exception(scode=winerror.S_FALSE) - # print "GLOP ret=",lineNo, (charPos-lastOffset) + # print("GLOP ret=", lineNo, (charPos - lastOffset)) return lineNo, (charPos - lastOffset) def GetNextLine(self): @@ -187,13 +186,13 @@ def _MakeContextAtPosition(self, charPos): # Returns a DebugCodeContext. debugDocument can be None for smart hosts. def GetCodeContextAtPosition(self, charPos): - # trace("GetContextOfPos", charPos, maxChars) + # trace("GetContextOfPos", charPos, maxChars) # Convert to line number. lineNo, offset = self.GetLineOfPosition(charPos) charPos = self.GetPositionOfLine(lineNo) try: cc = self.codeContexts[charPos] - # trace(" GetContextOfPos using existing") + # trace(" GetContextOfPos using existing") except KeyError: cc = self._MakeContextAtPosition(charPos) self.codeContexts[charPos] = cc @@ -253,11 +252,10 @@ def GetName(self, dnt): if __name__ == "__main__": - sys.path.append(".") - import ttest + from Test import ttest sc = SourceModuleContainer(ttest) - # sc = SourceCodeContainer(open(sys.argv[1], "rb").read(), sys.argv[1]) + # sc = SourceCodeContainer(open(sys.argv[1], "rb").read(), sys.argv[1]) attrs = sc.GetSyntaxColorAttributes() attrlen = 0 for attr in attrs: @@ -269,8 +267,8 @@ def GetName(self, dnt): if attrlen != len(text): print("Lengths dont match!!! (%d/%d)" % (attrlen, len(text))) - # print "Attributes:" - # print attrs + # print("Attributes:") + # print(attrs) print("GetLineOfPos=", sc.GetLineOfPosition(0)) print("GetLineOfPos=", sc.GetLineOfPosition(4)) print("GetLineOfPos=", sc.GetLineOfPosition(10)) diff --git a/com/win32comext/axdebug/contexts.py b/com/win32comext/axdebug/contexts.py index 8581663943..8953f5ab9c 100644 --- a/com/win32comext/axdebug/contexts.py +++ b/com/win32comext/axdebug/contexts.py @@ -1,13 +1,10 @@ """ A module for managing the AXDebug I*Contexts """ -import pythoncom -import win32com.server.util - from . import adb, axdebug, gateways # Utility function for wrapping object created by this module. -from .util import _wrap, _wrap_remove, trace +from .util import _wrap class DebugCodeContext(gateways.DebugCodeContext, gateways.DebugDocumentContext): diff --git a/com/win32comext/axdebug/debugger.py b/com/win32comext/axdebug/debugger.py index 3157586bce..b0722f2524 100644 --- a/com/win32comext/axdebug/debugger.py +++ b/com/win32comext/axdebug/debugger.py @@ -3,18 +3,8 @@ import sys import pythoncom -import win32api -from win32com.axdebug import ( - adb, - axdebug, - codecontainer, - contexts, - documents, - expressions, - gateways, -) -from win32com.axdebug.util import _wrap, _wrap_remove, trace -from win32com.axscript import axscript +from win32com.axdebug import adb, axdebug, codecontainer, documents, expressions +from win32com.axdebug.util import _wrap currentDebugger = None @@ -50,9 +40,9 @@ def BuildModule(module, built_nodes, rootNode, create_node_fn, create_node_args) ".pyd", ".dll", ] - # keep = keep and module.__name__=='__main__' + # keep = keep and module.__name__=='__main__' if module and keep: - # print "keeping", module.__name__ + # print("keeping", module.__name__) node = ModuleTreeNode(module) built_nodes[module] = node realNode = create_node_fn(*(node,) + create_node_args) @@ -92,12 +82,12 @@ def __init__(self, axdebugger): self.axdebugger.RefreshAllModules(self.nodes, self) def FromFileName(self, fname): - ### It appears we cant add modules during a debug session! - # if self.currentNumModules != len(sys.modules): - # self.axdebugger.RefreshAllModules(self.nodes, self) - # self.currentNumModules = len(sys.modules) - # for key in self.ccsAndNodes.keys(): - # print "File:", key + # It appears we cant add modules during a debug session! + # if self.currentNumModules != len(sys.modules): + # self.axdebugger.RefreshAllModules(self.nodes, self) + # self.currentNumModules = len(sys.modules) + # for key in self.ccsAndNodes.keys(): + # print "File:", key return documents.CodeContainerProvider.FromFileName(self, fname) def Close(self): diff --git a/com/win32comext/axdebug/documents.py b/com/win32comext/axdebug/documents.py index 2bcc1c6f14..11cff56aa3 100644 --- a/com/win32comext/axdebug/documents.py +++ b/com/win32comext/axdebug/documents.py @@ -4,14 +4,13 @@ import pythoncom import win32api -from win32com.server.exception import Exception from win32com.server.util import unwrap -from . import axdebug, codecontainer, contexts, gateways -from .util import RaiseNotImpl, _wrap, _wrap_remove, trace +from . import axdebug, gateways +from .util import _wrap, trace # def trace(*args): -# pass +# pass def GetGoodFileName(fname): @@ -56,7 +55,7 @@ def __init__(self, codeContainer): def _Close(self): self.docContexts = None - # self.codeContainer._Close() + # self.codeContainer._Close() self.codeContainer = None # IDebugDocumentInfo @@ -72,7 +71,7 @@ def GetDocumentClassId(self): # IDebugDocumentText methods. # def GetDocumentAttributes def GetSize(self): - # trace("GetSize") + # trace("GetSize") return self.codeContainer.GetNumLines(), self.codeContainer.GetNumChars() def GetPositionOfLine(self, cLineNumber): @@ -84,7 +83,7 @@ def GetLineOfPosition(self, charPos): def GetText(self, charPos, maxChars, wantAttr): # Get all the attributes, else the tokenizer will get upset. # XXX - not yet! - # trace("GetText", charPos, maxChars, wantAttr) + # trace("GetText", charPos, maxChars, wantAttr) cont = self.codeContainer attr = cont.GetSyntaxColorAttributes() return cont.GetText(), attr @@ -121,8 +120,8 @@ def AddCodeContainer(self, cc, node=None): def FromFileName(self, fname): cc, node = self.ccsAndNodes.get(GetGoodFileName(fname), (None, None)) - # if cc is None: - # print "FromFileName for %s returning None" % fname + # if cc is None: + # print("FromFileName for %s returning None" % fname) return cc def Close(self): diff --git a/com/win32comext/axdebug/dump.py b/com/win32comext/axdebug/dump.py index 26ee51e0d0..cd87f330cd 100644 --- a/com/win32comext/axdebug/dump.py +++ b/com/win32comext/axdebug/dump.py @@ -26,7 +26,7 @@ def DumpDebugApplicationNode(node, level=0): if doc: doctext = doc.QueryInterface(axdebug.IID_IDebugDocumentText) numLines, numChars = doctext.GetSize() - # text, attr = doctext.GetText(0, 20, 1) + # text, attr = doctext.GetText(0, 20, 1) text, attr = doctext.GetText(0, numChars, 1) print( "%sText is %s, %d bytes long" % (spacer, repr(text[:40] + "..."), len(text)) diff --git a/com/win32comext/axdebug/expressions.py b/com/win32comext/axdebug/expressions.py index e573eb514e..359d1636f9 100644 --- a/com/win32comext/axdebug/expressions.py +++ b/com/win32comext/axdebug/expressions.py @@ -5,17 +5,16 @@ from pprint import pprint import winerror -from win32com.server.exception import COMException from . import axdebug, gateways -from .util import RaiseNotImpl, _wrap, _wrap_remove +from .util import RaiseNotImpl, _wrap # Given an object, return a nice string def MakeNiceString(ob): stream = io.StringIO() pprint(ob, stream) - return string.strip(stream.getvalue()) + return stream.getvalue().strip() class ProvideExpressionContexts(gateways.ProvideExpressionContexts): @@ -33,7 +32,7 @@ def ParseLanguageText(self, code, radix, delim, flags): ) def GetLanguageInfo(self): - # print "GetLanguageInfo" + # print("GetLanguageInfo") return "Python", "{DF630910-1C1D-11d0-AE36-8C0F5E000000}" @@ -65,7 +64,7 @@ def Start(self, callback): sys.exc_info()[0], sys.exc_info()[1] ) # l is a list of strings with trailing "\n" - self.result = string.join((s[:-1] for s in l), "\n") + self.result = "\n".join(s[:-1] for s in l) self.hresult = winerror.E_FAIL finally: self.isComplete = 1 @@ -78,7 +77,7 @@ def QueryIsComplete(self): return self.isComplete def GetResultAsString(self): - # print "GetStrAsResult returning", self.result + # print("GetStrAsResult returning", self.result) return self.hresult, MakeNiceString(self.result) def GetResultAsDebugProperty(self): @@ -188,8 +187,8 @@ def GetPropertyInfo(self, dwFieldSpec, nRadix): dwFieldSpec, nRadix, self.hresult, - dictionary, - stackFrame, + self.dictionary, + self.stackFrame, ) def GetExtendedInfo(self): ### Note - not in the framework. diff --git a/com/win32comext/axdebug/stackframe.py b/com/win32comext/axdebug/stackframe.py index edc3fe8cb8..c685611bb0 100644 --- a/com/win32comext/axdebug/stackframe.py +++ b/com/win32comext/axdebug/stackframe.py @@ -4,13 +4,12 @@ """ import pythoncom -from win32com.server.exception import COMException from . import axdebug, expressions, gateways from .util import RaiseNotImpl, _wrap, trace # def trace(*args): -# pass +# pass class EnumDebugStackFrames(gateways.EnumDebugStackFrames): @@ -21,9 +20,9 @@ class EnumDebugStackFrames(gateways.EnumDebugStackFrames): def __init__(self, debugger): infos = [] frame = debugger.currentframe - # print "Stack check" + # print("Stack check") while frame: - # print " Checking frame", frame.f_code.co_filename, frame.f_lineno-1, frame.f_trace, + # print(" Checking frame", frame.f_code.co_filename, frame.f_lineno-1, frame.f_trace) # Get a DebugCodeContext for the stack frame. If we fail, then it # is not debuggable, and therefore not worth displaying. cc = debugger.codeContainerProvider.FromFileName(frame.f_code.co_filename) @@ -31,7 +30,7 @@ def __init__(self, debugger): try: address = frame.f_locals["__axstack_address__"] except KeyError: - # print "Couldnt find stack address for",frame.f_code.co_filename, frame.f_lineno-1 + # print("Couldnt find stack address for",frame.f_code.co_filename, frame.f_lineno-1) # Use this one, even tho it is wrong :-( address = axdebug.GetStackAddress() frameInfo = ( @@ -42,23 +41,23 @@ def __init__(self, debugger): None, ) infos.append(frameInfo) - # print "- Kept!" - # else: - # print "- rejected" + # print "- Kept!" + # else: + # print "- rejected" frame = frame.f_back gateways.EnumDebugStackFrames.__init__(self, infos, 0) - # def __del__(self): - # print "EnumDebugStackFrames dieing" + # def __del__(self): + # print "EnumDebugStackFrames dieing" def Next(self, count): return gateways.EnumDebugStackFrames.Next(self, count) - # def _query_interface_(self, iid): - # from win32com.util import IIDToInterfaceName - # print "EnumDebugStackFrames QI with %s (%s)" % (IIDToInterfaceName(iid), str(iid)) - # return 0 + # def _query_interface_(self, iid): + # from win32com.util import IIDToInterfaceName + # print("EnumDebugStackFrames QI with %s (%s)" % (IIDToInterfaceName(iid), str(iid))) + # return 0 def _wrap(self, obj): # This enum returns a tuple, with 2 com objects in it. obFrame, min, lim, fFinal, obFinal = obj @@ -75,8 +74,8 @@ def __init__(self, frame, lineno, codeContainer): self.codeContainer = codeContainer self.expressionContext = None - # def __del__(self): - # print "DSF dieing" + # def __del__(self): + # print("DSF dieing") def _query_interface_(self, iid): if iid == axdebug.IID_IDebugExpressionContext: if self.expressionContext is None: @@ -85,8 +84,8 @@ def _query_interface_(self, iid): axdebug.IID_IDebugExpressionContext, ) return self.expressionContext - # from win32com.util import IIDToInterfaceName - # print "DebugStackFrame QI with %s (%s)" % (IIDToInterfaceName(iid), str(iid)) + # from win32com.util import IIDToInterfaceName + # print(f"DebugStackFrame QI with {IIDToInterfaceName(iid)} ({iid})") return 0 # @@ -133,8 +132,8 @@ def __init__(self, debugger): self.debugger = debugger trace("DebugStackFrameSniffer instantiated") - # def __del__(self): - # print "DSFS dieing" + # def __del__(self): + # print("DSFS dieing") def EnumStackFrames(self): trace("DebugStackFrameSniffer.EnumStackFrames called") return _wrap( diff --git a/com/win32comext/axdebug/util.py b/com/win32comext/axdebug/util.py index c3d4f733f6..f609fca087 100644 --- a/com/win32comext/axdebug/util.py +++ b/com/win32comext/axdebug/util.py @@ -34,8 +34,6 @@ def trace(*args): # (Now this is only true for Document objects, and Python # now does ensure this. -all_wrapped = {} - def _wrap_nodebug(object, iid): return win32com.server.util.wrap(object, iid) @@ -54,24 +52,6 @@ def _wrap_debug(object, iid): _wrap = _wrap_nodebug -def _wrap_remove(object, iid=None): - # Old - no longer used or necessary! - return - - -def _dump_wrapped(): - from win32com.server.util import unwrap - - print("Wrapped items:") - for key, items in all_wrapped.items(): - print(key, end=" ") - try: - ob = unwrap(key) - print(ob, sys.getrefcount(ob)) - except: - print("") - - def RaiseNotImpl(who=None): if who is not None: print("********* Function %s Raising E_NOTIMPL ************" % (who)) @@ -97,12 +77,12 @@ def __init__(self, policyClass, object): win32com.server.policy.DispatcherTrace.__init__(self, policyClass, object) import win32traceutil # Sets up everything. - # print "Object with win32trace dispatcher created (object=%s)" % `object` + # print(f"Object with win32trace dispatcher created ({object})") def _QueryInterface_(self, iid): rc = win32com.server.policy.DispatcherBase._QueryInterface_(self, iid) - # if not rc: - # self._trace_("in _QueryInterface_ with unsupported IID %s (%s)\n" % (IIDToInterfaceName(iid),iid)) + # if not rc: + # self._trace_("in _QueryInterface_ with unsupported IID %s (%s)\n" % (IIDToInterfaceName(iid),iid)) return rc def _Invoke_(self, dispid, lcid, wFlags, args): @@ -119,7 +99,7 @@ def _Invoke_(self, dispid, lcid, wFlags, args): rc = win32com.server.policy.DispatcherBase._Invoke_( self, dispid, lcid, wFlags, args ) - # print "Invoke of", dispid, "returning", rc + # print("Invoke of", dispid, "returning", rc) return rc except Exception: t, v, tb = sys.exc_info() diff --git a/com/win32comext/axscript/client/debug.py b/com/win32comext/axscript/client/debug.py index b3871ab19c..97d11b0cb3 100644 --- a/com/win32comext/axscript/client/debug.py +++ b/com/win32comext/axscript/client/debug.py @@ -8,7 +8,7 @@ import winerror from win32com.axdebug import adb, axdebug, contexts, documents, gateways, stackframe from win32com.axdebug.codecontainer import SourceCodeContainer -from win32com.axdebug.util import _wrap, _wrap_remove +from win32com.axdebug.util import _wrap from win32com.client.util import Enumerator from win32com.server.exception import COMException from win32com.util import IIDToInterfaceName @@ -87,9 +87,7 @@ def __init__(self, scriptEngine): def Close(self): # Called by the language engine when it receives a close request - if self.activeScriptDebug is not None: - _wrap_remove(self.activeScriptDebug) - self.activeScriptDebug = None + self.activeScriptDebug = None self.scriptEngine = None self.rootNode = None self.debugApplication = None diff --git a/com/win32comext/axscript/test/testHost4Dbg.py b/com/win32comext/axscript/test/testHost4Dbg.py index 3bfafd676d..9a969a1bee 100644 --- a/com/win32comext/axscript/test/testHost4Dbg.py +++ b/com/win32comext/axscript/test/testHost4Dbg.py @@ -83,6 +83,5 @@ def TestEngine(): TestEngine() except: traceback.print_exc() - win32com.axdebug.util._dump_wrapped() sys.exc_type = sys.exc_value = sys.exc_traceback = None print(pythoncom._GetInterfaceCount(), "com objects still alive") From a041c13f04c6f9a2e27334ea9af6ea228479f3fc Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 21 Sep 2023 20:35:20 -0400 Subject: [PATCH 2/4] Ran format_all.bat --- Pythonwin/pywin/Demos/app/helloapp.py | 2 +- .../framework/editor/color/coloreditor.py | 8 +------- Pythonwin/pywin/framework/editor/configui.py | 11 +---------- Pythonwin/pywin/framework/editor/editor.py | 4 +--- Pythonwin/pywin/framework/winout.py | 1 - com/win32comext/axdebug/adb.py | 6 +++--- com/win32comext/axdebug/debugger.py | 8 ++++---- com/win32comext/axdebug/documents.py | 2 +- com/win32comext/axdebug/expressions.py | 1 - com/win32comext/axdebug/stackframe.py | 18 +++++++++--------- com/win32comext/axdebug/util.py | 2 +- 11 files changed, 22 insertions(+), 41 deletions(-) diff --git a/Pythonwin/pywin/Demos/app/helloapp.py b/Pythonwin/pywin/Demos/app/helloapp.py index 876f16f71d..6ac35b431a 100644 --- a/Pythonwin/pywin/Demos/app/helloapp.py +++ b/Pythonwin/pywin/Demos/app/helloapp.py @@ -14,7 +14,7 @@ import win32con import win32ui -from pywin.mfc import afxres, dialog, window +from pywin.mfc import window from pywin.mfc.thread import WinApp diff --git a/Pythonwin/pywin/framework/editor/color/coloreditor.py b/Pythonwin/pywin/framework/editor/color/coloreditor.py index 4aacc0eab5..3d9b7e09e6 100644 --- a/Pythonwin/pywin/framework/editor/color/coloreditor.py +++ b/Pythonwin/pywin/framework/editor/color/coloreditor.py @@ -5,13 +5,7 @@ import win32api import win32con import win32ui -from pywin.framework.editor import ( - GetEditorFontOption, - GetEditorOption, - SetEditorFontOption, - SetEditorOption, - defaultCharacterFormat, -) +from pywin.framework.editor import GetEditorOption from pywin.scintilla import bindings # from pywin.framework.editor import EditorPropertyPage diff --git a/Pythonwin/pywin/framework/editor/configui.py b/Pythonwin/pywin/framework/editor/configui.py index 903ad66c74..174cb907ba 100644 --- a/Pythonwin/pywin/framework/editor/configui.py +++ b/Pythonwin/pywin/framework/editor/configui.py @@ -2,15 +2,7 @@ import win32api import win32con import win32ui -from pywin.framework.editor import ( - DeleteEditorOption, - GetEditorFontOption, - GetEditorOption, - SetEditorFontOption, - SetEditorOption, - defaultCharacterFormat, - editorTemplate, -) +from pywin.framework.editor import DeleteEditorOption, GetEditorOption, SetEditorOption from pywin.mfc import dialog from . import document @@ -119,7 +111,6 @@ def OnInitDialog(self): import traceback traceback.print_exc() - pass self.HookCommand(self.OnButSimple, win32ui.IDC_FOLD_ENABLE) self.HookCommand(self.OnButSimple, win32ui.IDC_RADIO1) diff --git a/Pythonwin/pywin/framework/editor/editor.py b/Pythonwin/pywin/framework/editor/editor.py index 63df9cfcdb..c14a2b7242 100644 --- a/Pythonwin/pywin/framework/editor/editor.py +++ b/Pythonwin/pywin/framework/editor/editor.py @@ -26,11 +26,9 @@ from pywin.framework.editor import ( GetEditorFontOption, GetEditorOption, - SetEditorFontOption, - SetEditorOption, defaultCharacterFormat, ) -from pywin.mfc import afxres, dialog, docview +from pywin.mfc import afxres, docview patImport = regex.symcomp(r"import \(.*\)") patIndent = regex.compile(r"^\([ \t]*[~ \t]\)") diff --git a/Pythonwin/pywin/framework/winout.py b/Pythonwin/pywin/framework/winout.py index 7badd38415..b9bb49253b 100644 --- a/Pythonwin/pywin/framework/winout.py +++ b/Pythonwin/pywin/framework/winout.py @@ -46,7 +46,6 @@ class flags: # WindowOutputDocumentParent=docview.RichEditDoc # WindowOutputDocumentParent=docview.Document import pywin.scintilla.document -from pywin import default_scintilla_encoding from pywin.scintilla import scintillacon WindowOutputDocumentParent = pywin.scintilla.document.CScintillaDocument diff --git a/com/win32comext/axdebug/adb.py b/com/win32comext/axdebug/adb.py index 432fdb8b85..ec8d28f56e 100644 --- a/com/win32comext/axdebug/adb.py +++ b/com/win32comext/axdebug/adb.py @@ -118,7 +118,7 @@ def stop_here(self, frame): traceenter("stop_here", _dumpf(frame), _dumpf(self.stopframe)) # As per bdb.stop_here, except for logicalbotframe # if self.stopframe is None: - # return 1 + # return 1 if frame is self.stopframe: return 1 @@ -213,7 +213,7 @@ def trace_dispatch(self, frame, event, arg): # The user functions do bugger all! # # def user_call(self, frame, argument_list): - # traceenter("user_call",_dumpf(frame)) + # traceenter("user_call",_dumpf(frame)) def user_line(self, frame): traceenter("user_line", _dumpf(frame)) @@ -430,7 +430,7 @@ def _BreakFlagsChanged(self): trace("_BreakFlagsChanged has breaks", self.breaks) # If a request comes on our debugging thread, then do it now! # if self.debuggingThread!=win32api.GetCurrentThreadId(): - # return + # return if len(self.breaks) or self.breakFlags: if self.logicalbotframe: diff --git a/com/win32comext/axdebug/debugger.py b/com/win32comext/axdebug/debugger.py index b0722f2524..61e1463c8f 100644 --- a/com/win32comext/axdebug/debugger.py +++ b/com/win32comext/axdebug/debugger.py @@ -84,10 +84,10 @@ def __init__(self, axdebugger): def FromFileName(self, fname): # It appears we cant add modules during a debug session! # if self.currentNumModules != len(sys.modules): - # self.axdebugger.RefreshAllModules(self.nodes, self) - # self.currentNumModules = len(sys.modules) + # self.axdebugger.RefreshAllModules(self.nodes, self) + # self.currentNumModules = len(sys.modules) # for key in self.ccsAndNodes.keys(): - # print "File:", key + # print "File:", key return documents.CodeContainerProvider.FromFileName(self, fname) def Close(self): @@ -160,7 +160,7 @@ def Break(self): # Get/create the debugger, and tell it to break. self.app.StartDebugSession() - # self.app.CauseBreak() + # self.app.CauseBreak() self.pydebugger.SetupAXDebugging(None, frame) self.pydebugger.set_trace() diff --git a/com/win32comext/axdebug/documents.py b/com/win32comext/axdebug/documents.py index 11cff56aa3..68f3ce6504 100644 --- a/com/win32comext/axdebug/documents.py +++ b/com/win32comext/axdebug/documents.py @@ -10,7 +10,7 @@ from .util import _wrap, trace # def trace(*args): -# pass +# pass def GetGoodFileName(fname): diff --git a/com/win32comext/axdebug/expressions.py b/com/win32comext/axdebug/expressions.py index 359d1636f9..d741e45a44 100644 --- a/com/win32comext/axdebug/expressions.py +++ b/com/win32comext/axdebug/expressions.py @@ -1,5 +1,4 @@ import io -import string import sys import traceback from pprint import pprint diff --git a/com/win32comext/axdebug/stackframe.py b/com/win32comext/axdebug/stackframe.py index c685611bb0..8a0cb99917 100644 --- a/com/win32comext/axdebug/stackframe.py +++ b/com/win32comext/axdebug/stackframe.py @@ -9,7 +9,7 @@ from .util import RaiseNotImpl, _wrap, trace # def trace(*args): -# pass +# pass class EnumDebugStackFrames(gateways.EnumDebugStackFrames): @@ -41,23 +41,23 @@ def __init__(self, debugger): None, ) infos.append(frameInfo) - # print "- Kept!" + # print "- Kept!" # else: - # print "- rejected" + # print "- rejected" frame = frame.f_back gateways.EnumDebugStackFrames.__init__(self, infos, 0) # def __del__(self): - # print "EnumDebugStackFrames dieing" + # print "EnumDebugStackFrames dieing" def Next(self, count): return gateways.EnumDebugStackFrames.Next(self, count) # def _query_interface_(self, iid): - # from win32com.util import IIDToInterfaceName - # print("EnumDebugStackFrames QI with %s (%s)" % (IIDToInterfaceName(iid), str(iid))) - # return 0 + # from win32com.util import IIDToInterfaceName + # print("EnumDebugStackFrames QI with %s (%s)" % (IIDToInterfaceName(iid), str(iid))) + # return 0 def _wrap(self, obj): # This enum returns a tuple, with 2 com objects in it. obFrame, min, lim, fFinal, obFinal = obj @@ -75,7 +75,7 @@ def __init__(self, frame, lineno, codeContainer): self.expressionContext = None # def __del__(self): - # print("DSF dieing") + # print("DSF dieing") def _query_interface_(self, iid): if iid == axdebug.IID_IDebugExpressionContext: if self.expressionContext is None: @@ -133,7 +133,7 @@ def __init__(self, debugger): trace("DebugStackFrameSniffer instantiated") # def __del__(self): - # print("DSFS dieing") + # print("DSFS dieing") def EnumStackFrames(self): trace("DebugStackFrameSniffer.EnumStackFrames called") return _wrap( diff --git a/com/win32comext/axdebug/util.py b/com/win32comext/axdebug/util.py index f609fca087..573c078e7e 100644 --- a/com/win32comext/axdebug/util.py +++ b/com/win32comext/axdebug/util.py @@ -82,7 +82,7 @@ def __init__(self, policyClass, object): def _QueryInterface_(self, iid): rc = win32com.server.policy.DispatcherBase._QueryInterface_(self, iid) # if not rc: - # self._trace_("in _QueryInterface_ with unsupported IID %s (%s)\n" % (IIDToInterfaceName(iid),iid)) + # self._trace_("in _QueryInterface_ with unsupported IID %s (%s)\n" % (IIDToInterfaceName(iid),iid)) return rc def _Invoke_(self, dispid, lcid, wFlags, args): From 792e0adf3392b94f2921d6ee5bfaae38f7f24d32 Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 22 Sep 2023 00:19:51 -0400 Subject: [PATCH 3/4] axdebug string formatting --- com/win32comext/axdebug/Test/host.py | 8 +++----- com/win32comext/axdebug/adb.py | 15 ++++----------- com/win32comext/axdebug/codecontainer.py | 8 ++++---- com/win32comext/axdebug/debugger.py | 9 ++++----- com/win32comext/axdebug/documents.py | 2 +- com/win32comext/axdebug/dump.py | 10 ++++------ com/win32comext/axdebug/stackframe.py | 8 ++++---- com/win32comext/axdebug/util.py | 12 +++++------- 8 files changed, 29 insertions(+), 43 deletions(-) diff --git a/com/win32comext/axdebug/Test/host.py b/com/win32comext/axdebug/Test/host.py index e28622f6b0..b3d1317462 100644 --- a/com/win32comext/axdebug/Test/host.py +++ b/com/win32comext/axdebug/Test/host.py @@ -48,8 +48,7 @@ def _query_interface_(self, iid): from win32com.util import IIDToInterfaceName trace( - "PySourceModuleDebugDocumentHost QI with %s (%s)" - % (IIDToInterfaceName(iid), str(iid)) + f"PySourceModuleDebugDocumentHost QI with {IIDToInterfaceName(iid)} ({iid})" ) return 0 @@ -58,7 +57,7 @@ def _GetCodeContainer(self): try: codeText = open(self.module.__file__, "rt").read() except OSError as details: - codeText = "# Exception opening file\n# %s" % (details) + codeText = f"# Exception opening file\n# {details}" self.codeContainer = codecontainer.SourceCodeContainer( codeText, self.module.__file__ @@ -132,6 +131,5 @@ def test(): if __name__ == "__main__": test() print( - " %d/%d com objects still alive" - % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) + f" {pythoncom._GetInterfaceCount()}/{pythoncom._GetGatewayCount()} com objects still alive" ) diff --git a/com/win32comext/axdebug/adb.py b/com/win32comext/axdebug/adb.py index ec8d28f56e..f278048b4a 100644 --- a/com/win32comext/axdebug/adb.py +++ b/com/win32comext/axdebug/adb.py @@ -52,12 +52,7 @@ def _dumpf(frame): addn = "(with trace!)" if frame.f_trace is None: addn = " **No Trace Set **" - return "Frame at %d, file %s, line: %d%s" % ( - id(frame), - frame.f_code.co_filename, - frame.f_lineno, - addn, - ) + return f"Frame at {id(frame)}, file {frame.f_code.co_filename}, line: {frame.f_lineno}{addn}" g_adb = None @@ -280,8 +275,7 @@ def CloseApp(self): except pythoncom.com_error: trace( - "*** Could not RemoveStackFrameSniffer %d" - % (self.stackSnifferCookie) + f"*** Could not RemoveStackFrameSniffer {self.stackSnifferCookie}" ) self.stackSnifferCookie = self.stackSniffer = None @@ -304,7 +298,7 @@ def AttachApp(self, debugApplication, codeContainerProvider): self.stackSnifferCookie = debugApplication.AddStackFrameSniffer( self.stackSniffer ) - # trace("StackFrameSniffer added (%d)" % self.stackSnifferCookie) + # trace(f"StackFrameSniffer added ({self.stackSnifferCookie})") # Connect to the application events. self.appEventConnection = win32com.client.connect.SimpleConnection( @@ -424,8 +418,7 @@ def OnBreakFlagChange(self, abf, rdat): def _BreakFlagsChanged(self): traceenter( - "_BreakFlagsChanged to %s with our thread = %s, and debugging thread = %s" - % (self.breakFlags, self.debuggingThread, win32api.GetCurrentThreadId()) + "_BreakFlagsChanged to {self.breakFlags} with our thread = {self.debuggingThread}, and debugging thread = {win32api.GetCurrentThreadId()}" ) trace("_BreakFlagsChanged has breaks", self.breaks) # If a request comes on our debugging thread, then do it now! diff --git a/com/win32comext/axdebug/codecontainer.py b/com/win32comext/axdebug/codecontainer.py index fa5d27c24c..69a9f8e458 100644 --- a/com/win32comext/axdebug/codecontainer.py +++ b/com/win32comext/axdebug/codecontainer.py @@ -225,9 +225,9 @@ def GetText(self): try: self.text = open(fname, "r").read() except OSError as details: - self.text = "# Exception opening file\n# %s" % (repr(details)) + self.text = f"# Exception opening file\n# {repr(details)}" else: - self.text = "# No file available for module '%s'" % (self.module) + self.text = f"# No file available for module '{self.module}'" self._buildlines() return self.text @@ -246,7 +246,7 @@ def GetName(self, dnt): elif dnt == axdebug.DOCUMENTNAMETYPE_FILE_TAIL: return os.path.split(fname)[1] elif dnt == axdebug.DOCUMENTNAMETYPE_URL: - return "file:%s" % fname + return f"file:{fname}" else: raise Exception(scode=winerror.E_UNEXPECTED) @@ -265,7 +265,7 @@ def GetName(self, dnt): attrlen = attrlen + 1 text = sc.GetText() if attrlen != len(text): - print("Lengths dont match!!! (%d/%d)" % (attrlen, len(text))) + print(f"Lengths dont match!!! ({attrlen}/{len(text)})") # print("Attributes:") # print(attrs) diff --git a/com/win32comext/axdebug/debugger.py b/com/win32comext/axdebug/debugger.py index 61e1463c8f..fa0f8e8383 100644 --- a/com/win32comext/axdebug/debugger.py +++ b/com/win32comext/axdebug/debugger.py @@ -20,7 +20,7 @@ def __init__(self, module): self.cont = codecontainer.SourceModuleContainer(module) def __repr__(self): - return "" % (self.module) + return f"" def Attach(self, parentRealNode): self.realNode.Attach(parentRealNode) @@ -87,13 +87,13 @@ def FromFileName(self, fname): # self.axdebugger.RefreshAllModules(self.nodes, self) # self.currentNumModules = len(sys.modules) # for key in self.ccsAndNodes.keys(): - # print "File:", key + # print("File:", key) return documents.CodeContainerProvider.FromFileName(self, fname) def Close(self): documents.CodeContainerProvider.Close(self) self.axdebugger = None - print("Closing %d nodes" % (len(self.nodes))) + print(f"Closing {len(self.nodes)} nodes") for node in self.nodes.values(): node.Close() self.nodes = {} @@ -235,6 +235,5 @@ def test(): print("About to test the debugging interfaces!") test() print( - " %d/%d com objects still alive" - % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) + f" {pythoncom._GetInterfaceCount()}/{pythoncom._GetGatewayCount()} com objects still alive" ) diff --git a/com/win32comext/axdebug/documents.py b/com/win32comext/axdebug/documents.py index 68f3ce6504..31a5c8441c 100644 --- a/com/win32comext/axdebug/documents.py +++ b/com/win32comext/axdebug/documents.py @@ -121,7 +121,7 @@ def AddCodeContainer(self, cc, node=None): def FromFileName(self, fname): cc, node = self.ccsAndNodes.get(GetGoodFileName(fname), (None, None)) # if cc is None: - # print("FromFileName for %s returning None" % fname) + # print(f"FromFileName for {fname} returning None") return cc def Close(self): diff --git a/com/win32comext/axdebug/dump.py b/com/win32comext/axdebug/dump.py index cd87f330cd..e7bf2170e7 100644 --- a/com/win32comext/axdebug/dump.py +++ b/com/win32comext/axdebug/dump.py @@ -18,7 +18,7 @@ def DumpDebugApplicationNode(node, level=0): info = node.GetName(attr) except pythoncom.com_error: info = "" - print("%s%s: %s" % (spacer, desc, info)) + print(f"{spacer}{desc}: {info}") try: doc = node.GetDocument() except pythoncom.com_error: @@ -28,11 +28,9 @@ def DumpDebugApplicationNode(node, level=0): numLines, numChars = doctext.GetSize() # text, attr = doctext.GetText(0, 20, 1) text, attr = doctext.GetText(0, numChars, 1) - print( - "%sText is %s, %d bytes long" % (spacer, repr(text[:40] + "..."), len(text)) - ) + print(f"{spacer}Text is {repr(text[:40] + '...')}, {len(text)} bytes long") else: - print("%s%s" % (spacer, "")) + print(f"{spacer}") for child in Enumerator(node.EnumChildren()): DumpDebugApplicationNode(child, level + 1) @@ -47,7 +45,7 @@ def dumpall(): ) e = Enumerator(dm.EnumApplications()) for app in e: - print("Application: %s" % app.GetName()) + print(f"Application: {app.GetName()}") node = ( app.GetRootNode() ) # of type PyIDebugApplicationNode->PyIDebugDocumentProvider->PyIDebugDocumentInfo diff --git a/com/win32comext/axdebug/stackframe.py b/com/win32comext/axdebug/stackframe.py index 8a0cb99917..a5c888872c 100644 --- a/com/win32comext/axdebug/stackframe.py +++ b/com/win32comext/axdebug/stackframe.py @@ -41,22 +41,22 @@ def __init__(self, debugger): None, ) infos.append(frameInfo) - # print "- Kept!" + # print("- Kept!") # else: - # print "- rejected" + # print("- rejected") frame = frame.f_back gateways.EnumDebugStackFrames.__init__(self, infos, 0) # def __del__(self): - # print "EnumDebugStackFrames dieing" + # print("EnumDebugStackFrames dieing") def Next(self, count): return gateways.EnumDebugStackFrames.Next(self, count) # def _query_interface_(self, iid): # from win32com.util import IIDToInterfaceName - # print("EnumDebugStackFrames QI with %s (%s)" % (IIDToInterfaceName(iid), str(iid))) + # print(f"EnumDebugStackFrames QI with {IIDToInterfaceName(iid)} ({iid})") # return 0 def _wrap(self, obj): # This enum returns a tuple, with 2 com objects in it. diff --git a/com/win32comext/axdebug/util.py b/com/win32comext/axdebug/util.py index 573c078e7e..805d21b28b 100644 --- a/com/win32comext/axdebug/util.py +++ b/com/win32comext/axdebug/util.py @@ -54,7 +54,7 @@ def _wrap_debug(object, iid): def RaiseNotImpl(who=None): if who is not None: - print("********* Function %s Raising E_NOTIMPL ************" % (who)) + print(f"********* Function {who} Raising E_NOTIMPL ************") # Print a sort-of "traceback", dumping all the frames leading to here. try: @@ -62,7 +62,7 @@ def RaiseNotImpl(who=None): except: frame = sys.exc_info()[2].tb_frame while frame: - print("File: %s, Line: %d" % (frame.f_code.co_filename, frame.f_lineno)) + print(f"File: {frame.f_code.co_filename}, Line: {frame.f_lineno}") frame = frame.f_back # and raise the exception for COM @@ -82,7 +82,7 @@ def __init__(self, policyClass, object): def _QueryInterface_(self, iid): rc = win32com.server.policy.DispatcherBase._QueryInterface_(self, iid) # if not rc: - # self._trace_("in _QueryInterface_ with unsupported IID %s (%s)\n" % (IIDToInterfaceName(iid),iid)) + # self._trace_(f"in _QueryInterface_ with unsupported IID {IIDToInterfaceName(iid)} ({iid})\n") return rc def _Invoke_(self, dispid, lcid, wFlags, args): @@ -109,11 +109,9 @@ def _Invoke_(self, dispid, lcid, wFlags, args): desc = " (" + str(v.description) + ")" except AttributeError: desc = "" - print( - "*** Invoke of %s raised COM exception 0x%x%s" % (dispid, scode, desc) - ) + print(f"*** Invoke of {dispid} raised COM exception 0x{scode:x}{desc}") except: - print("*** Invoke of %s failed:" % dispid) + print(f"*** Invoke of {dispid} failed:") typ, val, tb = sys.exc_info() import traceback From bc4ecf8cb592e54cf211e95653cd972633dc3003 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 1 Nov 2023 14:44:03 -0400 Subject: [PATCH 4/4] post-merge improvements --- .../framework/editor/color/coloreditor.py | 18 ++++++---------- Pythonwin/pywin/framework/editor/editor.py | 21 ++++++++----------- com/win32comext/axdebug/documents.py | 2 +- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/Pythonwin/pywin/framework/editor/color/coloreditor.py b/Pythonwin/pywin/framework/editor/color/coloreditor.py index 3d9b7e09e6..9de95a392f 100644 --- a/Pythonwin/pywin/framework/editor/color/coloreditor.py +++ b/Pythonwin/pywin/framework/editor/color/coloreditor.py @@ -2,29 +2,23 @@ # even tighter into Pythonwin. import pywin.scintilla.keycodes +import pywin.scintilla.view import win32api import win32con import win32ui +from pywin.debugger import dbgcon from pywin.framework.editor import GetEditorOption -from pywin.scintilla import bindings - -# from pywin.framework.editor import EditorPropertyPage +from pywin.framework.editor.document import EditorDocumentBase +from pywin.scintilla import bindings, scintillacon -MSG_CHECK_EXTERNAL_FILE = ( - win32con.WM_USER + 1999 -) ## WARNING: Duplicated in document.py and editor.py +# WARNING: Duplicated in document.py and editor.py +MSG_CHECK_EXTERNAL_FILE = win32con.WM_USER + 1999 # Define a few common markers MARKER_BOOKMARK = 0 MARKER_BREAKPOINT = 1 MARKER_CURRENT = 2 -import pywin.scintilla.view -from pywin.debugger import dbgcon -from pywin.framework.editor.document import EditorDocumentBase -from pywin.scintilla import scintillacon # For the marker definitions -from pywin.scintilla.document import CScintillaDocument - class SyntEditDocument(EditorDocumentBase): "A SyntEdit document." diff --git a/Pythonwin/pywin/framework/editor/editor.py b/Pythonwin/pywin/framework/editor/editor.py index c14a2b7242..e394a06bfb 100644 --- a/Pythonwin/pywin/framework/editor/editor.py +++ b/Pythonwin/pywin/framework/editor/editor.py @@ -28,16 +28,21 @@ GetEditorOption, defaultCharacterFormat, ) -from pywin.mfc import afxres, docview +from pywin.mfc import afxres +from pywin.mfc.docview import RichEditView as ParentEditorView + +from .document import EditorDocumentBase as ParentEditorDocument + +# from pywin.mfc.docview import EditView as ParentEditorView +# from pywin.mfc.docview import Document as ParentEditorDocument patImport = regex.symcomp(r"import \(.*\)") patIndent = regex.compile(r"^\([ \t]*[~ \t]\)") ID_LOCATE_FILE = 0xE200 ID_GOTO_LINE = 0xE2001 -MSG_CHECK_EXTERNAL_FILE = ( - win32con.WM_USER + 1999 -) ## WARNING: Duplicated in document.py and coloreditor.py +# WARNING: Duplicated in document.py and coloreditor.py +MSG_CHECK_EXTERNAL_FILE = win32con.WM_USER + 1999 # Key Codes that modify the bufffer when Ctrl or Alt are NOT pressed. MODIFYING_VK_KEYS = [ @@ -76,11 +81,6 @@ isRichText = 1 # We are using the Rich Text control. This has not been tested with value "0" for quite some time! -# ParentEditorDocument=docview.Document -from .document import EditorDocumentBase - -ParentEditorDocument = EditorDocumentBase - class EditorDocument(ParentEditorDocument): # @@ -164,9 +164,6 @@ def SetLineColor(self, lineNo, color): # self.saveFileHandle.write(data) # return 1 # keep em coming! -# ParentEditorView=docview.EditView -ParentEditorView = docview.RichEditView - class EditorView(ParentEditorView): def __init__(self, doc): diff --git a/com/win32comext/axdebug/documents.py b/com/win32comext/axdebug/documents.py index 31a5c8441c..4b93e8c1d0 100644 --- a/com/win32comext/axdebug/documents.py +++ b/com/win32comext/axdebug/documents.py @@ -33,7 +33,7 @@ def GetDocument(self): return self.doc -class DebugDocumentText(gateways.DebugDocumentInfo, gateways.DebugDocumentText): +class DebugDocumentText(gateways.DebugDocumentText): _com_interfaces_ = ( gateways.DebugDocumentInfo._com_interfaces_ + gateways.DebugDocumentText._com_interfaces_