diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index db40b4254..88e5ae6ca 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -143,7 +143,7 @@ jobs: cache: pip cache-dependency-path: .github/workflows/main.yml check-latest: true - - run: pip install types-regex types-setuptools PyOpenGL mypy==1.11 + - run: pip install types-setuptools PyOpenGL mypy==1.11 - run: mypy . --python-version=${{ matrix.python-version }} pyright: @@ -162,7 +162,7 @@ jobs: cache-dependency-path: .github/workflows/main.yml check-latest: true # pyright vendors typeshed, but let's make sure we have the most up to date stubs - - run: pip install types-regex types-setuptools PyOpenGL + - run: pip install types-setuptools PyOpenGL - uses: jakebailey/pyright-action@v2 with: python-version: ${{ matrix.python-version }} diff --git a/AutoDuck/makedfromi.py b/AutoDuck/makedfromi.py index a975031e1..ff9431de1 100644 --- a/AutoDuck/makedfromi.py +++ b/AutoDuck/makedfromi.py @@ -20,7 +20,7 @@ def GetComments(line, lineNo, lines): if len(data) != 2: break if data[0].strip(): - break # Not a continutation! + break # Not a continuation! if data[1].strip().startswith("@"): # new command break diff --git a/AutoDuck/py2d.py b/AutoDuck/py2d.py index 647fb7121..2b2d779b8 100644 --- a/AutoDuck/py2d.py +++ b/AutoDuck/py2d.py @@ -75,7 +75,7 @@ def format_desc(desc): # 'first_para_of_docstring' # '@comm next para of docstring' # '@comm next para of docstring' ... etc - # BUT - also handling enbedded doctests, where we write + # BUT - also handling embedded doctests, where we write # '@iex >>> etc.' if not desc: return "" diff --git a/CHANGES.txt b/CHANGES.txt index 82cf59213..83ca2052e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,8 @@ https://mhammond.github.io/pywin32_installers.html. Coming in build 309, as yet unreleased -------------------------------------- +* Fixed Pythonwin's editor failing due to invalid regex import (#2419, @Avasam) +* Last error wrongly set by some modules (#2302, @CristiFati) * Dropped support for Python 3.7 (#2207, @Avasam) * Implement the creation of SAFEARRAY(VT_RECORD) from a sequence of COM Records (#2317, @geppi) * Implement record pointers as [in, out] method parameters of a Dispatch Interface (#2304, #2310, @geppi) @@ -68,7 +70,7 @@ as the .chm file, certain MAPI libraries etc, and .exe installers. * `win32com.client.build.error` * `win32com.client.genpy.error` * Add EnumDesktopWindows (#2219, @CristiFati) -* Marked `exc_type` and `exc_traceback` in `win32comext.axscript.client.error.AXScriptException.__init__` as deprecated. (#2236 , @Avasam) +* Marked `exc_type` and `exc_traceback` in `win32comext.axscript.client.error.AXScriptException.__init__` as deprecated. (#2236, @Avasam) They are now unused and all information is taken from the `exc_value` parameter. * Fixed non-overriden `pywin.scintilla.formatter.Formatter.ColorizeString` raising `TypeError` instead of `RuntimeError` due to too many parameters (#2216, @Avasam) * Fixed broken since Python 3 tokenization in `win32comext.axdebug.codecontainer.pySourceCodeContainer.GetSyntaxColorAttributes` (#2216, @Avasam) @@ -189,7 +191,7 @@ as the .chm file, certain MAPI libraries etc, and .exe installers. * Use byte-string (`b""`) for constant bytes values instead of superfluous `.encode` calls (#2046, @Avasam) * Cleaned up unused imports (#1986, #2051, #1990, #2124, #2126, @Avasam) * Removed duplicated declarations, constants and definitions (#2050, #1950, #1990, @Avasam) -* Small generalized optimization by using augmented assignements (in-place operators) where possible (#2274, @Avasam) +* Small generalized optimization by using augmented assignments (in-place operators) where possible (#2274, @Avasam) * General speed and size improvements due to all the removed code. (#2046, #1986, #2050, #1950, #2085, #2087, #2051, #1990, #2106, #2127, #2124, #2126, #2177, #2218, #2202, #2205, #2217) ### adodbapi diff --git a/Pythonwin/contents.d b/Pythonwin/contents.d index 86101de59..581380465 100644 --- a/Pythonwin/contents.d +++ b/Pythonwin/contents.d @@ -119,7 +119,7 @@ it uses overrides the default. Thus, regardless of your preferences, if the fir indent in the file is a tab, Pythonwin uses tabs for the entire file (and similarly, uses spaces if the first block is indented with spaces) -Things can appear to get wierd when editing a file with mixed tabs and spaces. +Things can appear to get weird when editing a file with mixed tabs and spaces. Although mixed tabs and spaces in the same indent is evil, there are a number of source files that have certain classes/functions indented with spaces, and others that use tabs. The editor will not correctly adjust to the current block - whatever diff --git a/Pythonwin/pythondoc.h b/Pythonwin/pythondoc.h index d0c2811d2..fb5f4b13c 100644 --- a/Pythonwin/pythondoc.h +++ b/Pythonwin/pythondoc.h @@ -112,7 +112,7 @@ BOOL CPythonDocTemp

::OnSaveDocument(const TCHAR *fileName) // @pyparm string|fileName||The name of the file being saved. // @xref // @comm If a handler is defined for this function, the base (MFC) function will not - // be called. If necessary, the handler must call this function explicitely. + // be called. If necessary, the handler must call this function explicitly. CVirtualHelper helper("OnSaveDocument", this); if (helper.call(fileName)) { int ret; @@ -131,7 +131,7 @@ BOOL CPythonDocTemp

::OnOpenDocument(const TCHAR *fileName) // @pyvirtual int|PyCDocument|OnOpenDocument|Called by the MFC architecture. // @xref // @comm If a handler is defined for this function, the base (MFC) function will not - // be called. If necessary, the handler must call this function explicitely. + // be called. If necessary, the handler must call this function explicitly. CVirtualHelper helper("OnOpenDocument", this); if (!helper.HaveHandler()) { PyErr_SetString(ui_module_error, "PyCDocument::OnOpenDocument handler does not exist."); @@ -155,7 +155,7 @@ BOOL CPythonDocTemp

::OnNewDocument() // @pyvirtual int|PyCDocument|OnNewDocument|Called by the MFC architecture. // @xref // @comm If a handler is defined for this function, the base (MFC) function will not - // be called. If necessary, the handler must call this function explicitely. + // be called. If necessary, the handler must call this function explicitly. CVirtualHelper helper("OnNewDocument", this); if (!helper.HaveHandler()) { helper.release_full(); @@ -182,7 +182,7 @@ void CPythonDocTemp

::OnCloseDocument() // @pyvirtual |PyCDocument|OnCloseDocument|Called by the MFC architecture. // @xref // @comm If a handler is defined for this function, the base (MFC) function will not - // be called. If necessary, the handler must call this function explicitely. + // be called. If necessary, the handler must call this function explicitly. CVirtualHelper helper("OnCloseDocument", this); if (helper.HaveHandler()) { helper.call(); @@ -215,7 +215,7 @@ void CPythonDocTemp

::DeleteContents() P::DeleteContents(); } // @comm If a handler is defined for this function, the base (MFC) function will not - // be called. If necessary, the handler must call this function explicitely. + // be called. If necessary, the handler must call this function explicitly. } template BOOL CPythonDocTemp

::SaveModified() @@ -223,7 +223,7 @@ BOOL CPythonDocTemp

::SaveModified() // @pyvirtual int|PyCDocument|SaveModified|Called by the MFC architecture when a document is closed. // @xref // @comm If a handler is defined for this function, the base (MFC) function will not - // be called. If necessary, the handler must call this function explicitely. + // be called. If necessary, the handler must call this function explicitly. CVirtualHelper helper("SaveModified", this); if (!helper.HaveHandler()) { helper.release_full(); @@ -244,7 +244,7 @@ void CPythonDocTemp

