comtypes 1.4.4__zip → 1.4.6__zip

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. {comtypes-1.4.4 → comtypes-1.4.6}/CHANGES.txt +24 -0
  2. {comtypes-1.4.4/comtypes.egg-info → comtypes-1.4.6}/PKG-INFO +1 -1
  3. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/GUID.py +24 -24
  4. comtypes-1.4.6/comtypes/__init__.py +268 -0
  5. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/_comobject.py +2 -1
  6. comtypes-1.4.6/comtypes/_idl_stuff.py +67 -0
  7. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/_memberspec.py +4 -12
  8. comtypes-1.4.6/comtypes/_post_coinit/__init__.py +15 -0
  9. comtypes-1.4.6/comtypes/_post_coinit/bstr.py +30 -0
  10. comtypes-1.4.6/comtypes/_post_coinit/misc.py +385 -0
  11. comtypes-1.4.6/comtypes/_post_coinit/unknwn.py +537 -0
  12. comtypes-1.4.6/comtypes/_py_instance_method.py +13 -0
  13. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/_safearray.py +3 -2
  14. comtypes-1.4.6/comtypes/_tlib_version_checker.py +18 -0
  15. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/automation.py +34 -45
  16. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/__init__.py +2 -9
  17. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/_code_cache.py +2 -2
  18. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/_generate.py +2 -1
  19. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/hints.pyi +38 -16
  20. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/safearray.py +11 -4
  21. comtypes-1.4.6/comtypes/stream.py +65 -0
  22. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_client.py +11 -0
  23. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_dispifc_records.py +1 -1
  24. comtypes-1.4.6/comtypes/test/test_dispifc_safearrays.py +89 -0
  25. comtypes-1.4.6/comtypes/test/test_istream.py +53 -0
  26. comtypes-1.4.6/comtypes/test/test_midl_safearray_create.py +100 -0
  27. comtypes-1.4.6/comtypes/test/test_recordinfo.py +79 -0
  28. comtypes-1.4.6/comtypes/test/test_typeannotator.py +127 -0
  29. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_wmi.py +11 -18
  30. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/codegenerator/codegenerator.py +0 -1
  31. comtypes-1.4.6/comtypes/tools/codegenerator/modulenamer.py +23 -0
  32. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/codegenerator/typeannotator.py +27 -22
  33. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/tlbparser.py +22 -24
  34. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/typedesc_base.py +2 -8
  35. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/typeinfo.py +33 -35
  36. {comtypes-1.4.4 → comtypes-1.4.6/comtypes.egg-info}/PKG-INFO +1 -1
  37. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes.egg-info/SOURCES.txt +13 -0
  38. {comtypes-1.4.4 → comtypes-1.4.6}/setup.cfg +1 -0
  39. comtypes-1.4.4/comtypes/__init__.py +0 -1229
  40. comtypes-1.4.4/comtypes/tools/codegenerator/modulenamer.py +0 -24
  41. {comtypes-1.4.4 → comtypes-1.4.6}/LICENSE.txt +0 -0
  42. {comtypes-1.4.4 → comtypes-1.4.6}/MANIFEST.in +0 -0
  43. {comtypes-1.4.4 → comtypes-1.4.6}/README.md +0 -0
  44. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/_meta.py +0 -0
  45. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/_npsupport.py +0 -0
  46. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/clear_cache.py +0 -0
  47. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/_constants.py +0 -0
  48. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/_events.py +0 -0
  49. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/dynamic.py +0 -0
  50. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/client/lazybind.py +0 -0
  51. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/connectionpoints.py +0 -0
  52. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/errorinfo.py +0 -0
  53. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/git.py +0 -0
  54. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/hresult.py +0 -0
  55. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/logutil.py +0 -0
  56. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/messageloop.py +0 -0
  57. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/patcher.py +0 -0
  58. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/persist.py +0 -0
  59. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/__init__.py +0 -0
  60. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/automation.py +0 -0
  61. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/connectionpoints.py +0 -0
  62. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/inprocserver.py +0 -0
  63. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/localserver.py +0 -0
  64. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/register.py +0 -0
  65. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/server/w_getopt.py +0 -0
  66. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/shelllink.py +0 -0
  67. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/TestComServer.idl +0 -0
  68. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/TestComServer.py +0 -0
  69. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/TestComServer.tlb +0 -0
  70. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/TestDispServer.idl +0 -0
  71. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/TestDispServer.py +0 -0
  72. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/TestDispServer.tlb +0 -0
  73. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/__init__.py +0 -0
  74. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/find_memleak.py +0 -0
  75. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/mylib.idl +0 -0
  76. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/mylib.tlb +0 -0
  77. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/mytypelib.idl +0 -0
  78. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/runtests.py +0 -0
  79. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/setup.py +0 -0
  80. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_BSTR.py +0 -0
  81. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_DISPPARAMS.py +0 -0
  82. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_GUID.py +0 -0
  83. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_QueryService.py +0 -0
  84. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_agilent.py +0 -0
  85. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_avmc.py +0 -0
  86. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_basic.py +0 -0
  87. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_casesensitivity.py +0 -0
  88. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_clear_cache.py +0 -0
  89. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_client_dynamic.py +0 -0
  90. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_client_regenerate_modules.py +0 -0
  91. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_collections.py +0 -0
  92. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_comserver.py +0 -0
  93. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_createwrappers.py +0 -0
  94. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_dict.py +0 -0
  95. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_dispinterface.py +0 -0
  96. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_dyndispatch.py +0 -0
  97. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_excel.py +0 -0
  98. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_findgendir.py +0 -0
  99. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_getactiveobj.py +0 -0
  100. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_ie.py +0 -0
  101. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_ienum.py +0 -0
  102. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_imfattributes.py +0 -0
  103. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_inout_args.py +0 -0
  104. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_jscript.js +0 -0
  105. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_msscript.py +0 -0
  106. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_npsupport.py +0 -0
  107. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_outparam.py +0 -0
  108. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_propputref.py +0 -0
  109. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_pump_events.py +0 -0
  110. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_safearray.py +0 -0
  111. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_sapi.py +0 -0
  112. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_server.py +0 -0
  113. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_showevents.py +0 -0
  114. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_subinterface.py +0 -0
  115. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_typeinfo.py +0 -0
  116. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_urlhistory.py +0 -0
  117. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_variant.py +0 -0
  118. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_win32com_interop.py +0 -0
  119. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/test_word.py +0 -0
  120. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/test/urlhist.tlb +0 -0
  121. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/__init__.py +0 -0
  122. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/codegenerator/__init__.py +0 -0
  123. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/codegenerator/helpers.py +0 -0
  124. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/codegenerator/namespaces.py +0 -0
  125. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/codegenerator/packing.py +0 -0
  126. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/tools/typedesc.py +0 -0
  127. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/util.py +0 -0
  128. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes/viewobject.py +0 -0
  129. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes.egg-info/dependency_links.txt +0 -0
  130. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes.egg-info/entry_points.txt +0 -0
  131. {comtypes-1.4.4 → comtypes-1.4.6}/comtypes.egg-info/top_level.txt +0 -0
  132. {comtypes-1.4.4 → comtypes-1.4.6}/pyproject.toml +0 -0
  133. {comtypes-1.4.4 → comtypes-1.4.6}/setup.py +0 -0
