diff --git a/CHANGES.txt b/CHANGES.txt index c31fd2dbe6..7a238523fb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -69,7 +69,7 @@ Build 305, released 2022-11-06 from there. (#1908) * Dropped support for allowing a bytes object to be passed where a COM BSTR - is expected - this support was accidental on the path from 2.x->3.x. + is expected - this support was accidental on the path from Python 2 -> 3. * win32crypt's PyCERTSTORE.CertCloseStore()'s `Flags` argument has been deprecated as it is likely to crash the process if diff --git a/Pythonwin/pywin/Demos/fontdemo.py b/Pythonwin/pywin/Demos/fontdemo.py index 68c353cb21..0c1f7f1d11 100644 --- a/Pythonwin/pywin/Demos/fontdemo.py +++ b/Pythonwin/pywin/Demos/fontdemo.py @@ -72,13 +72,12 @@ def FontDemo(): template = docview.DocTemplate(win32ui.IDR_PYTHONTYPE, None, None, FontView) doc = template.OpenDocumentFile(None) doc.SetTitle("Font Demo") - # print "template is ", template, "obj is", template._obj_ + # print("template is ", template, "obj is", template._obj_) template.close() + # print("closed") + # del template -# print "closed" -# del template - if __name__ == "__main__": import demoutils diff --git a/Pythonwin/pywin/Demos/guidemo.py b/Pythonwin/pywin/Demos/guidemo.py index 95b1dbbc91..887738c244 100644 --- a/Pythonwin/pywin/Demos/guidemo.py +++ b/Pythonwin/pywin/Demos/guidemo.py @@ -17,7 +17,7 @@ ("Dynamic window creation", "import createwin;createwin.demo()"), ("Various Dialog demos", "import dlgtest;dlgtest.demo()"), ("OCX Control Demo", "from ocx import ocxtest;ocxtest.demo()"), - ("OCX Serial Port Demo", "from ocx import ocxserialtest; ocxserialtest.test()"), + ("OCX Serial Port Demo", "from ocx import ocxserialtest; ocxserialtest.test()"), ( "IE4 Control Demo", 'from ocx import webbrowser; webbrowser.Demo("http://www.python.org")', diff --git a/Pythonwin/pywin/Demos/ocx/webbrowser.py b/Pythonwin/pywin/Demos/ocx/webbrowser.py index 914b84a555..1dc318c198 100644 --- a/Pythonwin/pywin/Demos/ocx/webbrowser.py +++ b/Pythonwin/pywin/Demos/ocx/webbrowser.py @@ -24,7 +24,7 @@ def OnBeforeNavigate2( self, pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel ): self.GetParent().OnNavigate(URL) - # print "BeforeNavigate2", pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel + # print("BeforeNavigate2", pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel) class BrowserFrame(window.MDIChildWnd): diff --git a/Pythonwin/pywin/Demos/splittst.py b/Pythonwin/pywin/Demos/splittst.py index 0114bf09a3..2dbeb1e223 100644 --- a/Pythonwin/pywin/Demos/splittst.py +++ b/Pythonwin/pywin/Demos/splittst.py @@ -60,8 +60,8 @@ def __init__(self): ) def InitialUpdateFrame(self, frame, doc, makeVisible): - # print "frame is ", frame, frame._obj_ - # print "doc is ", doc, doc._obj_ + # print("frame is ", frame, frame._obj_) + # print("doc is ", doc, doc._obj_) self._obj_.InitialUpdateFrame(frame, doc, makeVisible) # call default handler. frame.InitialUpdateFrame(doc, makeVisible) diff --git a/Pythonwin/pywin/Demos/threadedgui.py b/Pythonwin/pywin/Demos/threadedgui.py index 556ed18d5c..5b0704ef3b 100644 --- a/Pythonwin/pywin/Demos/threadedgui.py +++ b/Pythonwin/pywin/Demos/threadedgui.py @@ -61,7 +61,7 @@ def OnTimer(self, id, timeVal): self.InvalidateRect() def OnPaint(self): - # print "Paint message from thread", win32api.GetCurrentThreadId() + # print("Paint message from thread", win32api.GetCurrentThreadId()) dc, paintStruct = self.BeginPaint() self.OnPrepareDC(dc, None) diff --git a/Pythonwin/pywin/debugger/debugger.py b/Pythonwin/pywin/debugger/debugger.py index 3b801fc851..17e64f7c5d 100644 --- a/Pythonwin/pywin/debugger/debugger.py +++ b/Pythonwin/pywin/debugger/debugger.py @@ -118,11 +118,11 @@ def __init__(self, debugger): HierListItem.__init__(self, debugger, None) self.last_stack = [] - ## def __del__(self): - ## print "HierStackRoot dieing" + # def __del__(self): + # print("HierStackRoot dieing") def GetSubList(self): debugger = self.myobject - # print self.debugger.stack, self.debugger.curframe + # print(self.debugger.stack, self.debugger.curframe) ret = [] if debugger.debuggerState == DBGSTATE_BREAK: stackUse = debugger.stack[:] diff --git a/Pythonwin/pywin/docking/DockingBar.py b/Pythonwin/pywin/docking/DockingBar.py index 34b14a41a1..3e9b4131a6 100644 --- a/Pythonwin/pywin/docking/DockingBar.py +++ b/Pythonwin/pywin/docking/DockingBar.py @@ -234,15 +234,15 @@ def OnWindowPosChanged(self, msg): return 0 lparam = msg[3] """ LPARAM used with WM_WINDOWPOSCHANGED: - typedef struct { - HWND hwnd; - HWND hwndInsertAfter; - int x; - int y; - int cx; - int cy; - UINT flags;} WINDOWPOS; - """ + typedef struct { + HWND hwnd; + HWND hwndInsertAfter; + int x; + int y; + int cx; + int cy; + UINT flags;} WINDOWPOS; + """ format = "PPiiiii" bytes = win32ui.GetBytes(lparam, struct.calcsize(format)) hwnd, hwndAfter, x, y, cx, cy, flags = struct.unpack(format, bytes) diff --git a/Pythonwin/pywin/framework/editor/ModuleBrowser.py b/Pythonwin/pywin/framework/editor/ModuleBrowser.py index d1437e6a40..d7370e90cd 100644 --- a/Pythonwin/pywin/framework/editor/ModuleBrowser.py +++ b/Pythonwin/pywin/framework/editor/ModuleBrowser.py @@ -148,7 +148,7 @@ def DestroyBrowser(self): self.DestroyList() def OnActivateView(self, activate, av, dv): - # print "AV", self.bDirty, activate + # print("AV", self.bDirty, activate) if activate: self.CheckRefreshList() return self._obj_.OnActivateView(activate, av, dv) diff --git a/Pythonwin/pywin/framework/editor/color/coloreditor.py b/Pythonwin/pywin/framework/editor/color/coloreditor.py index 9de95a392f..6818d82502 100644 --- a/Pythonwin/pywin/framework/editor/color/coloreditor.py +++ b/Pythonwin/pywin/framework/editor/color/coloreditor.py @@ -9,7 +9,10 @@ from pywin.debugger import dbgcon from pywin.framework.editor import GetEditorOption from pywin.framework.editor.document import EditorDocumentBase +from pywin.framework.editor.frame import EditorFrame +from pywin.framework.editor.template import EditorTemplateBase from pywin.scintilla import bindings, scintillacon +from pywin.scintilla.view import CScintillaView as SyntEditViewParent # WARNING: Duplicated in document.py and editor.py MSG_CHECK_EXTERNAL_FILE = win32con.WM_USER + 1999 @@ -36,9 +39,6 @@ def FinalizeViewCreation(self, view): self.GetDocTemplate().CheckIDLEMenus(view.idle) -SyntEditViewParent = pywin.scintilla.view.CScintillaView - - class SyntEditView(SyntEditViewParent): "A view of a SyntEdit. Obtains data from document." @@ -462,7 +462,7 @@ def FoldTopLevelEvent(self, event=None): - scintillacon.SC_FOLDLEVELBASE ) is_header = level & scintillacon.SC_FOLDLEVELHEADERFLAG - # print lineSeek, level_no, is_header + # print(lineSeek, level_no, is_header) if level_no == 0 and is_header: if (expanding and not self.SCIGetFoldExpanded(lineSeek)) or ( not expanding and self.SCIGetFoldExpanded(lineSeek) @@ -571,9 +571,6 @@ def FoldCollapseAllEvent(self, event): win32ui.DoWaitCursor(-1) -from pywin.framework.editor.frame import EditorFrame - - class SplitterFrame(EditorFrame): def OnCreate(self, cs): self.HookCommand(self.OnWindowSplit, win32ui.ID_WINDOW_SPLIT) @@ -584,9 +581,6 @@ def OnWindowSplit(self, id, code): return 1 -from pywin.framework.editor.template import EditorTemplateBase - - class SyntEditTemplate(EditorTemplateBase): def __init__( self, res=win32ui.IDR_TEXTTYPE, makeDoc=None, makeFrame=None, makeView=None diff --git a/Pythonwin/pywin/framework/editor/editor.py b/Pythonwin/pywin/framework/editor/editor.py index e394a06bfb..6c332bd777 100644 --- a/Pythonwin/pywin/framework/editor/editor.py +++ b/Pythonwin/pywin/framework/editor/editor.py @@ -263,7 +263,7 @@ def Indent(self): else: curCol = curCol + 1 nextColumn = ((curCol / self.indentSize) + 1) * self.indentSize - # print "curCol is", curCol, "nextColumn is", nextColumn + # print("curCol is", curCol, "nextColumn is", nextColumn) ins = None if self.bSmartTabs: # Look for some context. diff --git a/Pythonwin/pywin/framework/editor/frame.py b/Pythonwin/pywin/framework/editor/frame.py index e927d16e5f..e0d97f37c4 100644 --- a/Pythonwin/pywin/framework/editor/frame.py +++ b/Pythonwin/pywin/framework/editor/frame.py @@ -25,15 +25,15 @@ def OnCreateClient(self, cp, context): splitter.CreateView(browserView, 0, 0, (0, 0)) sub_splitter.CreateView(view2, 0, 0, (0, 0)) - ## print "First view is", context.doc.GetFirstView() - ## print "Views are", view, view2, browserView - ## print "Parents are", view.GetParent(), view2.GetParent(), browserView.GetParent() - ## print "Splitter is", splitter - ## print "sub splitter is", sub_splitter - ## Old - ## splitter.CreateStatic (self, 1, 2) - ## splitter.CreateView(view, 0, 1, (0,0)) # size ignored. - ## splitter.CreateView (browserView, 0, 0, (0, 0)) + # print("First view is", context.doc.GetFirstView()) + # print("Views are", view, view2, browserView) + # print("Parents are", view.GetParent(), view2.GetParent(), browserView.GetParent()) + # print("Splitter is", splitter) + # print("sub splitter is", sub_splitter) + # Old + # splitter.CreateStatic (self, 1, 2) + # splitter.CreateView(view, 0, 1, (0,0)) # size ignored. + # splitter.CreateView (browserView, 0, 0, (0, 0)) # Restrict the size of the browser splitter (and we can avoid filling # it until it is shown) @@ -62,8 +62,8 @@ def GetBrowserView(self): def OnClose(self): doc = self.GetActiveDocument() if not doc.SaveModified(): - ## Cancel button selected from Save dialog, do not actually close - ## print 'close cancelled' + # Cancel button selected from Save dialog, do not actually close + # print("close cancelled") return 0 ## So the 'Save' dialog doesn't come up twice doc._obj_.SetModifiedFlag(False) diff --git a/Pythonwin/pywin/framework/editor/template.py b/Pythonwin/pywin/framework/editor/template.py index 362a74a62d..bbaed4e689 100644 --- a/Pythonwin/pywin/framework/editor/template.py +++ b/Pythonwin/pywin/framework/editor/template.py @@ -50,11 +50,11 @@ def OpenDocumentFile(self, filename, bMakeVisible=1): if filename is not None: try: path = os.path.split(filename)[0] - # print "The editor is translating", `filename`,"to", + # print("The editor is translating", "filename", "to") filename = win32api.FindFiles(filename)[0][8] filename = os.path.join(path, filename) - # print `filename` + # print("filename") except (win32api.error, IndexError) as details: + # print("Couldnt get the full filename!", details) pass - # print "Couldnt get the full filename!", details return self._obj_.OpenDocumentFile(filename, bMakeVisible) diff --git a/Pythonwin/pywin/framework/intpydde.py b/Pythonwin/pywin/framework/intpydde.py index 1f869b0f68..2401cdc566 100644 --- a/Pythonwin/pywin/framework/intpydde.py +++ b/Pythonwin/pywin/framework/intpydde.py @@ -21,7 +21,7 @@ def __init__(self, app): def Exec(self, data): try: - # print "Executing", cmd + # print("Executing", cmd) self.app.OnDDECommand(data) except: t, v, tb = sys.exc_info() diff --git a/Pythonwin/pywin/framework/mdi_pychecker.py b/Pythonwin/pywin/framework/mdi_pychecker.py index 40fd4472f2..72b70093a7 100644 --- a/Pythonwin/pywin/framework/mdi_pychecker.py +++ b/Pythonwin/pywin/framework/mdi_pychecker.py @@ -432,10 +432,10 @@ def GetParams(self): ) def OnSaveDocument(self, filename): - # print 'OnSaveDocument() filename=',filename + # print("OnSaveDocument() filename=",filename) savefile = open(filename, "wb") txt = self.GetParams() + "\n" - # print 'writing',txt + # print("writing",txt) savefile.write(txt) savefile.close() self.SetModifiedFlag(0) diff --git a/Pythonwin/pywin/framework/scriptutils.py b/Pythonwin/pywin/framework/scriptutils.py index a04ed7bbee..2f9c56e2de 100644 --- a/Pythonwin/pywin/framework/scriptutils.py +++ b/Pythonwin/pywin/framework/scriptutils.py @@ -1,6 +1,7 @@ """ Various utilities for running/importing a script """ + import bdb import linecache import os diff --git a/Pythonwin/pywin/framework/sgrepmdi.py b/Pythonwin/pywin/framework/sgrepmdi.py index 1c0d6339c4..a4068b5cd2 100644 --- a/Pythonwin/pywin/framework/sgrepmdi.py +++ b/Pythonwin/pywin/framework/sgrepmdi.py @@ -344,10 +344,10 @@ def GetParams(self): ) def OnSaveDocument(self, filename): - # print 'OnSaveDocument() filename=',filename + # print("OnSaveDocument() filename=", filename) savefile = open(filename, "wb") txt = self.GetParams() + "\n" - # print 'writing',txt + # print("writing", txt) savefile.write(txt) savefile.close() self.SetModifiedFlag(0) diff --git a/Pythonwin/pywin/framework/toolmenu.py b/Pythonwin/pywin/framework/toolmenu.py index afe06b2b41..1f16f9fca1 100644 --- a/Pythonwin/pywin/framework/toolmenu.py +++ b/Pythonwin/pywin/framework/toolmenu.py @@ -214,7 +214,7 @@ def OnOK(self): return self._obj_.OnOK() def OnCommandEditControls(self, id, cmd): - # print "OnEditControls", id, cmd + # print("OnEditControls", id, cmd) if cmd == win32con.EN_CHANGE and not self.bImChangingEditControls: itemNo = self.listControl.GetNextItem(-1, commctrl.LVNI_SELECTED) newText = self.editMenuCommand.GetWindowText() @@ -228,7 +228,7 @@ def OnNotifyListControlEndLabelEdit(self, id, cmd): self.listControl.SetItemText(itemNo, 0, newText) def OnNotifyListControl(self, id, cmd): - # print id, cmd + # print(id, cmd) try: itemNo = self.listControl.GetNextItem(-1, commctrl.LVNI_SELECTED) except win32ui.error: # No selection! diff --git a/Pythonwin/pywin/mfc/activex.py b/Pythonwin/pywin/mfc/activex.py index a9828e78dc..f3d9939a4b 100644 --- a/Pythonwin/pywin/mfc/activex.py +++ b/Pythonwin/pywin/mfc/activex.py @@ -1,5 +1,6 @@ """Support for ActiveX control hosting in Pythonwin. """ + import win32ui import win32uiole diff --git a/Pythonwin/pywin/mfc/dialog.py b/Pythonwin/pywin/mfc/dialog.py index 280c025aa1..41107e54d3 100644 --- a/Pythonwin/pywin/mfc/dialog.py +++ b/Pythonwin/pywin/mfc/dialog.py @@ -1,6 +1,7 @@ """ \ Base class for Dialogs. Also contains a few useful utility functions """ + # dialog.py # Python class for Dialog Boxes in PythonWin. diff --git a/Pythonwin/pywin/mfc/object.py b/Pythonwin/pywin/mfc/object.py index 063f835f76..62062a5351 100644 --- a/Pythonwin/pywin/mfc/object.py +++ b/Pythonwin/pywin/mfc/object.py @@ -33,7 +33,7 @@ def __getattr__( raise AttributeError(attr) def OnAttachedObjectDeath(self): - # print "object", self.__class__.__name__, "dieing" + # print("object", self.__class__.__name__, "dieing") self._obj_ = None def close(self): diff --git a/Pythonwin/pywin/scintilla/IDLEenvironment.py b/Pythonwin/pywin/scintilla/IDLEenvironment.py index f60f19de36..9114c2c6bd 100644 --- a/Pythonwin/pywin/scintilla/IDLEenvironment.py +++ b/Pythonwin/pywin/scintilla/IDLEenvironment.py @@ -533,30 +533,30 @@ def test(): e.SetSel((4, 4)) skip = """ - TestCheck("insert", e, 4) - TestCheck("insert wordstart", e, 3) - TestCheck("insert wordend", e, 8) - TestCheck("insert linestart", e, 0) - TestCheck("insert lineend", e, 12) - TestCheck("insert + 4 chars", e, 8) - TestCheck("insert +4c", e, 8) - TestCheck("insert - 2 chars", e, 2) - TestCheck("insert -2c", e, 2) - TestCheck("insert-2c", e, 2) - TestCheck("insert-2 c", e, 2) - TestCheck("insert- 2c", e, 2) - TestCheck("1.1", e, 1) - TestCheck("1.0", e, 0) - TestCheck("2.0", e, 13) - try: - TestCheck("sel.first", e, 0) - print "*** sel.first worked with an empty selection" - except TextError: - pass - e.SetSel((4,5)) - TestCheck("sel.first- 2c", e, 2) - TestCheck("sel.last- 2c", e, 3) - """ + TestCheck("insert", e, 4) + TestCheck("insert wordstart", e, 3) + TestCheck("insert wordend", e, 8) + TestCheck("insert linestart", e, 0) + TestCheck("insert lineend", e, 12) + TestCheck("insert + 4 chars", e, 8) + TestCheck("insert +4c", e, 8) + TestCheck("insert - 2 chars", e, 2) + TestCheck("insert -2c", e, 2) + TestCheck("insert-2c", e, 2) + TestCheck("insert-2 c", e, 2) + TestCheck("insert- 2c", e, 2) + TestCheck("1.1", e, 1) + TestCheck("1.0", e, 0) + TestCheck("2.0", e, 13) + try: + TestCheck("sel.first", e, 0) + print("*** sel.first worked with an empty selection") + except TextError: + pass + e.SetSel((4,5)) + TestCheck("sel.first- 2c", e, 2) + TestCheck("sel.last- 2c", e, 3) + """ # Check EOL semantics e.SetSel((4, 4)) TestGet("insert lineend", "insert lineend +1c", t, "\n") diff --git a/Pythonwin/pywin/scintilla/configui.py b/Pythonwin/pywin/scintilla/configui.py index 1c48c6cf65..2a47a0e0da 100644 --- a/Pythonwin/pywin/scintilla/configui.py +++ b/Pythonwin/pywin/scintilla/configui.py @@ -228,7 +228,7 @@ def UpdateUIForStyle(self, style): sel = 0 for c in paletteVGA: if format[4] == c[1]: - # print "Style", style.name, "is", c[0] + # print("Style", style.name, "is", c[0]) break sel = sel + 1 else: diff --git a/Pythonwin/pywin/scintilla/document.py b/Pythonwin/pywin/scintilla/document.py index f7f542d6c0..bf0a2f03be 100644 --- a/Pythonwin/pywin/scintilla/document.py +++ b/Pythonwin/pywin/scintilla/document.py @@ -37,7 +37,7 @@ def DeleteContents(self): def OnOpenDocument(self, filename): # init data members - # print "Opening", filename + # print("Opening", filename) self.SetPathName(filename) # Must set this early! try: # load the text as binary we can get smart diff --git a/Pythonwin/pywin/scintilla/formatter.py b/Pythonwin/pywin/scintilla/formatter.py index 0df8015366..0f91968fa1 100644 --- a/Pythonwin/pywin/scintilla/formatter.py +++ b/Pythonwin/pywin/scintilla/formatter.py @@ -142,7 +142,7 @@ def _ReformatStyle(self, style): return assert style.stylenum is not None, "Unregistered style." - # print "Reformat style", style.name, style.stylenum + # print("Reformat style", style.name, style.stylenum) scintilla = self.scintilla stylenum = style.stylenum # Now we have the style number, indirect for the actual style. @@ -252,7 +252,16 @@ def OnStyleNeeded(self, std, extra): endStyledChar = self.scintilla.SendScintilla(scintillacon.SCI_GETENDSTYLED) lineEndStyled = self.scintilla.LineFromChar(endStyledChar) endStyled = self.scintilla.LineIndex(lineEndStyled) - # print "enPosPaint %d endStyledChar %d lineEndStyled %d endStyled %d" % (endPosPaint, endStyledChar, lineEndStyled, endStyled) + # print( + # "endPosPaint", + # endPosPaint, + # "endStyledChar", + # endStyledChar, + # "lineEndStyled", + # lineEndStyled, + # "endStyled", + # endStyled, + # ) self.Colorize(endStyled, notify.position) def ColorSeg(self, start, end, styleName): diff --git a/Pythonwin/pywin/scintilla/view.py b/Pythonwin/pywin/scintilla/view.py index cf570ea1f2..d877bf3805 100644 --- a/Pythonwin/pywin/scintilla/view.py +++ b/Pythonwin/pywin/scintilla/view.py @@ -691,7 +691,16 @@ def _GetWordSplit(self, pos=-1, bAllowCalls=0): return "".join(before), "".join(after) def OnPrepareDC(self, dc, pInfo): - # print "OnPrepareDC for page", pInfo.GetCurPage(), "of", pInfo.GetFromPage(), "to", pInfo.GetToPage(), ", starts=", self.starts + # print( + # "OnPrepareDC for page", + # pInfo.GetCurPage(), + # "of", + # pInfo.GetFromPage(), + # "to", + # pInfo.GetToPage(), + # ", starts=", + # self.starts, + # ) if dc.IsPrinting(): # Check if we are beyond the end. # (only do this when actually printing, else messes up print preview!) @@ -779,7 +788,7 @@ def FormatRange(self, dc, pageStart, lengthDoc, rc, draw): def OnPrint(self, dc, pInfo): metrics = dc.GetTextMetrics() - # print "dev", w, h, l, metrics['tmAscent'], metrics['tmDescent'] + # print("dev", w, h, l, metrics["tmAscent"], metrics["tmDescent"]) if self.starts is None: self.CalculatePageRanges(dc, pInfo) pageNum = pInfo.GetCurPage() - 1 diff --git a/Pythonwin/pywin/tools/hierlist.py b/Pythonwin/pywin/tools/hierlist.py index cc76f1905a..495eea78f9 100644 --- a/Pythonwin/pywin/tools/hierlist.py +++ b/Pythonwin/pywin/tools/hierlist.py @@ -220,9 +220,9 @@ def Refresh(self, hparent=None): inewlook = inewlook + 1 if matched: # Insert the new items. - # print "Inserting after", old_items[iold], old_handles[iold] + # print("Inserting after", old_items[iold], old_handles[iold]) for i in range(inew, inewlook): - # print "Inserting index %d (%s)" % (i, new_items[i]) + # print(f"Inserting index {i} ({new_items[i]})") hAfter = self.AddItem(hparent, new_items[i], hAfter) inew = inewlook + 1 @@ -232,7 +232,7 @@ def Refresh(self, hparent=None): self.Refresh(hold) else: # Remove the deleted items. - # print "Deleting %d (%s)" % (iold, old_items[iold]) + # print(f"Deleting {iold} ({old_items[iold]})") hdelete = old_handles[iold] # First recurse and remove the children from the map. for hchild in self._GetChildHandles(hdelete): @@ -243,7 +243,7 @@ def Refresh(self, hparent=None): hAfter = old_handles[iold] # Fill any remaining new items: for newItem in new_items[inew:]: - # print "Inserting new item", newItem + # print("Inserting new item", newItem) self.AddItem(hparent, newItem) def AcceptRoot(self, root): diff --git a/Pythonwin/pywin/tools/regedit.py b/Pythonwin/pywin/tools/regedit.py index c62a029910..1f83213ec0 100644 --- a/Pythonwin/pywin/tools/regedit.py +++ b/Pythonwin/pywin/tools/regedit.py @@ -159,9 +159,9 @@ def SelectedItem(self): def SearchSelectedItem(self): handle = self.hierList.GetChildItem(0) while 1: - # print "State is", self.hierList.GetItemState(handle, -1) + # print("State is", self.hierList.GetItemState(handle, -1)) if self.hierList.GetItemState(handle, commctrl.TVIS_SELECTED): - # print "Item is ", self.hierList.ItemFromHandle(handle) + # print("Item is ", self.hierList.ItemFromHandle(handle)) return self.hierList.ItemFromHandle(handle) handle = self.hierList.GetNextSiblingItem(handle) diff --git a/Pythonwin/win32util.cpp b/Pythonwin/win32util.cpp index 294301f7d1..529aae5281 100644 --- a/Pythonwin/win32util.cpp +++ b/Pythonwin/win32util.cpp @@ -933,7 +933,7 @@ BOOL ParseCharFormatTuple(PyObject *args, CHARFORMAT *pFmt) // @tupleitem 6|int|bPitchAndFamily|The charset. See the LOGFONT structure for details. // @tupleitem 7|string|faceName|The font name. - // @comm Executing d=win32ui.CreateFontDialog(); d.DoModal(); print d.GetCharFormat() + // @comm Executing d=win32ui.CreateFontDialog(); d.DoModal(); print(d.GetCharFormat()) // will print a valid CHARFORMAT tuple. } diff --git a/SWIG/swig_lib/timers.i b/SWIG/swig_lib/timers.i index 35924ae56a..1d90e699d3 100644 --- a/SWIG/swig_lib/timers.i +++ b/SWIG/swig_lib/timers.i @@ -134,7 +134,7 @@ performance. To use a timer, simply use code like this : timer_start(0) ... a bunch of Python code ... timer_stop(0) - print timer_elapsed(0)," seconds of CPU time" + print(timer_elapsed(0), " seconds of CPU time") %} #endif diff --git a/adodbapi/__init__.py b/adodbapi/__init__.py index 428bdf432a..94a04bee36 100644 --- a/adodbapi/__init__.py +++ b/adodbapi/__init__.py @@ -3,6 +3,7 @@ Copyright (C) 2002 Henrik Ekelund, version 2.1 by Vernon Cole * http://sourceforge.net/projects/adodbapi """ + import time # Re-exports to keep backward compatibility with existing code diff --git a/adodbapi/adodbapi.py b/adodbapi/adodbapi.py index 36a2c88961..1dcca42c1f 100644 --- a/adodbapi/adodbapi.py +++ b/adodbapi/adodbapi.py @@ -91,7 +91,7 @@ def getIndexedValue(obj, index): from collections.abc import Mapping -# --- define objects to smooth out Python3000 <-> Python 2.x differences +# --- define objects to smooth out Python3000 <-> Python 2 differences unicodeType = str longType = int StringTypes = str diff --git a/adodbapi/apibase.py b/adodbapi/apibase.py index d16265917f..19ae54814e 100644 --- a/adodbapi/apibase.py +++ b/adodbapi/apibase.py @@ -26,7 +26,7 @@ DateTime = type(NotImplemented) # should never be seen on win32 NullTypes = type(None) -# --- define objects to smooth out Python3 <-> Python 2.x differences +# --- define objects to smooth out Python3 <-> Python 2 differences unicodeType = str longType = int StringTypes = str @@ -55,7 +55,7 @@ def standardErrorHandler(connection, cursor, errorclass, errorvalue): raise errorclass(errorvalue) -# Note: _BaseException is defined differently between Python 2.x and 3.x +# Note: _BaseException is defined differently between Python 2 and 3 class Error(_BaseException): pass # Exception that is the base class of all other error # exceptions. You can use this to catch all errors with one diff --git a/adodbapi/examples/db_table_names.py b/adodbapi/examples/db_table_names.py index 2d7bf9df0d..907bdb85ea 100644 --- a/adodbapi/examples/db_table_names.py +++ b/adodbapi/examples/db_table_names.py @@ -1,4 +1,5 @@ """ db_table_names.py -- a simple demo for ADO database table listing.""" + import sys import adodbapi diff --git a/adodbapi/is64bit.py b/adodbapi/is64bit.py index 911c61931e..36a8c63e48 100644 --- a/adodbapi/is64bit.py +++ b/adodbapi/is64bit.py @@ -1,4 +1,5 @@ """is64bit.Python() --> boolean value of detected Python word size. is64bit.os() --> os build version""" + import sys diff --git a/adodbapi/process_connect_string.py b/adodbapi/process_connect_string.py index 3c3f9e7afa..806c0954e8 100644 --- a/adodbapi/process_connect_string.py +++ b/adodbapi/process_connect_string.py @@ -1,4 +1,5 @@ """ a clumsy attempt at a macro language to let the programmer execute code on the server (ex: determine 64bit)""" + from . import is64bit as is64bit diff --git a/adodbapi/quick_reference.md b/adodbapi/quick_reference.md index e4bc9f9cfe..a61cf0a6a2 100644 --- a/adodbapi/quick_reference.md +++ b/adodbapi/quick_reference.md @@ -643,22 +643,22 @@ This is the PEP standard method: row = crsr.fetchone() while row: value = row[1] * row[2] - print('Your {:10s} is worth {:10.2f}'.format(row[0], value)) + print("Your {:10s} is worth {:10.2f}".format(row[0], value)) row = crsr.fetchone() # returns None when no data remains As an extension, a Row object can also be indexed by column name: crsr.execute("SELECT prodname, price, qtyonhand FROM cheese") for row in crsr: # note extension: using crsr as an iterator - value = row['price'] * row['qtyonhand'] - print('Your {:10s} is worth {:10.2f}'.format(row['prodname'], value)) + value = row["price"] * row["qtyonhand"] + print("Your {:10s} is worth {:10.2f}".format(row["prodname"], value)) But, _really_ lazy programmers, like me, use the column names as attributes: crsr.execute("SELECT prodname, price, qtyonhand FROM cheese") for row in crsr: value = row.price * row.qtyonhand - print('Your {:10s} is worth {:10.2f}'.format(row.prodname, value)) + print("Your {:10s} is worth {:10.2f}".format(row.prodname, value)) Now, isn't that easier to read and understand? diff --git a/adodbapi/remote.py b/adodbapi/remote.py index ae22b5a7ea..910c6b49a6 100644 --- a/adodbapi/remote.py +++ b/adodbapi/remote.py @@ -62,7 +62,7 @@ if verbose: print(version) -# --- define objects to smooth out Python3 <-> Python 2.x differences +# --- define objects to smooth out Python3 <-> Python 2 differences unicodeType = str # this line will be altered by 2to3.py to '= str' longType = int # this line will be altered by 2to3.py to '= int' StringTypes = str diff --git a/adodbapi/schema_table.py b/adodbapi/schema_table.py index 21ad37e31d..636766bba5 100644 --- a/adodbapi/schema_table.py +++ b/adodbapi/schema_table.py @@ -1,4 +1,5 @@ """call using an open ADO connection --> list of table names""" + from . import adodbapi diff --git a/adodbapi/setup.py b/adodbapi/setup.py index d25869adf9..51c999e5b4 100644 --- a/adodbapi/setup.py +++ b/adodbapi/setup.py @@ -3,6 +3,7 @@ Adodbapi can be run on CPython 3.5 and later. or IronPython version 2.6 and later (in theory, possibly no longer in practice!) """ + CLASSIFIERS = """\ Development Status :: 5 - Production/Stable Intended Audience :: Developers diff --git a/adodbapi/test/adodbapitest.py b/adodbapi/test/adodbapitest.py index d7a4f2c9bc..a5d4fce867 100644 --- a/adodbapi/test/adodbapitest.py +++ b/adodbapi/test/adodbapitest.py @@ -1,4 +1,5 @@ """ Unit tests version 2.6.1.0 for adodbapi""" + """ adodbapi - A python DB API 2.0 interface to Microsoft ADO @@ -251,9 +252,9 @@ def testUserDefinedConversionForExactNumericTypes(self): ) finally: # now reset the converter to its original function - adodbapi.variantConversions[ - ado_consts.adNumeric - ] = oldconverter # Restore the original convertion function + adodbapi.variantConversions[ado_consts.adNumeric] = ( + oldconverter # Restore the original convertion function + ) def helpTestDataType( self, @@ -1387,13 +1388,13 @@ def testOkConnect(self): assert c is not None # def testStoredProcedure(self): - # crsr=self.conn.cursor() + # crsr = self.conn.cursor() # try: # crsr.execute("DROP PROCEDURE DeleteMeOnlyForTesting") # self.conn.commit() - # except: #Make sure it is empty + # except: # Make sure it is empty # pass - # spdef= """ + # spdef = """ # DELIMITER $$ # CREATE PROCEDURE DeleteMeOnlyForTesting (onein CHAR(10), twoin CHAR(10), OUT theout CHAR(20)) # DETERMINISTIC @@ -1405,16 +1406,20 @@ def testOkConnect(self): # # crsr.execute(spdef) # - # retvalues=crsr.callproc('DeleteMeOnlyForTesting',('Dodsworth','Anne',' ')) - # print 'return value (mysql)=',repr(crsr.returnValue) ### - # assert retvalues[0]=='Dodsworth', '%s is not "Dodsworth"'%repr(retvalues[0]) - # assert retvalues[1]=='Anne','%s is not "Anne"'%repr(retvalues[1]) - # assert retvalues[2]=='DodsworthAnne','%s is not "DodsworthAnne"'%repr(retvalues[2]) + # retvalues = crsr.callproc( + # "DeleteMeOnlyForTesting", ("Dodsworth", "Anne", " ") + # ) + # print("return value (mysql)=", repr(crsr.returnValue)) + # assert retvalues[0] == "Dodsworth", '%s is not "Dodsworth"' % repr(retvalues[0]) + # assert retvalues[1] == "Anne", '%s is not "Anne"' % repr(retvalues[1]) + # assert retvalues[2] == "DodsworthAnne", '%s is not "DodsworthAnne"' % repr( + # retvalues[2] + # ) # # try: # crsr.execute("DROP PROCEDURE, DeleteMeOnlyForTesting") # self.conn.commit() - # except: #Make sure it is empty + # except: # Make sure it is empty # pass @@ -1453,8 +1458,8 @@ def testOkConnect(self): assert c is not None # def testStoredProcedure(self): - # crsr=self.conn.cursor() - # spdef= """ + # crsr = self.conn.cursor() + # spdef = """ # CREATE OR REPLACE FUNCTION DeleteMeOnlyForTesting (text, text) # RETURNS text AS $funk$ # BEGIN @@ -1463,18 +1468,22 @@ def testOkConnect(self): # $funk$ # LANGUAGE SQL; # """ - # + # crsr.execute(spdef) - # retvalues = crsr.callproc('DeleteMeOnlyForTesting',('Dodsworth','Anne',' ')) - # ### print 'return value (pg)=',repr(crsr.returnValue) ### - # assert retvalues[0]=='Dodsworth', '%s is not "Dodsworth"'%repr(retvalues[0]) - # assert retvalues[1]=='Anne','%s is not "Anne"'%repr(retvalues[1]) - # assert retvalues[2]=='Dodsworth Anne','%s is not "Dodsworth Anne"'%repr(retvalues[2]) + # retvalues = crsr.callproc( + # "DeleteMeOnlyForTesting", ("Dodsworth", "Anne", " ") + # ) + # # print("return value (pg)=", repr(crsr.returnValue)) + # assert retvalues[0] == "Dodsworth", '%s is not "Dodsworth"' % repr(retvalues[0]) + # assert retvalues[1] == "Anne", '%s is not "Anne"' % repr(retvalues[1]) + # assert retvalues[2] == "Dodsworth Anne", '%s is not "Dodsworth Anne"' % repr( + # retvalues[2] + # ) # self.conn.rollback() # try: # crsr.execute("DROP PROCEDURE, DeleteMeOnlyForTesting") # self.conn.commit() - # except: #Make sure it is empty + # except: # Make sure it is empty # pass diff --git a/adodbapi/test/dbapi20.py b/adodbapi/test/dbapi20.py index 5f983cdc8d..2cd8335776 100644 --- a/adodbapi/test/dbapi20.py +++ b/adodbapi/test/dbapi20.py @@ -18,13 +18,13 @@ import time import unittest -if sys.version[0] >= "3": # python 3.x +if sys.version[0] >= "3": # Python 3 _BaseException = Exception def _failUnless(self, expr, msg=None): self.assertTrue(expr, msg) -else: # python 2.x +else: # Python 2 from exceptions import Exception as _BaseException def _failUnless(self, expr, msg=None): diff --git a/adodbapi/test/is64bit.py b/adodbapi/test/is64bit.py index ed390fad00..33d0244302 100644 --- a/adodbapi/test/is64bit.py +++ b/adodbapi/test/is64bit.py @@ -1,4 +1,5 @@ """is64bit.Python() --> boolean value of detected Python word size. is64bit.os() --> os build version""" + import sys diff --git a/adodbapi/test/test_adodbapi_dbapi20.py b/adodbapi/test/test_adodbapi_dbapi20.py index 6115138336..ccf7e7cbf5 100644 --- a/adodbapi/test/test_adodbapi_dbapi20.py +++ b/adodbapi/test/test_adodbapi_dbapi20.py @@ -51,9 +51,9 @@ else: conn_kws["host"] = host -conn_kws[ - "provider" -] = "Provider=MSOLEDBSQL;DataTypeCompatibility=80;MARS Connection=True;" +conn_kws["provider"] = ( + "Provider=MSOLEDBSQL;DataTypeCompatibility=80;MARS Connection=True;" +) connStr = "%(provider)s; %(security)s; Initial Catalog=%(name)s;Data Source=%(host)s" if onWindows and node != "z-PC": @@ -108,7 +108,7 @@ def setUp(self): if self.getTestMethodName() == "test_callproc": con = self._connect() engine = con.dbms_name - ## print('Using database Engine=%s' % engine) ## + # print(f"Using database Engine={engine}") if engine != "MS Jet": sql = """ create procedure templower diff --git a/com/help/active_directory.html b/com/help/active_directory.html index d7764002ba..4b93d8b0a7 100644 --- a/com/help/active_directory.html +++ b/com/help/active_directory.html @@ -114,7 +114,7 @@
This then allows things like:
-print('The last name: ',opends('fred').sn) #sn =surname
+print("The last name: ",opends("fred").sn) #sn =surname
or to get the groups fred is a member of
-print("groups=',opends('fred').memberOf)
+print("groups=",opends("fred").memberOf)
def opends(loc,server=''):
@@ -189,23 +189,23 @@
What does the object have?
def ad_dict(ldapobj,attr_dict={},recurse=0,auth=1,filter=()):
if ldapobj.find(',')==-1: ldapobj='cn='+ldapobj+','+Ad.ldap_main_loc
if auth: #setup authenticated connections
- if debug: print 'auth'
+ if debug: print("auth")
adobj=opends(ldapobj)
- #if debug: print 'authenticated to',ldapobj
+ # if debug: print("authenticated to",ldapobj)
else:
adobj=win32com.client.GetObject('LDAP://'+ldapobj)
- if debug: print 'connected to',ldapobj
+ if debug: print("connected to",ldapobj)
if not(filter):
#check for children
for i in adobj:
- if debug: print '****at',i.cn,str(adobj.cn)
+ if debug: print("****at",i.cn,str(adobj.cn))
if recurse:
pass
#get children's attributes too
#attr_dict[i.distinguishedName]={}
#get_all(i.distinguishedName,attr_dict[i.distinguishedName],recurse,auth)
- if debug: print 'getting schema'
+ if debug: print("getting schema")
schema_obj=win32com.client.GetObject(adobj.schema)
for i in schema_obj.MandatoryProperties:
if i =='nTSecurityDescriptor':continue #takes a long time, skip it
@@ -246,7 +246,7 @@ The time property
user=opends('fred')
-print 'time in seconds',conv_time(user.pwdLastSet.lowpart,user.pwdLastSet.highpart)
+print("time in seconds",conv_time(user.pwdLastSet.lowpart,user.pwdLastSet.highpart))
user.pwdLastSet returns a com object, not a python data type.
diff --git a/com/help/adsi.html b/com/help/adsi.html
index 6fd2ab119e..d97b0d6838 100644
--- a/com/help/adsi.html
+++ b/com/help/adsi.html
@@ -152,7 +152,7 @@ Getting/Modify user info
myDSObject.Getinfo()
# To access a user's data try:
attribute = myDSObject.Get('Extension-Attribute-1')
-print attribute
+print(attribute)
# To modify a user try:
myDSObject.Put('Extension-Attribute-1','barney was here')
myDSObject.Setinfo()
@@ -188,7 +188,7 @@ Deleting a user from exchange
dsobj.Delete("OrganizationalPerson", "cn="+login)
dsobj.Setinfo()
except:
- print 'Error deleting '+login, sys.exc_type , sys.exc_value
+ print("Error deleting "+login, sys.exc_type , sys.exc_value)
Example
o = win32com.client.Dispatch("Excel.Application")
o.Visible = 1
-o.Workbooks.Add() # for office 97 – 95 a bit different!
+o.Workbooks.Add() # for office 97 – 95 a bit different!
o.Cells(1,1).Value = "Hello"
And we will see the word "Hello" appear in the top cell.
This is obviously a very simple server. In particular, custom error handling would be needed for a production class server. In addition, there are some contrived properties just for demonstration purposes.
At this stage, Python and Unicode don’t really work well together. All strings which come from COM will actually be Unicode objects rather than string objects.
+At this stage, Python and Unicode don’t really work well together. All strings which come from COM will actually be Unicode objects rather than string objects.
To make this code work in a COM environment, the last line of the "Hello" method must become:
_public_attrs_ = ['softspace', 'noCalls']
_readonly_attrs_ = ['noCalls']
def __init__(self):
-[Same from here…]
[Same from here…]
Microsoft Visual C++ comes with various tools for generating CLSID's, which are quite suitable. Alternatively, the pythoncom module exports the function CreateGuid() to generate these identifiers.
>>> import pythoncom
->>> print pythoncom.CreateGuid()
+>>> print(pythoncom.CreateGuid())
{7CC9F362-486D-11D1-BB48-0000E838A65F}
Obviously the GUID that you get will be different than that displayed here.
The default policy object has a few special attributes that define who the object is exposed to COM. The example above shows the _public_methods attribute, but this section describes all such attributes in detail.
Required list of strings, containing the names of all methods to be exposed to COM. It is possible this will be enhanced in the future (eg, possibly '*' will be recognised to say all methods, or some other ideas…)
+Required list of strings, containing the names of all methods to be exposed to COM. It is possible this will be enhanced in the future (eg, possibly '*' will be recognised to say all methods, or some other ideas…)
Optional list of strings containing all attribute names to be exposed, both for reading and writing. The attribute names must be valid instance variables.
Optional list of strings defining the name of attributes exposed read-only.
Optional list of IIDs exposed by this object. If this attribute is missing, IID_IDispatch is assumed (ie, if not supplied, the COM object will be created as a normal Automation object.
+Optional list of IIDs exposed by this object. If this attribute is missing, IID_IDispatch is assumed (ie, if not supplied, the COM object will be created as a normal Automation object).
and actual instance attributes:
_dynamic_ : optional method
_value_ : optional attribute
diff --git a/com/win32com/client/CLSIDToClass.py b/com/win32com/client/CLSIDToClass.py index fde3274332..88b742e0ac 100644 --- a/com/win32com/client/CLSIDToClass.py +++ b/com/win32com/client/CLSIDToClass.py @@ -16,6 +16,7 @@ This obviously applies to all cooperating objects, not just DAO and Access. """ + mapCLSIDToClass = {} diff --git a/com/win32com/client/__init__.py b/com/win32com/client/__init__.py index 6f8ad07088..36f2c1d778 100644 --- a/com/win32com/client/__init__.py +++ b/com/win32com/client/__init__.py @@ -303,7 +303,7 @@ class object that derives from three classes: >>> class IEEvents: ... def OnVisible(self, visible): - ... print "Visible changed:", visible + ... print("Visible changed:", visible) ... >>> ie = DispatchWithEvents("InternetExplorer.Application", IEEvents) >>> ie.Visible = 1 @@ -358,7 +358,7 @@ def WithEvents(disp, user_event_class): >>> class IEEvents: ... def OnVisible(self, visible): - ... print "Visible changed:", visible + ... print("Visible changed:", visible) ... >>> ie = Dispatch("InternetExplorer.Application") >>> ie_events = WithEvents(ie, IEEvents) @@ -437,7 +437,7 @@ def getevents(clsid): >>> >>> class InternetExplorerEvents(win32com.client.getevents("InternetExplorer.Application.1")): ... def OnVisible(self, Visible): - ... print "Visibility changed: ", Visible + ... print("Visibility changed: ", Visible) ... >>> >>> ie=win32com.client.Dispatch("InternetExplorer.Application.1") diff --git a/com/win32com/client/build.py b/com/win32com/client/build.py index 1035ecdff9..8318b88949 100644 --- a/com/win32com/client/build.py +++ b/com/win32com/client/build.py @@ -69,9 +69,7 @@ class NotSupportedException(Exception): pythoncom.VT_VOID, ] -NoTranslateMap = {} -for v in NoTranslateTypes: - NoTranslateMap[v] = None +NoTranslateMap = set(NoTranslateTypes) class MapEntry: diff --git a/com/win32com/client/combrowse.py b/com/win32com/client/combrowse.py index 18576251ee..a5e76a85ba 100644 --- a/com/win32com/client/combrowse.py +++ b/com/win32com/client/combrowse.py @@ -22,6 +22,7 @@ work. """ + import sys import pythoncom diff --git a/com/win32com/client/connect.py b/com/win32com/client/connect.py index 24788204ec..7cb3969464 100644 --- a/com/win32com/client/connect.py +++ b/com/win32com/client/connect.py @@ -1,4 +1,5 @@ """Utilities for working with Connections""" + import pythoncom import win32com.server.util diff --git a/com/win32com/client/dynamic.py b/com/win32com/client/dynamic.py index dc938e8cbe..51d4702f8a 100644 --- a/com/win32com/client/dynamic.py +++ b/com/win32com/client/dynamic.py @@ -15,6 +15,7 @@ >>> xl.Visible = 1 # The Excel window becomes visible. """ + import traceback import types @@ -234,7 +235,7 @@ def __repr__(self): return "Win32 username is "+win32api.GetUserName()) <% import sys -print sys.path +print(sys.path) from win32com.axscript.asputil import * -print "Hello" -print "There" -print "How are you" +print("Hello") +print("There") +print("How are you") %> <%bc = Server.CreateObject("MSWC.BrowserType")%> diff --git a/com/win32comext/axscript/demos/client/ie/CHARTPY.HTM b/com/win32comext/axscript/demos/client/ie/CHARTPY.HTM index 4bba12c19e..fe7d1b5fbd 100644 --- a/com/win32comext/axscript/demos/client/ie/CHARTPY.HTM +++ b/com/win32comext/axscript/demos/client/ie/CHARTPY.HTM @@ -75,7 +75,7 @@ def DoChartType(WhatType): # Turns horizontal gridlines on or off depending on value of chkHorizontal checkbox def DoHorizontalGrid(): - print ax.chkHorizontal.Checked + print(ax.chkHorizontal.Checked) if ax.chkHorizontal.Checked: ax.Chart1.HGridStyle = 1 else: diff --git a/com/win32comext/axscript/demos/client/ie/FOO.HTM b/com/win32comext/axscript/demos/client/ie/FOO.HTM index 840672ff9c..34a880fa8d 100644 --- a/com/win32comext/axscript/demos/client/ie/FOO.HTM +++ b/com/win32comext/axscript/demos/client/ie/FOO.HTM @@ -39,7 +39,7 @@ End Sub