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/Test/host.py b/com/win32comext/axdebug/Test/host.py index cb3a160a8d..b3d1317462 100644 --- a/com/win32comext/axdebug/Test/host.py +++ b/com/win32comext/axdebug/Test/host.py @@ -3,10 +3,9 @@ import pythoncom import win32api -import win32com.server.util import winerror -from win32com.axdebug import adb, axdebug, codecontainer, gateways -from win32com.axdebug.util import trace +from win32com.axdebug import codecontainer, gateways +from win32com.axdebug.util import _wrap, trace from win32com.server.exception import Exception @@ -24,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): @@ -47,9 +48,7 @@ def _query_interface_(self, iid): from win32com.util import IIDToInterfaceName trace( - "PySourceModuleDebugDocumentHost QI with {} ({})".format( - 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__ @@ -96,71 +95,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() @@ -170,22 +123,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()) + f" {pythoncom._GetInterfaceCount()}/{pythoncom._GetGatewayCount()} com objects still alive" ) diff --git a/com/win32comext/axdebug/adb.py b/com/win32comext/axdebug/adb.py index 68850b5c1b..7f0984535d 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 @@ -53,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 @@ -118,8 +112,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 +151,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 +189,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 +207,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 +220,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): @@ -281,11 +275,8 @@ def CloseApp(self): except pythoncom.com_error: trace( - "*** Could not RemoveStackFrameSniffer %d" - % (self.stackSnifferCookie) + f"*** Could not RemoveStackFrameSniffer {self.stackSnifferCookie}" ) - if self.stackSniffer: - _wrap_remove(self.stackSniffer) self.stackSnifferCookie = self.stackSniffer = None if self.appEventConnection is not None: @@ -298,7 +289,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 +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( @@ -321,7 +312,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 @@ -427,14 +418,14 @@ def OnBreakFlagChange(self, abf, rdat): def _BreakFlagsChanged(self): traceenter( - "_BreakFlagsChanged to {} with our thread = {}, and debugging thread = {}".format( - self.breakFlags, self.debuggingThread, win32api.GetCurrentThreadId() - ) + f"_BreakFlagsChanged to {self.breakFlags} " + + f"with our thread = {self.debuggingThread}, " + + f"and debugging thread = {win32api.GetCurrentThreadId()}" ) 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..69a9f8e458 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 @@ -226,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 @@ -247,17 +246,16 @@ 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) 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: @@ -267,10 +265,10 @@ 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 + # 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 d1f5d4801e..8953f5ab9c 100644 --- a/com/win32comext/axdebug/contexts.py +++ b/com/win32comext/axdebug/contexts.py @@ -1,9 +1,6 @@ """ 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. diff --git a/com/win32comext/axdebug/debugger.py b/com/win32comext/axdebug/debugger.py index 5738007903..65a682680c 100644 --- a/com/win32comext/axdebug/debugger.py +++ b/com/win32comext/axdebug/debugger.py @@ -2,18 +2,8 @@ import sys import pythoncom -import win32api -from win32com.axdebug import ( - adb, - axdebug, - codecontainer, - contexts, - documents, - expressions, - gateways, -) +from win32com.axdebug import adb, axdebug, codecontainer, documents, expressions from win32com.axdebug.util import _wrap -from win32com.axscript import axscript currentDebugger = None @@ -29,7 +19,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) @@ -49,9 +39,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) @@ -91,18 +81,18 @@ 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): 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 = {} @@ -169,7 +159,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() @@ -244,6 +234,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 f5a3823b22..4b93e8c1d0 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, gateways from .util import _wrap, trace # def trace(*args): -# pass +# pass def GetGoodFileName(fname): @@ -34,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_ @@ -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(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 c47654fb1c..61a1cfc7ab 100644 --- a/com/win32comext/axdebug/dump.py +++ b/com/win32comext/axdebug/dump.py @@ -26,13 +26,11 @@ 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)) - ) + print(f"{spacer}Text is {repr(text[:40] + '...')}, {len(text)} bytes long") else: - print("{}{}".format(spacer, "")) + print(f"{spacer*2}") 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/expressions.py b/com/win32comext/axdebug/expressions.py index 8a95842dcb..d741e45a44 100644 --- a/com/win32comext/axdebug/expressions.py +++ b/com/win32comext/axdebug/expressions.py @@ -4,7 +4,6 @@ from pprint import pprint import winerror -from win32com.server.exception import COMException from . import axdebug, gateways from .util import RaiseNotImpl, _wrap @@ -32,7 +31,7 @@ def ParseLanguageText(self, code, radix, delim, flags): ) def GetLanguageInfo(self): - # print "GetLanguageInfo" + # print("GetLanguageInfo") return "Python", "{DF630910-1C1D-11d0-AE36-8C0F5E000000}" @@ -77,7 +76,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): @@ -187,8 +186,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..a5c888872c 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(f"EnumDebugStackFrames QI with {IIDToInterfaceName(iid)} ({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 ff0af1720d..805d21b28b 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,27 +52,9 @@ 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)) + print(f"********* Function {who} Raising E_NOTIMPL ************") # Print a sort-of "traceback", dumping all the frames leading to here. try: @@ -82,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 @@ -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_(f"in _QueryInterface_ with unsupported IID {IIDToInterfaceName(iid)} ({iid})\n") 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() @@ -131,7 +111,7 @@ def _Invoke_(self, dispid, lcid, wFlags, args): 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 diff --git a/com/win32comext/axscript/client/debug.py b/com/win32comext/axscript/client/debug.py index e2eec02911..b1d7dabec7 100644 --- a/com/win32comext/axscript/client/debug.py +++ b/com/win32comext/axscript/client/debug.py @@ -7,7 +7,7 @@ import winerror from win32com.axdebug import adb, axdebug, documents, gateways 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 @@ -86,9 +86,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 9b38a9ef4a..f642ab0096 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")