@@ -1,6 +1,30 @@
1
1
  Comtypes CHANGELOG
2
2
  ==================
3
3
 
4
+ Release 1.4.6
5
+ --------------
6
+ * Add tests and method annotations for ``IRecordInfo``. By @junkmd.
7
+ * Improve static typings in ``automation``. By @junkmd.
8
+ * Tidy up import part in some modules. By @junkmd.
9
+ * Refer to ``Any`` and ``Tuple`` from the ``hints`` stub instead of directly importing them in generated modules. By @junkmd.
10
+ * Modernize ``GUID.py``. By @junkmd.
11
+ * Improve ``codegenerator.modulenamer`` static typing. By @junkmd.
12
+ * Avoid using keywords in ``TYPE_CHECKING`` blocks. By @junkmd.
13
+ * Improve member defining parts of ``ParseInterface`` and ``ParseDispatch``. By @junkmd.
14
+ * Fix Annoying SyntaxWarning. By @v01d-gh.
15
+
16
+ Release 1.4.5
17
+ --------------
18
+ * Split ``__init__.py`` into some modules. By @junkmd.
19
+ * Fix importing ``_DispMemberSpec`` in ``automation``. By @junkmd.
20
+ * Fix importing ``_encode_idl`` in ``_comobject``. By @junkmd.
21
+ * Change the name of the component that implements the interface for record parameter testing. By @geppi.
22
+ * Implement ``SAFEARRAY`` pointers and ``SAFEARRAY``s as method parameters of a Dispatch Interface. By @geppi.
23
+ * Change the default value of the ``extra`` parameter in the ``create`` method of ``tagSAFEARRAY`` subtypes. By @geppi.
24
+ * Implement static import for ``ISequentialStream``. By @jonschz.
25
+ * Modernize ``test_wmi``. By @junkmd.
26
+ * Add static typing for ``_midlSAFEARRAY``. By @junkmd.
27
+
4
28
  Release 1.4.4
