From 1f0f8b5d9fcaec23538de3c53af4683783ebff9a Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 10 Aug 2023 17:36:09 -0400 Subject: [PATCH] Fix plenty of undefined names --- Pythonwin/pywin/Demos/fontdemo.py | 2 +- Pythonwin/pywin/debugger/__init__.py | 6 ------ Pythonwin/pywin/framework/dlgappcore.py | 4 +++- Pythonwin/pywin/framework/interact.py | 2 +- Pythonwin/pywin/framework/mdi_pychecker.py | 1 + Pythonwin/pywin/scintilla/configui.py | 4 ++-- Pythonwin/pywin/tools/TraceCollector.py | 10 +++++----- com/win32com/readme.html | 2 +- com/win32com/server/dispatcher.py | 3 ++- com/win32com/server/exception.py | 2 +- com/win32com/test/daodump.py | 1 + com/win32com/test/testClipboard.py | 3 +-- com/win32com/test/testGatewayAddresses.py | 2 +- com/win32com/test/testvb.py | 1 + com/win32comext/adsi/demos/test.py | 1 + com/win32comext/axdebug/Test/host.py | 13 +++++++------ com/win32comext/axdebug/codecontainer.py | 1 + com/win32comext/axdebug/expressions.py | 4 ++-- com/win32comext/axscript/client/pydumper.py | 14 ++++++++------ .../shell/demos/servers/context_menu.py | 2 +- com/win32comext/shell/demos/servers/shell_view.py | 2 +- isapi/install.py | 4 ++-- pywin32_postinstall.py | 1 + win32/Lib/win32rcparser.py | 1 - win32/Lib/winnt.py | 4 ++-- win32/scripts/VersionStamp/BrandProject.py | 7 +++---- win32/scripts/backupEventLog.py | 2 +- win32/scripts/ce/pysynch.py | 1 + win32/scripts/rasutil.py | 1 + win32/test/test_win32api.py | 1 + win32/test/test_win32wnet.py | 4 ++-- 31 files changed, 56 insertions(+), 50 deletions(-) diff --git a/Pythonwin/pywin/Demos/fontdemo.py b/Pythonwin/pywin/Demos/fontdemo.py index fc35f4ca38..68c353cb21 100644 --- a/Pythonwin/pywin/Demos/fontdemo.py +++ b/Pythonwin/pywin/Demos/fontdemo.py @@ -43,7 +43,7 @@ def SetFont(self, new_font): # Change font on the fly self.font = win32ui.CreateFont(new_font) # redraw the entire client window - selfInvalidateRect(None) + self.InvalidateRect(None) def OnSize(self, params): lParam = params[3] diff --git a/Pythonwin/pywin/debugger/__init__.py b/Pythonwin/pywin/debugger/__init__.py index 31bb76b59c..6a6b65da7f 100644 --- a/Pythonwin/pywin/debugger/__init__.py +++ b/Pythonwin/pywin/debugger/__init__.py @@ -1,11 +1,5 @@ import sys - -# Some cruft to deal with the Pythonwin GUI booting up from a non GUI app. -def _MakeDebuggerGUI(): - app.InitInstance() - - isInprocApp = -1 diff --git a/Pythonwin/pywin/framework/dlgappcore.py b/Pythonwin/pywin/framework/dlgappcore.py index 4b60cc1c0a..df6169cd36 100644 --- a/Pythonwin/pywin/framework/dlgappcore.py +++ b/Pythonwin/pywin/framework/dlgappcore.py @@ -27,12 +27,14 @@ def OnInitDialog(self): def OnPaint(self): if not self.IsIconic(): return self._obj_.OnPaint() + dc, paintStruct = self.BeginPaint() self.DefWindowProc(win32con.WM_ICONERASEBKGND, dc.GetHandleOutput(), 0) left, top, right, bottom = self.GetClientRect() left = (right - win32api.GetSystemMetrics(win32con.SM_CXICON)) >> 1 top = (bottom - win32api.GetSystemMetrics(win32con.SM_CYICON)) >> 1 hIcon = win32ui.GetApp().LoadIcon(self.iconId) - self.GetDC().DrawIcon((left, top), hIcon) + dc.DrawIcon((left, top), hIcon) + self.EndPaint(paintStruct) # Only needed to provide a minimized icon (and this seems # less important under win95/NT4 diff --git a/Pythonwin/pywin/framework/interact.py b/Pythonwin/pywin/framework/interact.py index ed3a7e0820..1b2ec8b64a 100644 --- a/Pythonwin/pywin/framework/interact.py +++ b/Pythonwin/pywin/framework/interact.py @@ -332,7 +332,7 @@ def Init(self): % (win32ui.copyright,) ) else: - sys.stderr.write(banner) + sys.stderr.write(self.banner) rcfile = os.environ.get("PYTHONSTARTUP") if rcfile: import __main__ diff --git a/Pythonwin/pywin/framework/mdi_pychecker.py b/Pythonwin/pywin/framework/mdi_pychecker.py index 06fbcc82b0..37986d3a0b 100644 --- a/Pythonwin/pywin/framework/mdi_pychecker.py +++ b/Pythonwin/pywin/framework/mdi_pychecker.py @@ -38,6 +38,7 @@ import re import sys import time +from functools import reduce import win32api import win32con diff --git a/Pythonwin/pywin/scintilla/configui.py b/Pythonwin/pywin/scintilla/configui.py index 8b6157b604..1c48c6cf65 100644 --- a/Pythonwin/pywin/scintilla/configui.py +++ b/Pythonwin/pywin/scintilla/configui.py @@ -286,7 +286,7 @@ def OnOK(self): def test(): - page = ColorEditorPropertyPage() - sheet = pywin.mfc.dialog.PropertySheet("Test") + page = ScintillaFormatPropertyPage() + sheet = dialog.PropertySheet("Test") sheet.AddPage(page) sheet.CreateWindow() diff --git a/Pythonwin/pywin/tools/TraceCollector.py b/Pythonwin/pywin/tools/TraceCollector.py index 5800488b91..093ecf133d 100644 --- a/Pythonwin/pywin/tools/TraceCollector.py +++ b/Pythonwin/pywin/tools/TraceCollector.py @@ -49,11 +49,11 @@ def _StopThread(self): def Close(self): self._StopThread() winout.WindowOutput.Close(self) - # def OnViewDestroy(self, frame): - # return winout.WindowOutput.OnViewDestroy(self, frame) - # def Create(self, title=None, style = None): - # rc = winout.WindowOutput.Create(self, title, style) - return rc + # def OnViewDestroy(self, frame): + # return winout.WindowOutput.OnViewDestroy(self, frame) + # def Create(self, title=None, style = None): + # rc = winout.WindowOutput.Create(self, title, style) + # return rc def MakeOutputWindow(): diff --git a/com/win32com/readme.html b/com/win32com/readme.html index 3df753404d..57146ec62a 100644 --- a/com/win32com/readme.html +++ b/com/win32com/readme.html @@ -36,7 +36,7 @@