::OnChangedViewList() // @pyvirtual int|PyCDocument|OnChangedViewList|Called by the MFC architecture when after a view is attached. // @xref // @comm If a handler is defined for this function, the base (MFC) function will not - // be called. If necessary, the handler must call this function explicitely. + // be called. If necessary, the handler must call this function explicitly. CVirtualHelper helper("OnChangedViewList", this); if (helper.HaveHandler() && helper.call()) { return; diff --git a/Pythonwin/pywin/debugger/fail.py b/Pythonwin/pywin/debugger/fail.py index dbb5320ae..0afc70eb3 100644 --- a/Pythonwin/pywin/debugger/fail.py +++ b/Pythonwin/pywin/debugger/fail.py @@ -28,7 +28,7 @@ def b(): b = 1 pywin.debugger.set_trace() # After importing or running this module, you are likely to be - # sitting at the next line. This is because we explicitely + # sitting at the next line. This is because we explicitly # broke into the debugger using the "set_trace() function # "pywin.debugger.brk()" is a shorter alias for this. c() diff --git a/Pythonwin/pywin/framework/editor/editor.py b/Pythonwin/pywin/framework/editor/editor.py index da8106015..061809e3a 100644 --- a/Pythonwin/pywin/framework/editor/editor.py +++ b/Pythonwin/pywin/framework/editor/editor.py @@ -9,7 +9,7 @@ # We now support reloading of externally modified documented # (eg, presumably by some other process, such as source control or # another editor. -# We also suport auto-loading of externally modified files. +# We also support auto-loading of externally modified files. # - if the current document has not been modified in this # editor, but has been modified on disk, then the file # can be automatically reloaded. @@ -19,7 +19,6 @@ import re -import regex import win32api import win32con import win32ui @@ -36,8 +35,8 @@ # 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]\)") +patImport = re.compile(r"import (?P.*)") +patIndent = re.compile(r"^([ \t]*[~ \t])") ID_LOCATE_FILE = 0xE200 ID_GOTO_LINE = 0xE2001 @@ -364,9 +363,10 @@ def OnRClick(self, params): # look for a module name line = self._obj_.GetLine().strip() flags = win32con.MF_STRING | win32con.MF_ENABLED - if patImport.match(line) == len(line): + matchResult = patImport.match(line) + if matchResult and matchResult[0] == line: menu.AppendMenu( - flags, ID_LOCATE_FILE, "&Locate {}.py".format(patImport.group("name")) + flags, ID_LOCATE_FILE, f"&Locate {matchResult.group('name')}.py" ) menu.AppendMenu(win32con.MF_SEPARATOR) menu.AppendMenu(flags, win32ui.ID_EDIT_UNDO, "&Undo") diff --git a/Pythonwin/pywin/framework/editor/vss.py b/Pythonwin/pywin/framework/editor/vss.py index 29046d2fb..10b691e80 100644 --- a/Pythonwin/pywin/framework/editor/vss.py +++ b/Pythonwin/pywin/framework/editor/vss.py @@ -86,7 +86,7 @@ def CheckoutFile(fileName): project, vssFname, database = rc if g_sourceSafe is None: g_sourceSafe = win32com.client.Dispatch("SourceSafe") - # SS seems a bit wierd. It defaults the arguments as empty strings, but + # SS seems a bit weird. It defaults the arguments as empty strings, but # then complains when they are used - so we pass "Missing" if not database: database = pythoncom.Missing diff --git a/Pythonwin/pywin/framework/intpyapp.py b/Pythonwin/pywin/framework/intpyapp.py index 9172284ec..9cf8f6a43 100644 --- a/Pythonwin/pywin/framework/intpyapp.py +++ b/Pythonwin/pywin/framework/intpyapp.py @@ -473,7 +473,7 @@ def OnFileLocate(self, id, code): else: win32ui.GetApp().OpenDocumentFile(newName) - # Display all the "options" proprety pages we can find + # Display all the "options" property pages we can find def OnViewOptions(self, id, code): win32ui.InitRichEdit() sheet = dialog.PropertySheet("Pythonwin Options") diff --git a/Pythonwin/pywin/framework/mdi_pychecker.py b/Pythonwin/pywin/framework/mdi_pychecker.py index 28ea04742..c31b50da8 100644 --- a/Pythonwin/pywin/framework/mdi_pychecker.py +++ b/Pythonwin/pywin/framework/mdi_pychecker.py @@ -147,8 +147,7 @@ def __radd__(self, other): # Group(1) is the filename, group(2) is the lineno. -# regexGrepResult=regex.compile(r"^\([a-zA-Z]:.*\)(\([0-9]+\))") -# regexGrep=re.compile(r"^([a-zA-Z]:[^(]*)\((\d+)\)") +# regexGrep = re.compile(r"^([a-zA-Z]:[^(]*)\((\d+)\)") regexGrep = re.compile(r"^(..[^\(:]+)?[\(:](\d+)[\):]:?\s*(.*)") # these are the atom numbers defined by Windows for basic dialog controls diff --git a/Pythonwin/pywin/framework/sgrepmdi.py b/Pythonwin/pywin/framework/sgrepmdi.py index e8b37a518..6c10a617b 100644 --- a/Pythonwin/pywin/framework/sgrepmdi.py +++ b/Pythonwin/pywin/framework/sgrepmdi.py @@ -129,8 +129,6 @@ def __radd__(self, other): # Group(1) is the filename, group(2) is the lineno. -# regexGrepResult=regex.compile(r"^\([a-zA-Z]:.*\)(\([0-9]+\))") - regexGrep = re.compile(r"^([a-zA-Z]:[^(]*)\(([0-9]+)\)") # these are the atom numbers defined by Windows for basic dialog controls diff --git a/Pythonwin/pywin/framework/startup.py b/Pythonwin/pywin/framework/startup.py index 3cc6c0169..ca7a44d87 100644 --- a/Pythonwin/pywin/framework/startup.py +++ b/Pythonwin/pywin/framework/startup.py @@ -50,7 +50,7 @@ pywin.__path__[0] = win32ui.FullPath(pywin.__path__[0]) pywin.framework.__path__[0] = win32ui.FullPath(pywin.framework.__path__[0]) -# make a few wierd sys values. This is so later we can clobber sys.argv to trick +# make a few weird sys values. This is so later we can clobber sys.argv to trick # scripts when running under a GUI environment. moduleName = "pywin.framework.intpyapp" diff --git a/Pythonwin/pywin/scintilla/keycodes.py b/Pythonwin/pywin/scintilla/keycodes.py index d94ccda47..12867080a 100644 --- a/Pythonwin/pywin/scintilla/keycodes.py +++ b/Pythonwin/pywin/scintilla/keycodes.py @@ -70,7 +70,7 @@ def get_vk(chardesc): def parse_key_name(name): - name += "-" # Add a sentinal + name += "-" # Add a sentinel start = pos = 0 max = len(name) toks = [] diff --git a/Pythonwin/pywin/scintilla/view.py b/Pythonwin/pywin/scintilla/view.py index f2b83065a..f5148113d 100644 --- a/Pythonwin/pywin/scintilla/view.py +++ b/Pythonwin/pywin/scintilla/view.py @@ -749,7 +749,7 @@ def CalculatePageRanges(self, dc, pInfo): pageStart = self.FormatRange(dc, pageStart, textLen, rc, 0) maxPage += 1 self.starts[maxPage] = pageStart - # And a sentinal for one page past the end + # And a sentinel for one page past the end self.starts[maxPage + 1] = textLen # When actually printing, maxPage doesn't have any effect at this late state. # but is needed to make the Print Preview work correctly. diff --git a/Pythonwin/win32bitmap.cpp b/Pythonwin/win32bitmap.cpp index 157457063..0422fbf75 100644 --- a/Pythonwin/win32bitmap.cpp +++ b/Pythonwin/win32bitmap.cpp @@ -210,7 +210,7 @@ PyObject *ui_bitmap_load_bitmap_file(PyObject *self, PyObject *args) return NULL; } */ - /* Attempt to load wierd bitmap format. + /* Attempt to load weird bitmap format. if (bmFileHeader.bfOffBits) { PyObject *args = Py_BuildValue("(i)", bmFileHeader.bfOffBits); result = gui_call_object(seeker, args); diff --git a/Pythonwin/win32dlg.cpp b/Pythonwin/win32dlg.cpp index 598aae410..6a0e2fecb 100644 --- a/Pythonwin/win32dlg.cpp +++ b/Pythonwin/win32dlg.cpp @@ -162,7 +162,7 @@ PyCDialog::~PyCDialog() GlobalFree(hSaved); } - ui_assoc_object::SetAssocInvalid(); // must call this explicitely, as I ignore SetAssocInvalid + ui_assoc_object::SetAssocInvalid(); // must call this explicitly, as I ignore SetAssocInvalid Py_XDECREF(ddlist); // we can not have the pointer deleted at window destruction time // for a dialog (as MFC still needs it after the dialog has completed BOOL bManDeleteSave = bManualDelete; diff --git a/Pythonwin/win32virt.cpp b/Pythonwin/win32virt.cpp index 5d049fbf3..a53aa58a8 100644 --- a/Pythonwin/win32virt.cpp +++ b/Pythonwin/win32virt.cpp @@ -42,7 +42,7 @@ CVirtualHelper::CVirtualHelper(const char *iname, void *iassoc, EnumVirtualError PyErr_Fetch(&t, &v, &tb); handler = PyObject_GetAttrString(py_bob->virtualInst, (char *)iname); if (handler) { - // explicitely check a method returned, else the classes + // explicitly check a method returned, else the classes // delegation may cause a circular call chain. if (!PyMethod_Check(handler)) { if (!PyCFunction_Check(handler)) { diff --git a/adodbapi/adodbapi.py b/adodbapi/adodbapi.py index b63b829d8..19adbfb30 100644 --- a/adodbapi/adodbapi.py +++ b/adodbapi/adodbapi.py @@ -66,7 +66,7 @@ def getIndexedValue(obj, index): def make_COM_connecter(): try: pythoncom.CoInitialize() # v2.1 Paj - c = Dispatch("ADODB.Connection") # connect _after_ CoIninialize v2.1.1 adamvan + c = Dispatch("ADODB.Connection") # connect _after_ CoInitialize v2.1.1 adamvan except: raise api.InterfaceError( "Windows COM Error: Dispatch('ADODB.Connection') failed." @@ -593,7 +593,7 @@ def _raiseCursorError(self, errorclass, errorvalue): eh(self.connection, self, errorclass, errorvalue) def build_column_info(self, recordset): - self.converters = [] # convertion function for each column + self.converters = [] # conversion function for each column self.columnNames = {} # names of columns {lowercase name : number,...} self._description = None diff --git a/adodbapi/readme.txt b/adodbapi/readme.txt index 00f76f7c2..877c400cb 100644 --- a/adodbapi/readme.txt +++ b/adodbapi/readme.txt @@ -34,7 +34,7 @@ Try: or: adodbapi.apibase.variantConversions[adodbapi.ado_consts.adNumeric] = adodbapi.apibase.cvtFloat or: - adodbapi.apibase.variantConversions[adodbapi.ado_consts.adNumeric] = write_your_own_convertion_function + adodbapi.apibase.variantConversions[adodbapi.ado_consts.adNumeric] = write_your_own_conversion_function ............ notes for 2.6.2: The definitive source has been moved to https://github.com/mhammond/pywin32/tree/master/adodbapi. diff --git a/adodbapi/test/adodbapitest.py b/adodbapi/test/adodbapitest.py index dd8e9196d..88dab1267 100644 --- a/adodbapi/test/adodbapitest.py +++ b/adodbapi/test/adodbapitest.py @@ -213,7 +213,7 @@ def testUserDefinedConversionForExactNumericTypes(self): # now return strings adodbapi.variantConversions[ado_consts.adNumeric] = adodbapi.cvtString self.helpTestDataType("numeric(18,2)", "NUMBER", "3.45") - # now a completly weird user defined convertion + # now a completely weird user defined conversion adodbapi.variantConversions[ado_consts.adNumeric] = ( lambda x: "!!This function returns a funny unicode string %s!!" % x ) @@ -228,7 +228,7 @@ def testUserDefinedConversionForExactNumericTypes(self): finally: # now reset the converter to its original function adodbapi.variantConversions[ado_consts.adNumeric] = ( - oldconverter # Restore the original convertion function + oldconverter # Restore the original conversion function ) def helpTestDataType( diff --git a/adodbapi/test/dbapi20.py b/adodbapi/test/dbapi20.py index 373b984d6..ea920d42b 100644 --- a/adodbapi/test/dbapi20.py +++ b/adodbapi/test/dbapi20.py @@ -71,7 +71,7 @@ # - Now a subclass of TestCase, to avoid requiring the driver stub # to use multiple inheritance # - Reversed the polarity of buggy test in test_description -# - Test exception heirarchy correctly +# - Test exception hierarchy correctly # - self.populate is now self._populate(), so if a driver stub # overrides self.ddl1 this change propogates # - VARCHAR columns now have a width, which will hopefully make the @@ -198,7 +198,7 @@ def test_paramstyle(self): def test_Exceptions(self): # Make sure required exceptions exist, and are in the - # defined heirarchy. + # defined hierarchy. if sys.version[0] == "3": # under Python 3 StardardError no longer exists self.assertTrue(issubclass(self.driver.Warning, Exception)) self.assertTrue(issubclass(self.driver.Error, Exception)) diff --git a/adodbapi/test/setuptestframework.py b/adodbapi/test/setuptestframework.py index e09549421..4b9de6a7d 100644 --- a/adodbapi/test/setuptestframework.py +++ b/adodbapi/test/setuptestframework.py @@ -56,7 +56,7 @@ def makeadopackage(testfolder): shutil.copy(os.path.join(adoPath, f), newpackage) return testfolder else: - raise OSError("Connot find source of adodbapi to test.") + raise OSError("Cannot find source of adodbapi to test.") def makemdb(testfolder, mdb_name): diff --git a/build_env.md b/build_env.md index 4f616bf99..7e166c4d9 100644 --- a/build_env.md +++ b/build_env.md @@ -117,7 +117,7 @@ where mc ``` (Note that the above process for 'mc' doesn't appear necessary for VS2017, but -markh hasn't tried with VS2019 - please share your experiences!) +@mhammond hasn't tried with VS2019 - please share your experiences!) # Build diff --git a/com/changes.txt b/com/changes.txt index f94adde87..27e387a8c 100644 --- a/com/changes.txt +++ b/com/changes.txt @@ -110,7 +110,7 @@ Dec 1, 96 win32com.pythoncom works (and is the "official" way!). - Connection point support added. makepy will now generate code suitable to be used as an OCX, or as a connection point sink. - Slightly wierd connection point demo (client and server!) is in demos\connect.py + Slightly weird connection point demo (client and server!) is in demos\connect.py Note - All old OCX code will be broken. You must regenerate all .py files, AND CHANGE ALL SUPPORT CODE (sorry!). Specifically, the name of the class you should sub-class from will have changed - it diff --git a/com/win32com/changes.txt b/com/win32com/changes.txt index 3b3a0588e..57734d924 100644 --- a/com/win32com/changes.txt +++ b/com/win32com/changes.txt @@ -113,7 +113,7 @@ Dec 1, 96 win32com.pythoncom works (and is the "official" way!). - Connection point support added. makepy will now generate code suitable to be used as an OCX, or as a connection point sink. - Slightly wierd connection point demo (client and server!) is in demos\connect.py + Slightly weird connection point demo (client and server!) is in demos\connect.py Note - All old OCX code will be broken. You must regenerate all .py files, AND CHANGE ALL SUPPORT CODE (sorry!). Specifically, the name of the class you should sub-class from will have changed - it diff --git a/com/win32com/server/policy.py b/com/win32com/server/policy.py index 0c1f92427..f4593b4b9 100644 --- a/com/win32com/server/policy.py +++ b/com/win32com/server/policy.py @@ -321,7 +321,7 @@ def _getidsofnames_(self, names, lcid): # IDispatchEx support for policies. Most of the IDispathEx functionality # by default will raise E_NOTIMPL. Thus it is not necessary for derived - # policies to explicitely implement all this functionality just to not implement it! + # policies to explicitly implement all this functionality just to not implement it! def _GetDispID_(self, name, fdex): return self._getdispid_(name, fdex) diff --git a/com/win32com/server/register.py b/com/win32com/server/register.py index 9b233f66e..73021ae25 100644 --- a/com/win32com/server/register.py +++ b/com/win32com/server/register.py @@ -448,7 +448,7 @@ def RegisterClasses(*classes, **flags): win32api.FindFiles(sys.argv[0])[0][8] )[0] except (IndexError, win32api.error): - # Can't find the script file - the user must explicitely set the _reg_... attribute. + # Can't find the script file - the user must explicitly set the _reg_... attribute. raise TypeError( "Can't locate the script hosting the COM object - please set _reg_class_spec_ in your object" ) diff --git a/com/win32com/src/dllmain.cpp b/com/win32com/src/dllmain.cpp index bac646ece..de857ed84 100644 --- a/com/win32com/src/dllmain.cpp +++ b/com/win32com/src/dllmain.cpp @@ -156,7 +156,7 @@ typedef HRESULT(WINAPI *PFNCoInitializeEx)(LPVOID pvReserved, DWORD dwCoInit); // particular about the order of shutdown - in MAPI's case, you MUST // do the CoUninit _before_ the MAPIUninit. // These functions have logic so the Python programmer can call either -// the Init for Term function explicitely, and the framework will detect +// the Init for Term function explicitly, and the framework will detect // it no longer needs doing. // XXX - Needs more thought about threading implications. HRESULT PyCom_CoInitializeEx(LPVOID reserved, DWORD dwInit) diff --git a/com/win32com/src/univgw_dataconv.cpp b/com/win32com/src/univgw_dataconv.cpp index 23107d01d..520adb66b 100644 --- a/com/win32com/src/univgw_dataconv.cpp +++ b/com/win32com/src/univgw_dataconv.cpp @@ -702,7 +702,7 @@ PyObject *dataconv_ReadFromInTuple(PyObject *self, PyObject *args) default: obArg = NULL; PyErr_SetString(PyExc_TypeError, "Unknown/bad type description type!"); - // barf here, we don't wtf they were thinking... + // barf here, we don't know wtf they were thinking... break; } // switch } // if ARRAY diff --git a/com/win32comext/axdebug/documents.py b/com/win32comext/axdebug/documents.py index eb45517e7..723d2bf13 100644 --- a/com/win32comext/axdebug/documents.py +++ b/com/win32comext/axdebug/documents.py @@ -105,7 +105,7 @@ class CodeContainerProvider: Given a Python file name (as the debugger knows it by) this will return a CodeContainer interface suitable for use. - This provides a simple base imlpementation that simply supports + This provides a simple base implementation that simply supports a dictionary of nodes and providers. """ diff --git a/com/win32comext/axscript/client/pyscript.py b/com/win32comext/axscript/client/pyscript.py index 3da66a345..9831fdcd1 100644 --- a/com/win32comext/axscript/client/pyscript.py +++ b/com/win32comext/axscript/client/pyscript.py @@ -100,7 +100,7 @@ def _FindAttribute_(self, attr): class NamedScriptAttribute: - "An explicitely named object in an objects namespace" + "An explicitly named object in an objects namespace" # Each named object holds a reference to one of these. # Whenever a sub-item appears in a namespace, it is really one of these diff --git a/com/win32comext/axscript/demos/client/ie/demo_intro.htm b/com/win32comext/axscript/demos/client/ie/demo_intro.htm index 9987d8972..c02be1a6e 100644 --- a/com/win32comext/axscript/demos/client/ie/demo_intro.htm +++ b/com/win32comext/axscript/demos/client/ie/demo_intro.htm @@ -30,7 +30,7 @@