5
29
  --------------
6
30
  * Stop mentioning the last version supporting Windows CE in ``README.md``. By @forderud.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: comtypes
3
- Version: 1.4.4
3
+ Version: 1.4.6
4
4
  Summary: Pure Python COM package
5
5
  Home-page: https://github.com/enthought/comtypes
6
6
  Download-URL: https://github.com/enthought/comtypes/releases
@@ -1,8 +1,12 @@
1
- from ctypes import *
2
- import sys
1
+ from ctypes import oledll, windll
2
+ from ctypes import byref, c_byte, c_ushort, c_ulong, c_wchar_p, Structure
3
+ from typing import Any, TYPE_CHECKING
3
4
 
5
+ if TYPE_CHECKING:
6
+ from comtypes import hints # type: ignore
4
7
 
5
- def binary(obj):
8
+
9
+ def binary(obj: "GUID") -> bytes:
6
10
  return bytes(obj)
7
11
 
8
12
 
@@ -31,37 +35,32 @@ class GUID(Structure):
31
35
  _CLSIDFromString(str(name), byref(self))
32
36
 
33
37
  def __repr__(self):
34
- return 'GUID("%s")' % str(self)
38
+ return f'GUID("{str(self)}")'
35
39
 
36
- def __unicode__(self):
40
+ def __str__(self) -> str:
37
41
  p = c_wchar_p()
38
42
  _StringFromCLSID(byref(self), byref(p))
39
43
  result = p.value
40
44
  _CoTaskMemFree(p)
41
- return result
42
-
43
- __str__ = __unicode__
44
-
45
- def __cmp__(self, other):
46
- if isinstance(other, GUID):
47
- return cmp(binary(self), binary(other))
48
- return -1
45
+ # stringified `GUID_null` would be '{00000000-0000-0000-0000-000000000000}'
46
+ # Should we do `assert result is not None`?
47
+ return result # type: ignore
49
48
 
50
- def __bool__(self):
49
+ def __bool__(self) -> bool:
51
50
  return self != GUID_null
52
51
 
53
- def __eq__(self, other):
52
+ def __eq__(self, other) -> bool:
54
53
  return isinstance(other, GUID) and binary(self) == binary(other)
55
54
 
56
- def __hash__(self):
55
+ def __hash__(self) -> int:
57
56
  # We make GUID instances hashable, although they are mutable.
58
57
  return hash(binary(self))
59
58
 
60
- def copy(self):
59
+ def copy(self) -> "GUID":
61
60
  return GUID(str(self))
62
61
 
63
62
  @classmethod
64
- def from_progid(cls, progid):
63
+ def from_progid(cls, progid: Any) -> "hints.Self":
65
64
  """Get guid from progid, ..."""
66
65
  if hasattr(progid, "_reg_clsid_"):
