source: trunk/src/allmydata/windows/fixups.py

Last change on this file was 0bbc8f6, checked in by Itamar Turner-Trauring <itamar@…>, at 2024-03-01T17:16:40Z

Delete Python 2 specific code.

  • Property mode set to 100644
File size: 1.2 KB
Line 
1# This code isn't loadable or sensible except on Windows.  Importers all know
2# this and are careful.  Normally I would just let an import error from ctypes
3# explain any mistakes but Mypy also needs some help here.  This assert
4# explains to it that this module is Windows-only.  This prevents errors about
5# ctypes.windll and such which only exist when running on Windows.
6#
7# Beware of the limitations of the Mypy AST analyzer.  The check needs to take
8# exactly this form or it may not be recognized.
9#
10# https://mypy.readthedocs.io/en/stable/common_issues.html?highlight=platform#python-version-and-system-platform-checks
11import sys
12assert sys.platform == "win32"
13
14# <https://msdn.microsoft.com/en-us/library/ms680621%28VS.85%29.aspx>
15from win32api import (
16    SetErrorMode,
17)
18from win32con import (
19    SEM_FAILCRITICALERRORS,
20    SEM_NOOPENFILEERRORBOX,
21)
22
23# Keep track of whether `initialize` has run so we don't do any of the
24# initialization more than once.
25_done = False
26
27
28def initialize():
29    global _done
30    import sys
31    if sys.platform != "win32" or _done:
32        return True
33    _done = True
34
35    SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX)
Note: See TracBrowser for help on using the repository browser.