VARIANT objects

Up until build 212, code could set pythoncom.__future_currency__ = True to force use of the decimal module, with a warning issued otherwise. In builds 213 and later, the decimal module is unconditionally used when -pythoncon returns you a currency value. +pythoncom returns you a currency value.

Recent Changes

diff --git a/com/win32com/server/dispatcher.py b/com/win32com/server/dispatcher.py index 71b91e7a59..46184727e9 100644 --- a/com/win32com/server/dispatcher.py +++ b/com/win32com/server/dispatcher.py @@ -6,6 +6,8 @@ from sys import exc_info import pythoncom +import pywin.debugger +import pywin.debugger.dbgcon import win32api import win32com from win32com.server.exception import IsCOMServerException @@ -255,7 +257,6 @@ def _HandleException_(self): """Invoke the debugger post mortem capability""" # Save details away. typ, val, tb = exc_info() - # import pywin.debugger, pywin.debugger.dbgcon debug = 0 try: raise typ(val) diff --git a/com/win32com/server/exception.py b/com/win32com/server/exception.py index e7f4d08060..25496556ae 100644 --- a/com/win32com/server/exception.py +++ b/com/win32com/server/exception.py @@ -93,7 +93,7 @@ def IsCOMException(t=None): try: return issubclass(t, pythoncom.com_error) except TypeError: # 1.5 in -X mode? - return t is pythoncon.com_error + return t is pythoncom.com_error def IsCOMServerException(t=None): diff --git a/com/win32com/test/daodump.py b/com/win32com/test/daodump.py index c222087a51..1cf7be302f 100644 --- a/com/win32com/test/daodump.py +++ b/com/win32com/test/daodump.py @@ -1,6 +1,7 @@ # import dao3032 # No longer imported here - callers responsibility to load # +import pythoncom import win32com.client diff --git a/com/win32com/test/testClipboard.py b/com/win32com/test/testClipboard.py index 60df8668b8..bf55b7b869 100644 --- a/com/win32com/test/testClipboard.py +++ b/com/win32com/test/testClipboard.py @@ -68,8 +68,7 @@ def QueryGetData(self, fe): return None # should check better def GetCanonicalFormatEtc(self, fe): - RaiseCOMException(winerror.DATA_S_SAMEFORMATETC) - # return fe + raise COMException(winerror.DATA_S_SAMEFORMATETC) def SetData(self, fe, medium): raise COMException(hresult=winerror.E_NOTIMPL) diff --git a/com/win32com/test/testGatewayAddresses.py b/com/win32com/test/testGatewayAddresses.py index d489916992..65d959f36a 100644 --- a/com/win32com/test/testGatewayAddresses.py +++ b/com/win32com/test/testGatewayAddresses.py @@ -76,7 +76,7 @@ class Dummy2: ] -class DeletgatedDummy: +class DelegatedDummy: _public_methods_ = [] diff --git a/com/win32com/test/testvb.py b/com/win32com/test/testvb.py index c82b4e73fb..2de76b2053 100644 --- a/com/win32com/test/testvb.py +++ b/com/win32com/test/testvb.py @@ -4,6 +4,7 @@ # import traceback +from collections.abc import Callable import pythoncom import win32com.client diff --git a/com/win32comext/adsi/demos/test.py b/com/win32comext/adsi/demos/test.py index d5b8fde98e..392701ce49 100644 --- a/com/win32comext/adsi/demos/test.py +++ b/com/win32comext/adsi/demos/test.py @@ -1,5 +1,6 @@ import string import sys +from collections.abc import Callable import pythoncom import win32api diff --git a/com/win32comext/axdebug/Test/host.py b/com/win32comext/axdebug/Test/host.py index 7704f4fb17..7b42cc3d40 100644 --- a/com/win32comext/axdebug/Test/host.py +++ b/com/win32comext/axdebug/Test/host.py @@ -2,6 +2,7 @@ import traceback import pythoncom +import ttest import win32api import win32com.server.util import winerror @@ -97,12 +98,12 @@ 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") @@ -171,15 +172,15 @@ def TestSmartProvider(): def test(): try: - # app = TestSmartHelper() + # app = TestSmartHelper() app = TestSmartProvider() - # app = testdumb() + # app = testdumb() except: traceback.print_exc() -# _wrap_remove(externalConnectionManager) -# wrappedExternalConnectionManager = None +# _wrap_remove(externalConnectionManager) +# wrappedExternalConnectionManager = None if __name__ == "__main__": test() diff --git a/com/win32comext/axdebug/codecontainer.py b/com/win32comext/axdebug/codecontainer.py index 44c5f0e797..8b920b47a8 100644 --- a/com/win32comext/axdebug/codecontainer.py +++ b/com/win32comext/axdebug/codecontainer.py @@ -4,6 +4,7 @@ to color the text, and also how to translate lines into offsets, and back. """ +import os import sys import tokenize diff --git a/com/win32comext/axdebug/expressions.py b/com/win32comext/axdebug/expressions.py index 28c7b90457..57157b2ac5 100644 --- a/com/win32comext/axdebug/expressions.py +++ b/com/win32comext/axdebug/expressions.py @@ -188,8 +188,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/axscript/client/pydumper.py b/com/win32comext/axscript/client/pydumper.py index 3d0725aeff..8414609a73 100644 --- a/com/win32comext/axscript/client/pydumper.py +++ b/com/win32comext/axscript/client/pydumper.py @@ -13,6 +13,10 @@ # as a scripting language - meaning the dumps produced can be quite dynamic, # and based on the script code you execute. +import sys + +import win32api +import win32con from win32com.axscript import axscript from . import pyscript @@ -34,8 +38,6 @@ class PyScript(pyscript.PyScript): def Register(): - import sys - if "-d" in sys.argv: dispatcher = "DispatcherWin32trace" debug_desc = " (" + dispatcher + ")" @@ -51,7 +53,7 @@ def Register(): policy = None # "win32com.axscript.client.axspolicy.AXScriptPolicy" print("Registering COM server%s..." % debug_desc) - from win32com.server.register import RegisterServer + from win32com.server.register import RegisterServer, _set_string languageName = "PyDump" verProgId = "Python.Dumper.1" @@ -66,10 +68,10 @@ def Register(): dispatcher=dispatcher, ) - CreateRegKey(languageName + "\\OLEScript") + win32api.RegCreateKey(win32con.HKEY_CLASSES_ROOT, languageName + "\\OLEScript") # Basic Registration for wsh. - win32com.server.register._set_string(".pysDump", "pysDumpFile") - win32com.server.register._set_string("pysDumpFile\\ScriptEngine", languageName) + _set_string(".pysDump", "pysDumpFile") + _set_string("pysDumpFile\\ScriptEngine", languageName) print("Dumping Server registered.") diff --git a/com/win32comext/shell/demos/servers/context_menu.py b/com/win32comext/shell/demos/servers/context_menu.py index b92109d738..1947d7d76a 100644 --- a/com/win32comext/shell/demos/servers/context_menu.py +++ b/com/win32comext/shell/demos/servers/context_menu.py @@ -49,7 +49,7 @@ def QueryContextMenu(self, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags): elif uFlags & shellcon.CMF_EXPLORE: print("CMF_EXPLORE...") items.append(msg + " - normal file, right-click in Explorer") - elif uFlags & CMF_DEFAULTONLY: + elif uFlags & shellcon.CMF_DEFAULTONLY: print("CMF_DEFAULTONLY...\r\n") else: print("** unknown flags", uFlags) diff --git a/com/win32comext/shell/demos/servers/shell_view.py b/com/win32comext/shell/demos/servers/shell_view.py index 29b66ac573..1a4dc23eab 100644 --- a/com/win32comext/shell/demos/servers/shell_view.py +++ b/com/win32comext/shell/demos/servers/shell_view.py @@ -849,7 +849,7 @@ def CreateViewWindow(self, prev, settings, browser, rect): } # win32gui.SetWindowLong(self.hwnd, win32con.GWL_WNDPROC, message_map) - file_data = file(self.filename, "U").read() + file_data = open(self.filename, "U").read() self._SetupLexer() self._SendSci(scintillacon.SCI_ADDTEXT, len(file_data), file_data) diff --git a/isapi/install.py b/isapi/install.py index 154f82aff3..84c0be9f5a 100644 --- a/isapi/install.py +++ b/isapi/install.py @@ -209,8 +209,8 @@ def GetWebServer(description=None): def LoadWebServer(path): try: server = GetObject(path) - except pythoncom.com_error as details: - msg = details.strerror + except pythoncom.com_error as exc: + msg = exc.strerror if exc.excepinfo and exc.excepinfo[2]: msg = exc.excepinfo[2] msg = "WebServer %s: %s" % (path, msg) diff --git a/pywin32_postinstall.py b/pywin32_postinstall.py index 5b6a6da749..508ef74909 100644 --- a/pywin32_postinstall.py +++ b/pywin32_postinstall.py @@ -2,6 +2,7 @@ # # copies PyWinTypesxx.dll and PythonCOMxx.dll into the system directory, # and creates a pth file +import argparse import glob import os import shutil diff --git a/win32/Lib/win32rcparser.py b/win32/Lib/win32rcparser.py index 1d90bfd717..d2cf8543f0 100644 --- a/win32/Lib/win32rcparser.py +++ b/win32/Lib/win32rcparser.py @@ -605,7 +605,6 @@ def Parse(rc_name, h_name=None): if h_file is not None: h_file.close() rc_file.close() - return rcp def GenerateFrozenResource(rc_name, output_name, h_name=None): diff --git a/win32/Lib/winnt.py b/win32/Lib/winnt.py index a88627e0fd..b19fcd002b 100644 --- a/win32/Lib/winnt.py +++ b/win32/Lib/winnt.py @@ -905,11 +905,11 @@ def DECREF(x): IMAGE_ORDINAL_FLAG = -2147483648 -def IMAGE_SNAP_BY_ORDINAL(Ordina): +def IMAGE_SNAP_BY_ORDINAL(Ordinal): return (Ordinal & IMAGE_ORDINAL_FLAG) != 0 -def IMAGE_ORDINAL(Ordina): +def IMAGE_ORDINAL(Ordinal): return Ordinal & 65535 diff --git a/win32/scripts/VersionStamp/BrandProject.py b/win32/scripts/VersionStamp/BrandProject.py index cc78d8d91f..7338ad08ac 100644 --- a/win32/scripts/VersionStamp/BrandProject.py +++ b/win32/scripts/VersionStamp/BrandProject.py @@ -3,6 +3,7 @@ # Brand a VSS project with a "build number", then optionally # stamp DLL/EXE files with version information. +import getopt import os import string import sys @@ -33,7 +34,7 @@ def BrandProject( bulkstamp.scan(build, stampPath, descFile) for infile, outfile in filesToSubstitute: - SubstituteVSSInFile(vssProjectName, infile, outfile) + vssutil.SubstituteVSSInFile(vssProjectName, infile, outfile) return 1 @@ -65,10 +66,8 @@ def usage(msg): if __name__ == "__main__": try: - import getopt - opts, args = getopt.getopt(sys.argv[1:], "af:d:r") - except getopts.error as msg: + except getopt.error as msg: usage(msg) bAuto = bRebrand = 0 stampFiles = [] diff --git a/win32/scripts/backupEventLog.py b/win32/scripts/backupEventLog.py index bc7d53fec5..d20ca303d8 100644 --- a/win32/scripts/backupEventLog.py +++ b/win32/scripts/backupEventLog.py @@ -27,7 +27,7 @@ def BackupClearLog(logType): # OK - have unique file name. try: hlog = win32evtlog.OpenEventLog(None, logType) - except win32evtlogutil.error as details: + except win32evtlog.error as details: print("Could not open the event log", details) return try: diff --git a/win32/scripts/ce/pysynch.py b/win32/scripts/ce/pysynch.py index c3054f0e2e..ba8673b6d9 100644 --- a/win32/scripts/ce/pysynch.py +++ b/win32/scripts/ce/pysynch.py @@ -5,6 +5,7 @@ import os import string import sys +from collections.abc import Callable import win32api import win32con diff --git a/win32/scripts/rasutil.py b/win32/scripts/rasutil.py index 3c13d49682..1819a79b01 100644 --- a/win32/scripts/rasutil.py +++ b/win32/scripts/rasutil.py @@ -1,6 +1,7 @@ # A demo of using the RAS API from Python import sys +import win32api import win32ras diff --git a/win32/test/test_win32api.py b/win32/test/test_win32api.py index 81b2fe5ef9..5a3b474bc4 100644 --- a/win32/test/test_win32api.py +++ b/win32/test/test_win32api.py @@ -4,6 +4,7 @@ import os import sys import tempfile +import time import unittest import win32api diff --git a/win32/test/test_win32wnet.py b/win32/test/test_win32wnet.py index 316c2e29dd..1cdf0224bd 100644 --- a/win32/test/test_win32wnet.py +++ b/win32/test/test_win32wnet.py @@ -108,7 +108,7 @@ def testNetbios(self): ncb.Reset() ncb.Command = netbios.NCBRESET ncb.Lana_num = la_enum.lana[i] - rc = Netbios(ncb) + rc = win32wnet.Netbios(ncb) self.assertEqual(rc, 0) ncb.Reset() ncb.Command = netbios.NCBASTAT @@ -116,7 +116,7 @@ def testNetbios(self): ncb.Callname = b"* " adapter = netbios.ADAPTER_STATUS() ncb.Buffer = adapter - Netbios(ncb) + win32wnet.Netbios(ncb) # expect 6 bytes in the mac address. self.assertTrue(len(adapter.adapter_address), 6)