67
66
  progid = progid._reg_clsid_
@@ -74,19 +73,20 @@ class GUID(Structure):
74
73
  _CLSIDFromProgID(str(progid), byref(inst))
75
74
  return inst
76
75
  else:
77
- raise TypeError("Cannot construct guid from %r" % progid)
76
+ raise TypeError(f"Cannot construct guid from {progid!r}")
78
77
 
79
- def as_progid(self):
80
- "Convert a GUID into a progid"
78
+ def as_progid(self) -> str:
79
+ """Convert a GUID into a progid"""
81
80
  progid = c_wchar_p()
82
81
  _ProgIDFromCLSID(byref(self), byref(progid))
83
82
  result = progid.value
84
83
  _CoTaskMemFree(progid)
85
- return result
84
+ # Should we do `assert result is not None`?
85
+ return result # type: ignore
86
86
 
87
87
  @classmethod
88
- def create_new(cls):
89
- "Create a brand new guid"
88
+ def create_new(cls) -> "hints.Self":
89
+ """Create a brand new guid"""
90
90
  guid = cls()
91
91
  _CoCreateGuid(byref(guid))
92
92
  return guid
@@ -0,0 +1,268 @@
1
+ # comtypes version numbers follow semver (http://semver.org/) and PEP 440
2
+ __version__ = "1.4.6"
3
+
4
+ try:
5
+ from _ctypes import COMError # noqa
6
+ except ImportError as e:
7
+ msg = "\n".join(
8
+ (
9
+ "COM technology not available (maybe it's the wrong platform).",
10
+ "Note that COM is only supported on Windows.",
11
+ "For more details, please check: "
12
+ "https://learn.microsoft.com/en-us/windows/win32/com",
13
+ )
14
+ )
15
+ raise ImportError(msg) from e
16
+
17
+ import atexit
18
+
19
+ # HACK: Workaround for projects that depend on this package
20
+ # There should be several projects around the world that depend on this package
21
+ # and indirectly reference the symbols of `ctypes` from `comtypes`.
22
+ # If we remove the wildcard import from `ctypes`, they might break. So it is
23
+ # left in the following line.
24
+ from ctypes import * # noqa
25
+ from ctypes import HRESULT # noqa
26
+ from ctypes import _Pointer, _SimpleCData # noqa
27
+ from ctypes import c_int, c_ulong, oledll, windll
28
+ import logging
29
+ import sys
30
+ from typing import TYPE_CHECKING
31
+
32
+ if TYPE_CHECKING:
33
+ from ctypes import _CData # only in `typeshed`, private in runtime
34
+ from comtypes import hints as hints # noqa # type: ignore
35
+ else:
36
+ _CData = _SimpleCData.__mro__[:-1][-1]
37
+
38
+ from comtypes.GUID import GUID
39
+ from comtypes import patcher # noqa
40
+ from comtypes._npsupport import interop as npsupport # noqa
41
+ from comtypes._tlib_version_checker import _check_version # noqa
42
+ from comtypes._py_instance_method import instancemethod # noqa
43
+ from comtypes._idl_stuff import defaultvalue, helpstring, dispid # noqa
44
+ from comtypes._idl_stuff import STDMETHOD, DISPMETHOD, DISPPROPERTY, COMMETHOD # noqa
45
+
46
+ _all_slice = slice(None, None, None)
47
+
48
+
49
+ class NullHandler(logging.Handler):
50
+ """A Handler that does nothing."""
51
+
52
+ def emit(self, record):
53
+ pass
54
+
55
+
56
+ logger = logging.getLogger(__name__)
57
+
58
+ # Add a NULL handler to the comtypes logger. This prevents getting a
59
+ # message like this:
60
+ # No handlers could be found for logger "comtypes"
61
+ # when logging is not configured and logger.error() is called.
62
+ logger.addHandler(NullHandler())
63
+
64
+
65
+ class ReturnHRESULT(Exception):
66
+ """ReturnHRESULT(hresult, text)
67
+
68
+ Return a hresult code from a COM method implementation
69
+ without logging an error.
70
+ """
71
+
72
+
73
+ # class IDLWarning(UserWarning):
74
+ # "Warn about questionable type information"
75
+
76
+ _GUID = GUID
77
+ IID = GUID
78
+ DWORD = c_ulong
79
+
80
+ wireHWND = c_ulong
81
+
82
+ ################################################################
83
+ # About COM apartments:
84
+ # http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx
85
+ ################################################################
86
+
87
+ ################################################################
88
+ # constants for object creation
89
+ CLSCTX_INPROC_SERVER = 1
90
+ CLSCTX_INPROC_HANDLER = 2
91
+ CLSCTX_LOCAL_SERVER = 4
92
+
93
+ CLSCTX_INPROC = 3
94
+ CLSCTX_SERVER = 5
95
+ CLSCTX_ALL = 7
96
+
97
+ CLSCTX_INPROC_SERVER16 = 8
98
+ CLSCTX_REMOTE_SERVER = 16
99
+ CLSCTX_INPROC_HANDLER16 = 32
100
+ CLSCTX_RESERVED1 = 64
101
+ CLSCTX_RESERVED2 = 128
102
+ CLSCTX_RESERVED3 = 256
103
+ CLSCTX_RESERVED4 = 512
104
+ CLSCTX_NO_CODE_DOWNLOAD = 1024
105
+ CLSCTX_RESERVED5 = 2048
106
+ CLSCTX_NO_CUSTOM_MARSHAL = 4096
107
+ CLSCTX_ENABLE_CODE_DOWNLOAD = 8192
108
+ CLSCTX_NO_FAILURE_LOG = 16384
109
+ CLSCTX_DISABLE_AAA = 32768
110
+ CLSCTX_ENABLE_AAA = 65536
111
+ CLSCTX_FROM_DEFAULT_CONTEXT = 131072
112
+
113
+ tagCLSCTX = c_int # enum
114
+ CLSCTX = tagCLSCTX
115
+
116
+ # Constants for security setups
117
+ SEC_WINNT_AUTH_IDENTITY_UNICODE = 0x2
118
+ RPC_C_AUTHN_WINNT = 10
119
+ RPC_C_AUTHZ_NONE = 0
120
+ RPC_C_AUTHN_LEVEL_CONNECT = 2
121
+ RPC_C_IMP_LEVEL_IMPERSONATE = 3
122
+ EOAC_NONE = 0
123
+
124
+
125
+ ################################################################
126
+ # Initialization and shutdown
127
+ _ole32 = oledll.ole32
128
+ _ole32_nohresult = windll.ole32 # use this for functions that don't return a HRESULT
129
+
130
+ COINIT_MULTITHREADED = 0x0
131
+ COINIT_APARTMENTTHREADED = 0x2
132
+ COINIT_DISABLE_OLE1DDE = 0x4
133
+ COINIT_SPEED_OVER_MEMORY = 0x8
134
+
135
+
136
+ def CoInitialize():
137
+ return CoInitializeEx(COINIT_APARTMENTTHREADED)
138
+
139
+
140
+ def CoInitializeEx(flags=None):
141
+ if flags is None:
142
+ flags = getattr(sys, "coinit_flags", COINIT_APARTMENTTHREADED)
143
+ logger.debug("CoInitializeEx(None, %s)", flags)
144
+ _ole32.CoInitializeEx(None, flags)
145
+
146
+
147
+ # COM is initialized automatically for the thread that imports this
148
+ # module for the first time. sys.coinit_flags is passed as parameter
149
+ # to CoInitializeEx, if defined, otherwise COINIT_APARTMENTTHREADED
150
+ # (COINIT_MULTITHREADED on Windows CE) is used.
151
+ #
152
+ # A shutdown function is registered with atexit, so that
153
+ # CoUninitialize is called when Python is shut down.
154
+ CoInitializeEx()
155
+
156
+
157
+ # We need to have CoUninitialize for multithreaded model where we have
158
+ # to initialize and uninitialize COM for every new thread (except main)
159
+ # in which we are using COM
160
+ def CoUninitialize():
161
+ logger.debug("CoUninitialize()")
162
+ _ole32_nohresult.CoUninitialize()
163
+
164
+
165
+ ################################################################
166
+ # global registries.
167
+
168
+ # allows to find interface classes by guid strings (iid)
169
+ com_interface_registry = {}
170
+
171
+ # allows to find coclasses by guid strings (clsid)
172
+ com_coclass_registry = {}
173
+
174
+
175
+ ################################################################
176
+ # IUnknown, the root of all evil...
177
+ from comtypes._post_coinit import _shutdown
178
+ from comtypes._post_coinit.unknwn import IUnknown # noqa
179
+
180
+ atexit.register(_shutdown)
181
+
182
+ ################################################################
183
+
184
+ from comtypes._post_coinit.bstr import BSTR # noqa
185
+
186
+
187
+ ################################################################
188
+ # IPersist is a trivial interface, which allows to ask an object about
189
+ # its clsid.
190
+ from comtypes._post_coinit.misc import IPersist, IServiceProvider # noqa
191
+
192
+
193
+ ################################################################
194
+
195
+
196
+ from comtypes._post_coinit.misc import ( # noqa
197
+ _is_object,
198
+ CoGetObject,
199
+ CoCreateInstance,
200
+ CoGetClassObject,
201
+ GetActiveObject,
202
+ MULTI_QI,
203
+ _COAUTHIDENTITY,
204
+ COAUTHIDENTITY,
205
+ _COAUTHINFO,
206
+ COAUTHINFO,
207
+ _COSERVERINFO,
208
+ COSERVERINFO,
209
+ _CoGetClassObject,
210
+ tagBIND_OPTS,
211
+ BIND_OPTS,
212
+ tagBIND_OPTS2,
213
+ BINDOPTS2,
214
+ _SEC_WINNT_AUTH_IDENTITY,
215
+ SEC_WINNT_AUTH_IDENTITY,
216
+ _SOLE_AUTHENTICATION_INFO,
217
+ SOLE_AUTHENTICATION_INFO,
218
+ _SOLE_AUTHENTICATION_LIST,
219
+ SOLE_AUTHENTICATION_LIST,
220
+ CoCreateInstanceEx,
221
+ )
222
+
223
+
224
+ ################################################################
225
+ from comtypes._comobject import COMObject
226
+
227
+ # What's a coclass?
228
+ # a POINTER to a coclass is allowed as parameter in a function declaration:
229
+ # http://msdn.microsoft.com/library/en-us/midl/midl/oleautomation.asp
230
+
231
+ from comtypes._meta import _coclass_meta
232
+
233
+
234
+ class CoClass(COMObject, metaclass=_coclass_meta):
235
+ pass
236
+
237
+
238
+ ################################################################
239
+
240
+
241
+ # fmt: off
242
+ __known_symbols__ = [
243
+ "BIND_OPTS", "tagBIND_OPTS", "BINDOPTS2", "tagBIND_OPTS2", "BSTR",
244
+ "_check_version", "CLSCTX", "tagCLSCTX", "CLSCTX_ALL",
245
+ "CLSCTX_DISABLE_AAA", "CLSCTX_ENABLE_AAA", "CLSCTX_ENABLE_CODE_DOWNLOAD",
246
+ "CLSCTX_FROM_DEFAULT_CONTEXT", "CLSCTX_INPROC", "CLSCTX_INPROC_HANDLER",
247
+ "CLSCTX_INPROC_HANDLER16", "CLSCTX_INPROC_SERVER",
248
+ "CLSCTX_INPROC_SERVER16", "CLSCTX_LOCAL_SERVER", "CLSCTX_NO_CODE_DOWNLOAD",
249
+ "CLSCTX_NO_CUSTOM_MARSHAL", "CLSCTX_NO_FAILURE_LOG",
250
+ "CLSCTX_REMOTE_SERVER", "CLSCTX_RESERVED1", "CLSCTX_RESERVED2",
251
+ "CLSCTX_RESERVED3", "CLSCTX_RESERVED4", "CLSCTX_RESERVED5",
252
+ "CLSCTX_SERVER", "_COAUTHIDENTITY", "COAUTHIDENTITY", "_COAUTHINFO",
253
+ "COAUTHINFO", "CoClass", "CoCreateInstance", "CoCreateInstanceEx",
254
+ "_CoGetClassObject", "CoGetClassObject", "CoGetObject",
255
+ "COINIT_APARTMENTTHREADED", "COINIT_DISABLE_OLE1DDE",
256
+ "COINIT_MULTITHREADED", "COINIT_SPEED_OVER_MEMORY", "CoInitialize",
257
+ "CoInitializeEx", "COMError", "COMMETHOD", "COMObject", "_COSERVERINFO",
258
+ "COSERVERINFO", "CoUninitialize", "dispid", "DISPMETHOD", "DISPPROPERTY",
259
+ "DWORD", "EOAC_NONE", "GetActiveObject", "_GUID", "GUID", "helpstring",
260
+ "IID", "IPersist", "IServiceProvider", "IUnknown", "MULTI_QI",
261
+ "ReturnHRESULT", "RPC_C_AUTHN_LEVEL_CONNECT", "RPC_C_AUTHN_WINNT",
262
+ "RPC_C_AUTHZ_NONE", "RPC_C_IMP_LEVEL_IMPERSONATE",
263
+ "_SEC_WINNT_AUTH_IDENTITY", "SEC_WINNT_AUTH_IDENTITY",
264
+ "SEC_WINNT_AUTH_IDENTITY_UNICODE", "_SOLE_AUTHENTICATION_INFO",
265
+ "SOLE_AUTHENTICATION_INFO", "_SOLE_AUTHENTICATION_LIST",
266
+ "SOLE_AUTHENTICATION_LIST", "STDMETHOD", "wireHWND",
267
+ ]
268
+ # fmt: on
@@ -16,7 +16,8 @@ import os
16
16
  import queue