Known bugs and problems

  • Builtin objects such as MARQUEE are giving me grief. Objects accessed via forms are generally no problem.

  • If you are trying to use Python with the Windows Scripting Host, note that -.pys files are not correct registered - you will need to explicitely +.pys files are not correct registered - you will need to explicitly specify either cscript.exe or wscript.exe on the command line. diff --git a/com/win32comext/bits/src/bits.cpp b/com/win32comext/bits/src/bits.cpp index f92868f55..6b973f893 100755 --- a/com/win32comext/bits/src/bits.cpp +++ b/com/win32comext/bits/src/bits.cpp @@ -30,7 +30,7 @@ void PyObject_FreeBG_FILE_RANGE_LIST(DWORD num, BG_FILE_RANGE *fr) {} PyObject *PyObject_FromBG_FILE_PROGRESS(BG_FILE_PROGRESS *fp) { - // @object PyObject_FromBG_FILE_PROGRESS|A tuple of 3 elements (bytesTotal, bytesTransfered, completed), (int, int, + // @object PyObject_FromBG_FILE_PROGRESS|A tuple of 3 elements (bytesTotal, bytesTransferred, completed), (int, int, // bool) return Py_BuildValue("NNO", PyLong_FromLongLong(fp->BytesTotal), PyLong_FromLongLong(fp->BytesTransferred), fp->Completed ? Py_True : Py_False); @@ -38,14 +38,14 @@ PyObject *PyObject_FromBG_FILE_PROGRESS(BG_FILE_PROGRESS *fp) PyObject *PyObject_FromBG_JOB_PROGRESS(BG_JOB_PROGRESS *jp) { - // @object PyObject_FromBG_JOB_PROGRESS|A tuple of 4 elements (bytesTotal, bytesTransfered, filesTotal, - // filesTransfered), all ints. + // @object PyObject_FromBG_JOB_PROGRESS|A tuple of 4 elements (bytesTotal, bytesTransferred, filesTotal, + // filesTransferred), all ints. return Py_BuildValue("NNkk", PyLong_FromLongLong(jp->BytesTotal), PyLong_FromLongLong(jp->BytesTransferred), jp->FilesTotal, jp->FilesTransferred); } PyObject *PyObject_FromBG_JOB_REPLY_PROGRESS(BG_JOB_REPLY_PROGRESS *jrs) { - // @object BG_JOB_REPLY_PROGRESS|A tuple of 2 elements (bytesTotal, bytesTransfered), both ints. + // @object BG_JOB_REPLY_PROGRESS|A tuple of 2 elements (bytesTotal, bytesTransferred), both ints. return Py_BuildValue("NN", PyLong_FromLongLong(jrs->BytesTotal), PyLong_FromLongLong(jrs->BytesTransferred)); } diff --git a/com/win32comext/shell/demos/servers/folder_view.py b/com/win32comext/shell/demos/servers/folder_view.py index f2d039a15..f00e383cc 100644 --- a/com/win32comext/shell/demos/servers/folder_view.py +++ b/com/win32comext/shell/demos/servers/folder_view.py @@ -529,7 +529,7 @@ def QueryContextMenu(self, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags): def InvokeCommand(self, ci): mask, hwnd, verb, params, dir, nShow, hotkey, hicon = ci - # this seems very convuluted, but it's what the sample does :) + # this seems very convoluted, but it's what the sample does :) for verb_name, verb_id, flag in folderViewImplContextMenuIDs: if isinstance(verb, int): matches = verb == verb_id diff --git a/com/win32comext/shell/src/PyIShellItem2.cpp b/com/win32comext/shell/src/PyIShellItem2.cpp index eb0c1cdcf..9637882cc 100644 --- a/com/win32comext/shell/src/PyIShellItem2.cpp +++ b/com/win32comext/shell/src/PyIShellItem2.cpp @@ -485,7 +485,7 @@ STDMETHODIMP PyGShellItem2::GetProperty( PyObject *result; /* ??? Something strange with the format: If passing only a single object, and it's a tuple, - and you don't explicitely add the parens, + and you don't explicitly add the parens, the tuple gets unpacked and passed as separate args ??? */ HRESULT hr = InvokeViaPolicy("GetProperty", &result, "(N)", PyObject_FromSHCOLUMNID(&key)); diff --git a/win32/Demos/security/set_file_audit.py b/win32/Demos/security/set_file_audit.py index 324d72748..e46d05d77 100644 --- a/win32/Demos/security/set_file_audit.py +++ b/win32/Demos/security/set_file_audit.py @@ -59,7 +59,7 @@ win32con.GENERIC_ALL, my_sid, ) -## keep dir from inheriting any permissions so it only has ACEs explicitely set here +## keep dir from inheriting any permissions so it only has ACEs explicitly set here win32security.SetNamedSecurityInfo( dir_name, SE_FILE_OBJECT, diff --git a/win32/Lib/pywin32_testutil.py b/win32/Lib/pywin32_testutil.py index d9e517913..e2b1b8b3a 100644 --- a/win32/Lib/pywin32_testutil.py +++ b/win32/Lib/pywin32_testutil.py @@ -273,7 +273,7 @@ def _makeResult(self): return TestResult(self.stream, self.descriptions, self.verbosity) -# TestProgream subclass necessary just to get our TestRunner hooked up, +# TestProgram subclass necessary just to get our TestRunner hooked up, # which is necessary to get our TestResult hooked up *sob* class TestProgram(unittest.TestProgram): def runTests(self): @@ -282,7 +282,7 @@ def runTests(self): unittest.TestProgram.runTests(self) -# A convenient entry-point - if used, 'SKIPPED' exceptions will be supressed. +# A convenient entry-point - if used, 'SKIPPED' exceptions will be suppressed. def testmain(*args, **kw): new_kw = kw.copy() if "testLoader" not in new_kw: diff --git a/win32/Lib/win32cryptcon.py b/win32/Lib/win32cryptcon.py index 8d71996a0..92aac96eb 100644 --- a/win32/Lib/win32cryptcon.py +++ b/win32/Lib/win32cryptcon.py @@ -972,7 +972,7 @@ def GET_CMSG_ENCODING_TYPE(X): CMC_FAIL_BAD_REQUEST = 2 CMC_FAIL_BAD_TIME = 3 CMC_FAIL_BAD_CERT_ID = 4 -CMC_FAIL_UNSUPORTED_EXT = 5 +CMC_FAIL_UNSUPORTED_EXT = 5 # Yes Microsoft made a typo in "UNSUPPORTED" CMC_FAIL_MUST_ARCHIVE_KEYS = 6 CMC_FAIL_BAD_IDENTITY = 7 CMC_FAIL_POP_REQUIRED = 8 diff --git a/win32/Lib/win32pdhquery.py b/win32/Lib/win32pdhquery.py index 7a8a71ee5..b083968ec 100644 --- a/win32/Lib/win32pdhquery.py +++ b/win32/Lib/win32pdhquery.py @@ -504,10 +504,10 @@ def collectdatafor(self, totalperiod, period=1): def collectdatawhile(self, period=1): """ Threaded collection of performance data: - This method sets up a simple semaphor system for signalling + This method sets up a simple semaphore system for signalling when you would like to start and stop a threaded data collection method. The collection runs every period seconds until the - semaphor attribute is set to a non-true value (which normally + semaphore attribute is set to a non-true value (which normally should be done by calling query.collectdatawhile_stop() .) e.g.: query.collectdatawhile(2) diff --git a/win32/Lib/win32timezone.py b/win32/Lib/win32timezone.py index fdd71c855..01aa08d79 100644 --- a/win32/Lib/win32timezone.py +++ b/win32/Lib/win32timezone.py @@ -463,7 +463,7 @@ def _locate_day(year, cutoff): """ # MS stores Sunday as 0, Python datetime stores Monday as zero target_weekday = (cutoff.day_of_week + 6) % 7 - # For SYSTEMTIMEs relating to time zone inforamtion, cutoff.day + # For SYSTEMTIMEs relating to time zone information, cutoff.day # is the week of the month week_of_month = cutoff.day # so the following is the first day of that week diff --git a/win32/scripts/regsetup.py b/win32/scripts/regsetup.py index c6467b158..ef118f296 100644 --- a/win32/scripts/regsetup.py +++ b/win32/scripts/regsetup.py @@ -498,9 +498,9 @@ def RegisterShellInfo(searchPaths): # 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:\weird\spot\1 c:\weird\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, +as well as the 2 weird spots to locate the core Python files (eg, Python.exe, pythonXX.dll, the standard library and Win32 Extensions). "regsetup -a myappname . .\subdir" diff --git a/win32/src/PySECURITY_DESCRIPTOR.cpp b/win32/src/PySECURITY_DESCRIPTOR.cpp index 4ad9aa1d0..f21cfaae7 100644 --- a/win32/src/PySECURITY_DESCRIPTOR.cpp +++ b/win32/src/PySECURITY_DESCRIPTOR.cpp @@ -451,7 +451,7 @@ PyObject *PySECURITY_DESCRIPTOR::GetSecurityDescriptorOwner(PyObject *self, PyOb PyObject *PySECURITY_DESCRIPTOR::SetSecurityDescriptorOwner(PyObject *self, PyObject *args) { // @pyparm |sid||The sid to be set as owner in the security descriptor. - // @pyparm int|bOwnerDefaulted||Normally set to false since this explicitely set the owner. + // @pyparm int|bOwnerDefaulted||Normally set to false since this explicitly set the owner. BOOL bOwnerDefaulted; PySECURITY_DESCRIPTOR *This = (PySECURITY_DESCRIPTOR *)self; PSID NewOwnerSid = NULL; @@ -494,7 +494,7 @@ PyObject *PySECURITY_DESCRIPTOR::SetSecurityDescriptorOwner(PyObject *self, PyOb PyObject *PySECURITY_DESCRIPTOR::SetSecurityDescriptorGroup(PyObject *self, PyObject *args) { // @pyparm |sid||The group sid to be set in the security descriptor. - // @pyparm int|bOwnerDefaulted||Normally set to false since this explicitely set the owner. + // @pyparm int|bOwnerDefaulted||Normally set to false since this explicitly set the owner. BOOL bGroupDefaulted; PySECURITY_DESCRIPTOR *This = (PySECURITY_DESCRIPTOR *)self; PSECURITY_DESCRIPTOR psd = NULL; diff --git a/win32/src/PyWinTypes.h b/win32/src/PyWinTypes.h index 620aada9c..cd0fe7bdb 100644 --- a/win32/src/PyWinTypes.h +++ b/win32/src/PyWinTypes.h @@ -83,6 +83,8 @@ typedef Py_ssize_t Py_hash_t; #endif // _MSC_VER #endif // BUILD_PYWINTYPES +extern PYWINTYPES_EXPORT HMODULE PyWin_GetOrLoadLibraryHandle(const char *name); + // Py3k uses memoryview object in place of buffer, and we don't yet. extern PYWINTYPES_EXPORT PyObject *PyBuffer_New(Py_ssize_t size); extern PYWINTYPES_EXPORT PyObject *PyBuffer_FromMemory(void *buf, Py_ssize_t size); diff --git a/win32/src/PyWinTypesmodule.cpp b/win32/src/PyWinTypesmodule.cpp index 1564f84d5..e095fdf93 100644 --- a/win32/src/PyWinTypesmodule.cpp +++ b/win32/src/PyWinTypesmodule.cpp @@ -26,6 +26,17 @@ extern PyObject *PyWinMethod_NewHKEY(PyObject *self, PyObject *args); extern BOOL _PyWinDateTime_Init(); extern BOOL _PyWinDateTime_PrepareModuleDict(PyObject *dict); +HMODULE PyWin_GetOrLoadLibraryHandle(const char *name) +{ + DWORD lastErr = GetLastError(); + HMODULE hmodule = GetModuleHandleA(name); + if (hmodule == NULL) + hmodule = LoadLibraryA(name); + if (hmodule != NULL) + SetLastError(lastErr); + return hmodule; +} + // XXX - Needs py3k modernization! // For py3k, a function that returns new memoryview object instead of buffer. // ??? Byte array object is mutable, maybe just use that directly as a substitute ??? @@ -970,10 +981,8 @@ extern "C" __declspec(dllexport) BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwR { FARPROC fp; // dll usually will already be loaded - HMODULE hmodule = GetModuleHandle(_T("AdvAPI32.dll")); - if (hmodule == NULL) - hmodule = LoadLibrary(_T("AdvAPI32.dll")); - if (hmodule) { + HMODULE hmodule = PyWin_GetOrLoadLibraryHandle("advapi32.dll"); + if (hmodule != NULL) { fp = GetProcAddress(hmodule, "AddAccessAllowedAce"); if (fp) addaccessallowedace = (addacefunc)(fp); diff --git a/win32/src/PythonService.cpp b/win32/src/PythonService.cpp index 181c97b50..c6d8e1364 100644 --- a/win32/src/PythonService.cpp +++ b/win32/src/PythonService.cpp @@ -92,7 +92,7 @@ typedef struct { DWORD g_serviceProcessFlags = 0; // The global SCM dispatch table. A trailing NULL indicates to the SCM -// how many are used, so we allocate one extra for this sentinal +// how many are used, so we allocate one extra for this sentinel static SERVICE_TABLE_ENTRY DispatchTable[MAX_SERVICES + 1] = {{NULL, NULL}}; // A parallel array of Python information for the service. static PY_SERVICE_TABLE_ENTRY PythonServiceTable[MAX_SERVICES]; diff --git a/win32/src/win32apimodule.cpp b/win32/src/win32apimodule.cpp index 026816e69..45d8d532e 100644 --- a/win32/src/win32apimodule.cpp +++ b/win32/src/win32apimodule.cpp @@ -4772,14 +4772,12 @@ static PyObject *PySetSystemTime(PyObject *self, PyObject *args) )) return NULL; PyW32_BEGIN_ALLOW_THREADS result = ::SetSystemTime(&t); - PyW32_END_ALLOW_THREADS + PyW32_END_ALLOW_THREADS; - if (!result) - { + if (!result) { return ReturnAPIError("SetSystemTime"); } - else - { + else { return Py_BuildValue("i", result); } } @@ -6263,17 +6261,13 @@ PYWIN_MODULE_INIT_FUNC(win32api) PyModule_AddIntConstant(module, "VS_FF_PRIVATEBUILD", VS_FF_PRIVATEBUILD); PyModule_AddIntConstant(module, "VS_FF_SPECIALBUILD", VS_FF_SPECIALBUILD); - HMODULE hmodule = GetModuleHandle(TEXT("secur32.dll")); - if (hmodule == NULL) - hmodule = LoadLibrary(TEXT("secur32.dll")); + HMODULE hmodule = PyWin_GetOrLoadLibraryHandle("secur32.dll"); if (hmodule != NULL) { pfnGetUserNameEx = (GetUserNameExfunc)GetProcAddress(hmodule, "GetUserNameExW"); pfnGetComputerObjectName = (GetUserNameExfunc)GetProcAddress(hmodule, "GetComputerObjectNameW"); } - hmodule = GetModuleHandle(TEXT("kernel32.dll")); - if (hmodule == NULL) - hmodule = LoadLibrary(TEXT("kernel32.dll")); + hmodule = PyWin_GetOrLoadLibraryHandle("kernel32.dll"); if (hmodule != NULL) { pfnGetComputerNameEx = (GetComputerNameExfunc)GetProcAddress(hmodule, "GetComputerNameExW"); pfnGetLongPathNameA = (GetLongPathNameAfunc)GetProcAddress(hmodule, "GetLongPathNameA"); @@ -6289,9 +6283,7 @@ PYWIN_MODULE_INIT_FUNC(win32api) pfnGetNativeSystemInfo = (GetNativeSystemInfofunc)GetProcAddress(hmodule, "GetNativeSystemInfo"); } - hmodule = GetModuleHandle(TEXT("user32.dll")); - if (hmodule == NULL) - hmodule = LoadLibrary(TEXT("user32.dll")); + hmodule = PyWin_GetOrLoadLibraryHandle("user32.dll"); if (hmodule != NULL) { pfnEnumDisplayMonitors = (EnumDisplayMonitorsfunc)GetProcAddress(hmodule, "EnumDisplayMonitors"); pfnEnumDisplayDevices = (EnumDisplayDevicesfunc)GetProcAddress(hmodule, "EnumDisplayDevicesW"); @@ -6304,9 +6296,7 @@ PYWIN_MODULE_INIT_FUNC(win32api) pfnGetLastInputInfo = (GetLastInputInfofunc)GetProcAddress(hmodule, "GetLastInputInfo"); } - hmodule = GetModuleHandle(TEXT("Advapi32.dll")); - if (hmodule == NULL) - hmodule = LoadLibrary(TEXT("Advapi32.dll")); + hmodule = PyWin_GetOrLoadLibraryHandle("advapi32.dll"); if (hmodule != NULL) { pfnRegRestoreKey = (RegRestoreKeyfunc)GetProcAddress(hmodule, "RegRestoreKeyW"); pfnRegSaveKeyEx = (RegSaveKeyExfunc)GetProcAddress(hmodule, "RegSaveKeyExW"); diff --git a/win32/src/win32consolemodule.cpp b/win32/src/win32consolemodule.cpp index daae981cf..48e84d727 100644 --- a/win32/src/win32consolemodule.cpp +++ b/win32/src/win32consolemodule.cpp @@ -2079,9 +2079,7 @@ PYWIN_MODULE_INIT_FUNC(win32console) PyDict_SetItemString(dict, "error", PyWinExc_ApiError); // load function pointers - kernel32_dll = GetModuleHandle(L"kernel32.dll"); - if (kernel32_dll == NULL) - kernel32_dll = LoadLibrary(L"kernel32.dll"); + kernel32_dll = PyWin_GetOrLoadLibraryHandle("kernel32.dll"); if (kernel32_dll != NULL) { pfnGetConsoleProcessList = (GetConsoleProcessListfunc)GetProcAddress(kernel32_dll, "GetConsoleProcessList"); pfnGetConsoleDisplayMode = (GetConsoleDisplayModefunc)GetProcAddress(kernel32_dll, "GetConsoleDisplayMode"); diff --git a/win32/src/win32file.i b/win32/src/win32file.i index 5b1b010d7..716b76262 100644 --- a/win32/src/win32file.i +++ b/win32/src/win32file.i @@ -2,7 +2,7 @@ // @doc %module win32file // An interface to the win32 File API's -// This module includes the tranactional NTFS operations introduced with +// This module includes the transactional NTFS operations introduced with // Vista. The transacted functions are not wrapped separately, but are invoked by // passing a transaction handle to the corresponding Unicode API function. // This makes it simple to convert a set of file operations into a transaction by @@ -1179,13 +1179,13 @@ static PyObject *myGetQueuedCompletionStatus(PyObject *self, PyObject *args) PyObject *myPostQueuedCompletionStatus(PyObject *self, PyObject *args) { PyObject *obHandle, *obOverlapped = NULL, *obkey=Py_None; - DWORD bytesTransfered = 0; + DWORD bytesTransferred = 0; ULONG_PTR key = 0; // @pyparm |handle||handle to an I/O completion port - // @pyparm int|numberOfbytes|0|value to return via GetQueuedCompletionStatus' first result + // @pyparm int|numberOfBytes|0|value to return via GetQueuedCompletionStatus' first result // @pyparm int|completionKey|0|value to return via GetQueuedCompletionStatus' second result // @pyparm |overlapped|None|value to return via GetQueuedCompletionStatus' third result - if (!PyArg_ParseTuple(args, "O|iOO", &obHandle, &bytesTransfered, &obkey, &obOverlapped)) + if (!PyArg_ParseTuple(args, "O|iOO", &obHandle, &bytesTransferred, &obkey, &obOverlapped)) return NULL; if (obkey!=Py_None) if (!PyWinLong_AsVoidPtr(obkey, (void **)&key)) @@ -1198,7 +1198,7 @@ PyObject *myPostQueuedCompletionStatus(PyObject *self, PyObject *args) return NULL; BOOL ok; Py_BEGIN_ALLOW_THREADS - ok = ::PostQueuedCompletionStatus(handle, bytesTransfered, key, pOverlapped); + ok = ::PostQueuedCompletionStatus(handle, bytesTransferred, key, pOverlapped); Py_END_ALLOW_THREADS if (!ok) return PyWin_SetAPIError("PostQueuedCompletionStatus"); @@ -4168,7 +4168,7 @@ py_ReplaceFile(PyObject *self, PyObject *args) void encryptedfilecontextdestructor(PyObject *obctxt){ if (!PyCapsule_IsValid(obctxt, NULL)) return; // should not happen, but maybe print a warning just in case ? - // Check if context has already been explicitely destroyed + // Check if context has already been explicitly destroyed // The capsule's context is set to this value in CloseEncryptedFileRaw if (PyCapsule_GetContext(obctxt) == INVALID_HANDLE_VALUE) return; @@ -5932,11 +5932,8 @@ PyCFunction pfnpy_OpenFileById=(PyCFunction)py_OpenFileById; ) pmd->ml_flags = METH_VARARGS | METH_KEYWORDS; - HMODULE hmodule; - hmodule=GetModuleHandle(TEXT("AdvAPI32.dll")); - if (hmodule==NULL) - hmodule=LoadLibrary(TEXT("AdvAPI32.dll")); - if (hmodule){ + HMODULE hmodule = PyWin_GetOrLoadLibraryHandle("advapi32.dll"); + if (hmodule != NULL) { pfnEncryptFile=(EncryptFilefunc)GetProcAddress(hmodule, "EncryptFileW"); pfnDecryptFile=(DecryptFilefunc)GetProcAddress(hmodule, "DecryptFileW"); pfnEncryptionDisable=(EncryptionDisablefunc)GetProcAddress(hmodule, "EncryptionDisable"); @@ -5952,12 +5949,10 @@ PyCFunction pfnpy_OpenFileById=(PyCFunction)py_OpenFileById; pfnReadEncryptedFileRaw=(ReadEncryptedFileRawfunc)GetProcAddress(hmodule, "ReadEncryptedFileRaw"); pfnWriteEncryptedFileRaw=(WriteEncryptedFileRawfunc)GetProcAddress(hmodule, "WriteEncryptedFileRaw"); pfnCloseEncryptedFileRaw=(CloseEncryptedFileRawfunc)GetProcAddress(hmodule, "CloseEncryptedFileRaw"); - } + } - hmodule=GetModuleHandle(TEXT("kernel32.dll")); - if (hmodule==NULL) - hmodule=LoadLibrary(TEXT("kernel32.dll")); - if (hmodule){ + hmodule = PyWin_GetOrLoadLibraryHandle("kernel32.dll"); + if (hmodule != NULL) { pfnSetVolumeMountPoint=(SetVolumeMountPointfunc)GetProcAddress(hmodule, "SetVolumeMountPointW"); pfnDeleteVolumeMountPoint=(DeleteVolumeMountPointfunc)GetProcAddress(hmodule, "DeleteVolumeMountPointW"); pfnGetVolumeNameForVolumeMountPoint=(GetVolumeNameForVolumeMountPointfunc)GetProcAddress(hmodule, "GetVolumeNameForVolumeMountPointW"); @@ -6002,15 +5997,13 @@ PyCFunction pfnpy_OpenFileById=(PyCFunction)py_OpenFileById; pfnWow64RevertWow64FsRedirection=(Wow64RevertWow64FsRedirectionfunc)GetProcAddress(hmodule, "Wow64RevertWow64FsRedirection"); pfnReOpenFile=(ReOpenFilefunc)GetProcAddress(hmodule, "ReOpenFile"); pfnOpenFileById=(OpenFileByIdfunc)GetProcAddress(hmodule, "OpenFileById"); - } + } - hmodule=GetModuleHandle(TEXT("sfc.dll")); - if (hmodule==NULL) - hmodule=LoadLibrary(TEXT("sfc.dll")); - if (hmodule){ + hmodule = PyWin_GetOrLoadLibraryHandle("sfc.dll"); + if (hmodule != NULL) { pfnSfcGetNextProtectedFile=(SfcGetNextProtectedFilefunc)GetProcAddress(hmodule, "SfcGetNextProtectedFile"); pfnSfcIsFileProtected=(SfcIsFileProtectedfunc)GetProcAddress(hmodule, "SfcIsFileProtected"); - } + } %} diff --git a/win32/src/win32gui.i b/win32/src/win32gui.i index 518e84cf9..fa0906b7e 100644 --- a/win32/src/win32gui.i +++ b/win32/src/win32gui.i @@ -266,42 +266,36 @@ for (PyMethodDef *pmd = win32guiMethods; pmd->ml_name; pmd++) ) pmd->ml_flags = METH_VARARGS | METH_KEYWORDS; -HMODULE hmodule=GetModuleHandle(TEXT("user32.dll")); -if (hmodule==NULL) - hmodule=LoadLibrary(TEXT("user32.dll")); -if (hmodule){ - pfnSetLayeredWindowAttributes=(SetLayeredWindowAttributesfunc)GetProcAddress(hmodule,"SetLayeredWindowAttributes"); - pfnGetLayeredWindowAttributes=(GetLayeredWindowAttributesfunc)GetProcAddress(hmodule,"GetLayeredWindowAttributes"); - pfnUpdateLayeredWindow=(UpdateLayeredWindowfunc)GetProcAddress(hmodule,"UpdateLayeredWindow"); - pfnAnimateWindow=(AnimateWindowfunc)GetProcAddress(hmodule,"AnimateWindow"); - pfnGetMenuInfo=(GetMenuInfofunc)GetProcAddress(hmodule,"GetMenuInfo"); - pfnSetMenuInfo=(SetMenuInfofunc)GetProcAddress(hmodule,"SetMenuInfo"); - pfnDrawTextW=(DrawTextWfunc)GetProcAddress(hmodule, "DrawTextW"); - } - -hmodule=GetModuleHandle(TEXT("gdi32.dll")); -if (hmodule==NULL) - hmodule=LoadLibrary(TEXT("gdi32.dll")); -if (hmodule){ - pfnAngleArc=(AngleArcfunc)GetProcAddress(hmodule,"AngleArc"); - pfnPlgBlt=(PlgBltfunc)GetProcAddress(hmodule,"PlgBlt"); - pfnGetWorldTransform=(GetWorldTransformfunc)GetProcAddress(hmodule,"GetWorldTransform"); - pfnSetWorldTransform=(SetWorldTransformfunc)GetProcAddress(hmodule,"SetWorldTransform"); - pfnModifyWorldTransform=(ModifyWorldTransformfunc)GetProcAddress(hmodule,"ModifyWorldTransform"); - pfnCombineTransform=(CombineTransformfunc)GetProcAddress(hmodule,"CombineTransform"); - pfnMaskBlt=(MaskBltfunc)GetProcAddress(hmodule,"MaskBlt"); - pfnGetLayout=(GetLayoutfunc)GetProcAddress(hmodule,"GetLayout"); - pfnSetLayout=(SetLayoutfunc)GetProcAddress(hmodule,"SetLayout"); - } - -hmodule=GetModuleHandle(TEXT("msimg32.dll")); -if (hmodule==NULL) - hmodule=LoadLibrary(TEXT("msimg32.dll")); -if (hmodule){ - pfnGradientFill=(GradientFillfunc)GetProcAddress(hmodule,"GradientFill"); - pfnTransparentBlt=(TransparentBltfunc)GetProcAddress(hmodule,"TransparentBlt"); - pfnAlphaBlend=(AlphaBlendfunc)GetProcAddress(hmodule,"AlphaBlend"); - } +HMODULE hmodule = PyWin_GetOrLoadLibraryHandle("user32.dll"); +if (hmodule != NULL) { + pfnSetLayeredWindowAttributes = (SetLayeredWindowAttributesfunc)GetProcAddress(hmodule,"SetLayeredWindowAttributes"); + pfnGetLayeredWindowAttributes = (GetLayeredWindowAttributesfunc)GetProcAddress(hmodule,"GetLayeredWindowAttributes"); + pfnUpdateLayeredWindow = (UpdateLayeredWindowfunc)GetProcAddress(hmodule,"UpdateLayeredWindow"); + pfnAnimateWindow = (AnimateWindowfunc)GetProcAddress(hmodule,"AnimateWindow"); + pfnGetMenuInfo = (GetMenuInfofunc)GetProcAddress(hmodule,"GetMenuInfo"); + pfnSetMenuInfo = (SetMenuInfofunc)GetProcAddress(hmodule,"SetMenuInfo"); + pfnDrawTextW = (DrawTextWfunc)GetProcAddress(hmodule, "DrawTextW"); +} + +hmodule = PyWin_GetOrLoadLibraryHandle("gdi32.dll"); +if (hmodule != NULL) { + pfnAngleArc = (AngleArcfunc)GetProcAddress(hmodule,"AngleArc"); + pfnPlgBlt = (PlgBltfunc)GetProcAddress(hmodule,"PlgBlt"); + pfnGetWorldTransform = (GetWorldTransformfunc)GetProcAddress(hmodule,"GetWorldTransform"); + pfnSetWorldTransform = (SetWorldTransformfunc)GetProcAddress(hmodule,"SetWorldTransform"); + pfnModifyWorldTransform = (ModifyWorldTransformfunc)GetProcAddress(hmodule,"ModifyWorldTransform"); + pfnCombineTransform = (CombineTransformfunc)GetProcAddress(hmodule,"CombineTransform"); + pfnMaskBlt = (MaskBltfunc)GetProcAddress(hmodule,"MaskBlt"); + pfnGetLayout = (GetLayoutfunc)GetProcAddress(hmodule,"GetLayout"); + pfnSetLayout = (SetLayoutfunc)GetProcAddress(hmodule,"SetLayout"); +} + +hmodule = PyWin_GetOrLoadLibraryHandle("msimg32.dll"); +if (hmodule != NULL) { + pfnGradientFill = (GradientFillfunc)GetProcAddress(hmodule,"GradientFill"); + pfnTransparentBlt = (TransparentBltfunc)GetProcAddress(hmodule,"TransparentBlt"); + pfnAlphaBlend = (AlphaBlendfunc)GetProcAddress(hmodule,"AlphaBlend"); +} %} %{ diff --git a/win32/src/win32inet.i b/win32/src/win32inet.i index 33d5afa51..e9edf6c52 100644 --- a/win32/src/win32inet.i +++ b/win32/src/win32inet.i @@ -1941,7 +1941,7 @@ extern PyObject *PyWinHttpOpen(PyObject *, PyObject *); %init %{ PyDict_SetItemString(d, "error", PyWinExc_ApiError); - HMODULE hmod = GetModuleHandle(TEXT("wininet.dll")); + HMODULE hmod = PyWin_GetOrLoadLibraryHandle("wininet.dll"); assert(hmod); PyWin_RegisterErrorMessageModule(INTERNET_ERROR_BASE, INTERNET_ERROR_LAST, diff --git a/win32/src/win32job.i b/win32/src/win32job.i index 1b3af02e2..ccf0faf38 100644 --- a/win32/src/win32job.i +++ b/win32/src/win32job.i @@ -20,12 +20,10 @@ static IsProcessInJobfunc pfnIsProcessInJob=NULL; %init %{ -HMODULE hmodule=GetModuleHandle(L"kernel32.dll"); -if (hmodule==NULL) - hmodule=LoadLibrary(L"kernel32.dll"); -if (hmodule){ - pfnIsProcessInJob=(IsProcessInJobfunc)GetProcAddress(hmodule,"IsProcessInJob"); - } +HMODULE hmodule = PyWin_GetOrLoadLibraryHandle("kernel32.dll"); +if (hmodule != NULL) { + pfnIsProcessInJob = (IsProcessInJobfunc)GetProcAddress(hmodule, "IsProcessInJob"); +} %} diff --git a/win32/src/win32net/win32netmodule.cpp b/win32/src/win32net/win32netmodule.cpp index 1698bfb6f..e4b7ba108 100644 --- a/win32/src/win32net/win32netmodule.cpp +++ b/win32/src/win32net/win32netmodule.cpp @@ -1211,10 +1211,8 @@ PYWIN_MODULE_INIT_FUNC(win32net) AddConstant(dict, "USE_FORCE", USE_FORCE); AddConstant(dict, "USE_LOTS_OF_FORCE", USE_LOTS_OF_FORCE); - HMODULE hmodule = GetModuleHandle(_T("netapi32")); + HMODULE hmodule = PyWin_GetOrLoadLibraryHandle("netapi32.dll"); #if WINVER >= 0x0500 - if (hmodule == NULL) - hmodule = LoadLibrary(_T("netapi32")); if (hmodule != NULL) { pfnNetValidateName = (NetValidateNamefunc)GetProcAddress(hmodule, "NetValidateName"); pfnNetGetJoinInformation = (NetGetJoinInformationfunc)GetProcAddress(hmodule, "NetGetJoinInformation"); diff --git a/win32/src/win32pipe.i b/win32/src/win32pipe.i index 5311900c4..f29125c7c 100644 --- a/win32/src/win32pipe.i +++ b/win32/src/win32pipe.i @@ -25,15 +25,13 @@ static GetNamedPipeClientProcessIdfunc pfnGetNamedPipeServerSessionId = NULL; // All errors raised by this module are of this type. PyDict_SetItemString(d, "error", PyWinExc_ApiError); - HMODULE hmod=GetModuleHandle(_T("Kernel32.dll")); - if (!hmod) - hmod=LoadLibrary(_T("Kernel32.dll")); - if (hmod){ + HMODULE hmod = PyWin_GetOrLoadLibraryHandle("kernel32.dll"); + if (hmod != NULL) { pfnGetNamedPipeClientProcessId = (GetNamedPipeClientProcessIdfunc)GetProcAddress(hmod, "GetNamedPipeClientProcessId"); pfnGetNamedPipeServerProcessId = (GetNamedPipeClientProcessIdfunc)GetProcAddress(hmod, "GetNamedPipeServerProcessId"); pfnGetNamedPipeClientSessionId = (GetNamedPipeClientProcessIdfunc)GetProcAddress(hmod, "GetNamedPipeClientSessionId"); pfnGetNamedPipeServerSessionId = (GetNamedPipeClientProcessIdfunc)GetProcAddress(hmod, "GetNamedPipeServerSessionId"); - } + } %} %{ diff --git a/win32/src/win32process.i b/win32/src/win32process.i index 331ed0f23..c938f4566 100644 --- a/win32/src/win32process.i +++ b/win32/src/win32process.i @@ -1686,23 +1686,18 @@ PyObject *PyWriteProcessMemory(PyObject *self, PyObject *args) if (PyType_Ready(&PySTARTUPINFOType) == -1) return NULL; - FARPROC fp=NULL; - HMODULE hmodule=NULL; - hmodule=GetModuleHandle(_T("Psapi.dll")); - if (hmodule==NULL) - hmodule=LoadLibrary(_T("Psapi.dll")); - if (hmodule!=NULL){ + FARPROC fp = NULL; + HMODULE hmodule = PyWin_GetOrLoadLibraryHandle("psapi.dll"); + if (hmodule != NULL) { pfnEnumProcesses = (EnumProcessesfunc)GetProcAddress(hmodule, "EnumProcesses"); pfnEnumProcessModules = (EnumProcessModulesfunc)GetProcAddress(hmodule, "EnumProcessModules"); pfnEnumProcessModulesEx = (EnumProcessModulesExfunc)GetProcAddress(hmodule, "EnumProcessModulesEx"); pfnGetModuleFileNameEx = (GetModuleFileNameExfunc)GetProcAddress(hmodule, "GetModuleFileNameExW"); pfnGetProcessMemoryInfo = (GetProcessMemoryInfofunc)GetProcAddress(hmodule, "GetProcessMemoryInfo"); - } + } - hmodule=GetModuleHandle(_T("Kernel32.dll")); - if (hmodule==NULL) - hmodule=LoadLibrary(_T("Kernel32.dll")); - if (hmodule!=NULL){ + hmodule = PyWin_GetOrLoadLibraryHandle("kernel32.dll"); + if (hmodule != NULL) { pfnGetProcessTimes=(GetProcessTimesfunc)GetProcAddress(hmodule,"GetProcessTimes"); pfnGetProcessIoCounters=(GetProcessIoCountersfunc)GetProcAddress(hmodule,"GetProcessIoCounters"); pfnGetProcessShutdownParameters=(GetProcessShutdownParametersfunc)GetProcAddress(hmodule,"GetProcessShutdownParameters"); @@ -1720,15 +1715,13 @@ PyObject *PyWriteProcessMemory(PyObject *self, PyObject *args) pfnSetProcessAffinityMask=(SetProcessAffinityMaskfunc)GetProcAddress(hmodule,"SetProcessAffinityMask"); pfnGetProcessId=(GetProcessIdfunc)GetProcAddress(hmodule, "GetProcessId"); pfnIsWow64Process=(IsWow64Processfunc)GetProcAddress(hmodule, "IsWow64Process"); - } + } - hmodule=GetModuleHandle(_T("User32.dll")); - if (hmodule==NULL) - hmodule=LoadLibrary(_T("User32.dll")); - if (hmodule!=NULL){ + hmodule = PyWin_GetOrLoadLibraryHandle("user32.dll"); + if (hmodule != NULL) { pfnGetProcessWindowStation=(GetProcessWindowStationfunc)GetProcAddress(hmodule,"GetProcessWindowStation"); pfnGetGuiResources=(GetGuiResourcesfunc)GetProcAddress(hmodule,"GetGuiResources"); - } + } // *sob* - these symbols don't exist in the platform sdk needed to build // using Python 2.3 diff --git a/win32/src/win32profilemodule.cpp b/win32/src/win32profilemodule.cpp index 17299f00b..98c4fac72 100644 --- a/win32/src/win32profilemodule.cpp +++ b/win32/src/win32profilemodule.cpp @@ -489,10 +489,7 @@ PYWIN_MODULE_INIT_FUNC(win32profile) PyModule_AddIntConstant(module, "PT_ROAMING", PT_ROAMING); PyModule_AddIntConstant(module, "PT_TEMPORARY", PT_TEMPORARY); - HMODULE hmodule; - hmodule = GetModuleHandle(L"Userenv.dll"); - if (hmodule == NULL) - hmodule = LoadLibrary(L"Userenv.dll"); + HMODULE hmodule = PyWin_GetOrLoadLibraryHandle("userenv.dll"); if (hmodule != NULL) { pfnDeleteProfile = (DeleteProfilefunc)GetProcAddress(hmodule, "DeleteProfileW"); pfnExpandEnvironmentStringsForUser = diff --git a/win32/src/win32service.i b/win32/src/win32service.i index 1150dff74..b91a0e16b 100644 --- a/win32/src/win32service.i +++ b/win32/src/win32service.i @@ -36,12 +36,9 @@ EnumServicesStatusExfunc fpEnumServicesStatusEx=NULL; PyDict_SetItemString(d, "error", PyWinExc_ApiError); PyDict_SetItemString(d, "HWINSTAType", (PyObject *)&PyHWINSTAType); PyDict_SetItemString(d, "HDESKType", (PyObject *)&PyHDESKType); - HMODULE hmod; FARPROC fp; - hmod=GetModuleHandle(_T("Advapi32")); - if (hmod==NULL) - hmod=LoadLibrary(_T("Advapi32")); - if (hmod!=NULL){ + HMODULE hmod = PyWin_GetOrLoadLibraryHandle("advapi32.dll"); + if (hmod != NULL) { fp=GetProcAddress(hmod,"QueryServiceStatusEx"); if (fp!=NULL) fpQueryServiceStatusEx=(QueryServiceStatusExfunc)fp; @@ -54,7 +51,7 @@ EnumServicesStatusExfunc fpEnumServicesStatusEx=NULL; fp=GetProcAddress(hmod,"EnumServicesStatusExW"); if (fp!=NULL) fpEnumServicesStatusEx=(EnumServicesStatusExfunc)fp; - } + } %} %{ diff --git a/win32/src/win32transactionmodule.cpp b/win32/src/win32transactionmodule.cpp index 27c62d606..df39f67a1 100644 --- a/win32/src/win32transactionmodule.cpp +++ b/win32/src/win32transactionmodule.cpp @@ -235,10 +235,8 @@ PYWIN_MODULE_INIT_FUNC(win32transaction) " transacted NTFS and transacted registry functions."); // Load dll and function pointers to avoid dependency on newer libraries and headers - HMODULE hmodule = GetModuleHandle(L"Ktmw32.dll"); - if (hmodule == NULL) - hmodule = LoadLibrary(L"Ktmw32.dll"); - if (hmodule) { + HMODULE hmodule = PyWin_GetOrLoadLibraryHandle("ktmw32.dll"); + if (hmodule != NULL) { pfnCreateTransaction = (CreateTransactionfunc)GetProcAddress(hmodule, "CreateTransaction"); pfnRollbackTransaction = (RollbackTransactionfunc)GetProcAddress(hmodule, "RollbackTransaction"); pfnRollbackTransactionAsync = (RollbackTransactionAsyncfunc)GetProcAddress(hmodule, "RollbackTransactionAsync"); diff --git a/win32/src/win32tsmodule.cpp b/win32/src/win32tsmodule.cpp index ddd383dee..ac18c03dc 100644 --- a/win32/src/win32tsmodule.cpp +++ b/win32/src/win32tsmodule.cpp @@ -836,10 +836,8 @@ PYWIN_MODULE_INIT_FUNC(win32ts) PyModule_AddIntConstant(module, "NOTIFY_FOR_THIS_SESSION", NOTIFY_FOR_THIS_SESSION); PyModule_AddIntConstant(module, "NOTIFY_FOR_ALL_SESSIONS", NOTIFY_FOR_ALL_SESSIONS); - HMODULE h = GetModuleHandle(L"wtsapi32.dll"); - if (h == NULL) - h = LoadLibrary(L"wtsapi32.dll"); - if (h) { + HMODULE h = PyWin_GetOrLoadLibraryHandle("wtsapi32.dll"); + if (h != NULL) { pfnWTSQueryUserToken = (WTSQueryUserTokenfunc)GetProcAddress(h, "WTSQueryUserToken"); pfnWTSRegisterSessionNotification = (WTSRegisterSessionNotificationfunc)GetProcAddress(h, "WTSRegisterSessionNotification"); @@ -847,10 +845,8 @@ PYWIN_MODULE_INIT_FUNC(win32ts) (WTSUnRegisterSessionNotificationfunc)GetProcAddress(h, "WTSUnRegisterSessionNotification"); } - h = GetModuleHandle(L"kernel32.dll"); - if (h == NULL) - h = LoadLibrary(L"kernel32.dll"); - if (h) { + h = PyWin_GetOrLoadLibraryHandle("kernel32.dll"); + if (h != NULL) { pfnProcessIdToSessionId = (ProcessIdToSessionIdfunc)GetProcAddress(h, "ProcessIdToSessionId"); pfnWTSGetActiveConsoleSessionId = (WTSGetActiveConsoleSessionIdfunc)GetProcAddress(h, "WTSGetActiveConsoleSessionId");