diff --git a/Pythonwin/pywin/__init__.py b/Pythonwin/pywin/__init__.py index 2e44fba5ca..43d5c446fd 100644 --- a/Pythonwin/pywin/__init__.py +++ b/Pythonwin/pywin/__init__.py @@ -3,8 +3,5 @@ # others are looking at it, but it will go away soon! is_platform_unicode = 0 -# Ditto default_platform_encoding - not referenced and will die. -default_platform_encoding = "mbcs" - # This one *is* real and used - but in practice can't be changed. default_scintilla_encoding = "utf-8" # Scintilla _only_ supports this ATM 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/Pythonwin/pywin/framework/scriptutils.py b/Pythonwin/pywin/framework/scriptutils.py index 5fb6702f16..a04ed7bbee 100644 --- a/Pythonwin/pywin/framework/scriptutils.py +++ b/Pythonwin/pywin/framework/scriptutils.py @@ -98,7 +98,7 @@ def IsOnPythonPath(path): def GetPackageModuleName(fileName): - """Given a filename, return (module name, new path). + r"""Given a filename, return (module name, new path). eg - given "c:\a\b\c\my.py", return ("b.c.my",None) if "c:\a" is on sys.path. If no package found, will return ("my", "c:\a\b\c") """ diff --git a/Pythonwin/pywin/tools/hierlist.py b/Pythonwin/pywin/tools/hierlist.py index 580d4dcc3f..cc76f1905a 100644 --- a/Pythonwin/pywin/tools/hierlist.py +++ b/Pythonwin/pywin/tools/hierlist.py @@ -175,8 +175,6 @@ def AddItem(self, parentHandle, item, hInsertAfter=commctrl.TVI_LAST): bitmapSel = self.GetSelectedBitmapColumn(item) if bitmapSel is None: bitmapSel = bitmapCol - ## if isinstance(text, str): - ## text = text.encode("mbcs") hitem = self.listControl.InsertItem( parentHandle, hInsertAfter, diff --git a/com/win32com/client/__init__.py b/com/win32com/client/__init__.py index 9a74a4defc..6f8ad07088 100644 --- a/com/win32com/client/__init__.py +++ b/com/win32com/client/__init__.py @@ -55,7 +55,7 @@ def __WrapDispatch( def GetObject(Pathname=None, Class=None, clsctx=None): - """ + r""" Mimic VB's GetObject() function. ob = GetObject(Class = "ProgID") or GetObject(Class = clsid) will diff --git a/com/win32com/client/genpy.py b/com/win32com/client/genpy.py index 739f3ddd00..06f11889cd 100644 --- a/com/win32com/client/genpy.py +++ b/com/win32com/client/genpy.py @@ -1025,7 +1025,7 @@ def BuildOleItemsFromType(self): return oleItems, enumItems, recordItems, vtableItems - def open_writer(self, filename, encoding="mbcs"): + def open_writer(self, filename, encoding="utf-8"): # A place to put code to open a file with the appropriate encoding. # Does *not* set self.file - just opens and returns a file. # Actually returns a handle to a temp file - finish_writer then deletes @@ -1097,7 +1097,7 @@ def do_gen_file_header(self): # We assert this is it may indicate somewhere in pywin32 that needs # upgrading. assert self.file.encoding, self.file - encoding = self.file.encoding # or "mbcs" + encoding = self.file.encoding print(f"# -*- coding: {encoding} -*-", file=self.file) print(f"# Created by makepy.py version {makepy_version}", file=self.file) diff --git a/com/win32comext/authorization/demos/EditServiceSecurity.py b/com/win32comext/authorization/demos/EditServiceSecurity.py index 009f4245cb..f60f71a7c9 100644 --- a/com/win32comext/authorization/demos/EditServiceSecurity.py +++ b/com/win32comext/authorization/demos/EditServiceSecurity.py @@ -1,4 +1,4 @@ -""" +r""" Implements a permissions editor for services. Service can be specified as plain name for local machine, or as a remote service of the form \\machinename\service diff --git a/com/win32comext/axdebug/Test/host.py b/com/win32comext/axdebug/Test/host.py index abc0cfbe98..b3d1317462 100644 --- a/com/win32comext/axdebug/Test/host.py +++ b/com/win32comext/axdebug/Test/host.py @@ -3,7 +3,6 @@ import pythoncom import win32api -import win32com.server.util import winerror from win32com.axdebug import codecontainer, gateways from win32com.axdebug.util import _wrap, trace @@ -49,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 @@ -60,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__ @@ -115,8 +112,8 @@ def TestSmartProvider(): from win32com.axdebug import debugger d = debugger.AXDebugger() - # d.StartDebugger() - # d.Attach() + # d.StartDebugger() + # d.Attach() d.Break() input("Waiting...") ttest.test() @@ -133,10 +130,6 @@ def test(): 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 c7dd48d75e..7f0984535d 100644 --- a/com/win32comext/axdebug/adb.py +++ b/com/win32comext/axdebug/adb.py @@ -10,7 +10,6 @@ import win32api import win32com.client.connect from win32com.axdebug.util import _wrap, trace -from win32com.server.util import unwrap 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,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 @@ -296,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( @@ -305,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( @@ -319,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 @@ -425,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 a96910a29c..69a9f8e458 100644 --- a/com/win32comext/axdebug/codecontainer.py +++ b/com/win32comext/axdebug/codecontainer.py @@ -10,12 +10,10 @@ 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 @@ -44,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 @@ -79,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): @@ -188,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 @@ -227,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 @@ -248,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) @@ -257,7 +255,7 @@ def GetName(self, dnt): 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 4424eec84a..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): 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 94f10aeb62..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,22 +52,9 @@ def _wrap_debug(object, iid): _wrap = _wrap_nodebug -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: @@ -77,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 @@ -92,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): @@ -114,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() @@ -126,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/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") diff --git a/win32/scripts/regsetup.py b/win32/scripts/regsetup.py index fd0f636a06..0aca77188c 100644 --- a/win32/scripts/regsetup.py +++ b/win32/scripts/regsetup.py @@ -497,23 +497,24 @@ def RegisterShellInfo(searchPaths): of the registry. """ -examples = """\ +# Using raw string so that all paths meant to be copied read correctly inline and when printed +examples = r""" Examples: -"regsetup c:\\wierd\\spot\\1 c:\\wierd\\spot\\2" +"regsetup c:\wierd\spot\1 c:\wierd\spot\2" Attempts to setup the core Python. Looks in some standard places, as well as the 2 wierd spots to locate the core Python files (eg, Python.exe, pythonXX.dll, the standard library and Win32 Extensions. "regsetup -a myappname . .\subdir" -Registers a new Pythonpath entry named myappname, with "C:\\I\\AM\\HERE" and -"C:\\I\\AM\\HERE\subdir" added to the path (ie, all args are converted to +Registers a new Pythonpath entry named myappname, with "C:\I\AM\HERE" and +"C:\I\AM\HERE\subdir" added to the path (ie, all args are converted to absolute paths) -"regsetup -c c:\\my\\python\\files" -Unconditionally add "c:\\my\\python\\files" to the 'core' Python path. +"regsetup -c c:\my\python\files" +Unconditionally add "c:\my\python\files" to the 'core' Python path. -"regsetup -m some.pyd \\windows\\system" -Register the module some.pyd in \\windows\\system as a registered +"regsetup -m some.pyd \windows\system" +Register the module some.pyd in \windows\system as a registered module. This will allow some.pyd to be imported, even though the windows system directory is not (usually!) on the Python Path. diff --git a/win32/test/test_clipboard.py b/win32/test/test_clipboard.py index 8f74e8575e..3d6c1efc5a 100644 --- a/win32/test/test_clipboard.py +++ b/win32/test/test_clipboard.py @@ -67,7 +67,7 @@ def tearDown(self): CloseClipboard() def test_unicode(self): - val = "test-\a9har" + val = "test-\xa9har" SetClipboardData(win32con.CF_UNICODETEXT, val) self.assertEqual(GetClipboardData(win32con.CF_UNICODETEXT), val) diff --git a/win32/test/test_odbc.py b/win32/test/test_odbc.py index b40a3f6c51..ce0d0426a9 100644 --- a/win32/test/test_odbc.py +++ b/win32/test/test_odbc.py @@ -207,7 +207,7 @@ def testLongBinary(self): def testRaw(self): ## Test binary data - self._test_val("rawfield", memoryview(b"\1\2\3\4\0\5\6\7\8")) + self._test_val("rawfield", memoryview(b"\1\2\3\4\0\5\6\7")) def test_widechar(self): """Test a unicode character that would be mangled if bound as plain character.