17
17
  import sys
18
18
 
19
- from comtypes import COMError, ReturnHRESULT, instancemethod, _encode_idl
19
+ from comtypes import COMError, ReturnHRESULT, instancemethod
20
+ from comtypes._memberspec import _encode_idl
20
21
  from comtypes.errorinfo import ISupportErrorInfo, ReportException, ReportError
21
22
  from comtypes import IPersist
22
23
  from comtypes.hresult import (
@@ -0,0 +1,67 @@
1
+ from comtypes._memberspec import _ComMemberSpec, _DispMemberSpec, _resolve_argspec
2
+
3
+
4
+ class helpstring(str):
5
+ "Specifies the helpstring for a COM method or property."
6
+
7
+
8
+ class defaultvalue(object):
9
+ "Specifies the default value for parameters marked optional."
10
+
11
+ def __init__(self, value):
12
+ self.value = value
13
+
14
+
15
+ class dispid(int):
16
+ "Specifies the DISPID of a method or property."
17
+
18
+
19
+ # XXX STDMETHOD, COMMETHOD, DISPMETHOD, and DISPPROPERTY should return
20
+ # instances with more methods or properties, and should not behave as an unpackable.
21
+
22
+
23
+ def STDMETHOD(restype, name, argtypes=()) -> _ComMemberSpec:
24
+ "Specifies a COM method slot without idlflags"
25
+ return _ComMemberSpec(restype, name, argtypes, None, (), None)
26
+
27
+
28
+ def DISPMETHOD(idlflags, restype, name, *argspec) -> _DispMemberSpec:
29
+ "Specifies a method of a dispinterface"
30
+ return _DispMemberSpec("DISPMETHOD", name, tuple(idlflags), restype, argspec)
31
+
32
+
33
+ def DISPPROPERTY(idlflags, proptype, name) -> _DispMemberSpec:
34
+ "Specifies a property of a dispinterface"
35
+ return _DispMemberSpec("DISPPROPERTY", name, tuple(idlflags), proptype, ())
36
+
37
+
38
+ # tuple(idlflags) is for the method itself: (dispid, 'readonly')
39
+
40
+ # sample generated code:
41
+ # DISPPROPERTY([5, 'readonly'], OLE_YSIZE_HIMETRIC, 'Height'),
42
+ # DISPMETHOD(
43
+ # [6], None, 'Render', ([], c_int, 'hdc'), ([], c_int, 'x'), ([], c_int, 'y')
44
+ # )
45
+
46
+
47
+ def COMMETHOD(idlflags, restype, methodname, *argspec) -> _ComMemberSpec:
48
+ """Specifies a COM method slot with idlflags.
49
+
50
+ XXX should explain the sematics of the arguments.
51
+ """
52
+ # collect all helpstring instances
53
+ # We should suppress docstrings when Python is started with -OO
54
+ # join them together(does this make sense?) and replace by None if empty.
55
+ helptext = "".join(t for t in idlflags if isinstance(t, helpstring)) or None
56
+ paramflags, argtypes = _resolve_argspec(argspec)
57
+ if "propget" in idlflags:
58
+ name = "_get_%s" % methodname
59
+ elif "propput" in idlflags:
60
+ name = "_set_%s" % methodname
61
+ elif "propputref" in idlflags:
62
+ name = "_setref_%s" % methodname
63
+ else:
64
+ name = methodname
65
+ return _ComMemberSpec(
66
+ restype, name, argtypes, paramflags, tuple(idlflags), helptext
67
+ )
@@ -1,16 +1,8 @@
1
1
  import ctypes
2
- from typing import (
3
- Any,
4
- Callable,
5
- Dict,
6
- Iterator,
7
- List,
8
- NamedTuple,
9
- Optional,
10
- Tuple,
11
- Type,
12
- Union as _UnionT,
13
- )
2
+ from typing import Any, NamedTuple
3
+ from typing import Dict, List, Tuple, Type
4
+ from typing import Optional, Union as _UnionT
5
+ from typing import Callable, Iterator
14
6
 
15
7
  from comtypes import _CData
16
8
  import comtypes
@@ -0,0 +1,15 @@
1
+ """comtypes._post_coinit
2
+
3
+ This subpackage contains symbols that should be imported into `comtypes/__init__.py`
4
+ after `CoInitializeEx` is defined and called, and symbols that can be defined in
5
+ any order during the initialization of the `comtypes` package.
6
+
7
+ These were previously defined in `comtypes/__init__.py`, but due to the codebase
8
+ of the file becoming bloated, reducing the ease of changes and increasing
9
+ cognitive load, they have been moved here.
10
+
11
+ This subpackage is called simultaneously with the initialization of `comtypes`.
12
+ So it is necessary to maintain minimal settings to keep the lightweight action
13
+ when the package is initialized.
14
+ """
15
+ from comtypes._post_coinit.unknwn import _shutdown # noqa
@@ -0,0 +1,30 @@
1
+ from ctypes import _SimpleCData, windll
2
+
3
+
4
+ class BSTR(_SimpleCData):
5
+ "The windows BSTR data type"
6
+ _type_ = "X"
7
+ _needsfree = False
8
+
9
+ def __repr__(self):
10
+ return "%s(%r)" % (self.__class__.__name__, self.value)
11
+
12
+ def __ctypes_from_outparam__(self):
13
+ self._needsfree = True
14
+ return self.value
15
+
16
+ def __del__(self, _free=windll.oleaut32.SysFreeString):
17
+ # Free the string if self owns the memory
18
+ # or if instructed by __ctypes_from_outparam__.
19
+ if self._b_base_ is None or self._needsfree:
20
+ _free(self)
21
+
22
+ @classmethod
23
+ def from_param(cls, value):
24
+ """Convert into a foreign function call parameter."""
25
+ if isinstance(value, cls):
26
+ return value
27
+ # Although the builtin SimpleCData.from_param call does the
28
+ # right thing, it doesn't ensure that SysFreeString is called
29
+ # on destruction.
30
+ return cls(value)