comtypes 1.4.9__zip → 1.4.10__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 (146) hide show
  1. {comtypes-1.4.9 → comtypes-1.4.10}/CHANGES.txt +19 -0
  2. {comtypes-1.4.9/comtypes.egg-info → comtypes-1.4.10}/PKG-INFO +3 -2
  3. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/GUID.py +34 -13
  4. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/__init__.py +22 -13
  5. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_comobject.py +69 -14
  6. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_memberspec.py +14 -6
  7. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_meta.py +1 -0
  8. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/_cominterface_meta_patcher.py +0 -1
  9. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/bstr.py +12 -5
  10. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/instancemethod.py +1 -2
  11. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/misc.py +59 -24
  12. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/unknwn.py +2 -6
  13. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_safearray.py +2 -2
  14. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/automation.py +10 -4
  15. comtypes-1.4.10/comtypes/client/__init__.py +42 -0
  16. comtypes-1.4.10/comtypes/client/_activeobj.py +46 -0
  17. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_code_cache.py +6 -1
  18. comtypes-1.4.10/comtypes/client/_create.py +147 -0
  19. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_events.py +57 -12
  20. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_generate.py +3 -3
  21. comtypes-1.4.10/comtypes/client/_managing.py +114 -0
  22. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/dynamic.py +2 -3
  23. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/lazybind.py +10 -11
  24. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/connectionpoints.py +2 -1
  25. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/errorinfo.py +20 -7
  26. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/git.py +4 -3
  27. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/logutil.py +15 -3
  28. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/messageloop.py +1 -1
  29. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/persist.py +3 -5
  30. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/safearray.py +8 -6
  31. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/__init__.py +22 -4
  32. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/automation.py +1 -2
  33. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/connectionpoints.py +5 -5
  34. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/inprocserver.py +6 -3
  35. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/localserver.py +23 -5
  36. comtypes-1.4.10/comtypes/server/register.py +478 -0
  37. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/shelllink.py +13 -7
  38. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/stream.py +7 -4
  39. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestComServer.py +6 -7
  40. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestDispServer.py +4 -2
  41. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/__init__.py +1 -1
  42. comtypes-1.4.10/comtypes/test/find_memleak.py +72 -0
  43. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/runtests.py +1 -0
  44. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/setup.py +2 -1
  45. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_BSTR.py +7 -17
  46. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_GUID.py +1 -0
  47. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_QueryService.py +1 -0
  48. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_agilent.py +4 -3
  49. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_basic.py +12 -6
  50. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_clear_cache.py +1 -1
  51. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_client.py +2 -2
  52. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_client_dynamic.py +2 -2
  53. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_client_regenerate_modules.py +2 -2
  54. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_collections.py +1 -1
  55. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_comobject.py +4 -4
  56. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_comserver.py +31 -1
  57. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dispifc_records.py +1 -1
  58. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dispifc_safearrays.py +1 -1
  59. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dyndispatch.py +1 -0
  60. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_findgendir.py +1 -2
  61. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_getactiveobj.py +4 -4
  62. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_ie.py +19 -6
  63. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_ienum.py +2 -2
  64. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_imfattributes.py +13 -3
  65. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_inout_args.py +1 -1
  66. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_midl_safearray_create.py +6 -4
  67. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_monikers.py +23 -9
  68. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_msscript.py +2 -1
  69. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_npsupport.py +4 -4
  70. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_outparam.py +22 -6
  71. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_persist.py +2 -4
  72. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_recordinfo.py +1 -1
  73. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_sapi.py +4 -1
  74. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_server_register.py +113 -125
  75. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_shelllink.py +2 -3
  76. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_storage.py +12 -6
  77. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_stream.py +16 -5
  78. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_subinterface.py +4 -2
  79. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_typeannotator.py +1 -2
  80. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_typeinfo.py +19 -7
  81. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_urlhistory.py +7 -4
  82. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_variant.py +3 -2
  83. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_word.py +1 -1
  84. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/codegenerator.py +167 -435
  85. comtypes-1.4.10/comtypes/tools/codegenerator/comments.py +79 -0
  86. comtypes-1.4.10/comtypes/tools/codegenerator/heads.py +192 -0
  87. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/helpers.py +3 -6
  88. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/namespaces.py +13 -5
  89. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/typeannotator.py +13 -3
  90. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/tlbparser.py +22 -23
  91. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/typedesc.py +3 -2
  92. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/typedesc_base.py +2 -2
  93. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/typeinfo.py +149 -42
  94. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/viewobject.py +2 -4
  95. {comtypes-1.4.9 → comtypes-1.4.10/comtypes.egg-info}/PKG-INFO +3 -2
  96. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/SOURCES.txt +5 -0
  97. {comtypes-1.4.9 → comtypes-1.4.10}/pyproject.toml +11 -19
  98. comtypes-1.4.9/comtypes/client/__init__.py +0 -323
  99. comtypes-1.4.9/comtypes/server/register.py +0 -419
  100. comtypes-1.4.9/comtypes/test/find_memleak.py +0 -76
  101. {comtypes-1.4.9 → comtypes-1.4.10}/LICENSE.txt +0 -0
  102. {comtypes-1.4.9 → comtypes-1.4.10}/MANIFEST.in +0 -0
  103. {comtypes-1.4.9 → comtypes-1.4.10}/README.md +0 -0
  104. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_npsupport.py +0 -0
  105. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/__init__.py +0 -0
  106. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_tlib_version_checker.py +0 -0
  107. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_vtbl.py +0 -0
  108. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/clear_cache.py +0 -0
  109. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_constants.py +0 -0
  110. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/hints.pyi +0 -0
  111. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/hresult.py +0 -0
  112. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/patcher.py +0 -0
  113. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/w_getopt.py +0 -0
  114. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestComServer.idl +0 -0
  115. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestComServer.tlb +0 -0
  116. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestDispServer.idl +0 -0
  117. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestDispServer.tlb +0 -0
  118. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/mylib.idl +0 -0
  119. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/mylib.tlb +0 -0
  120. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/mytypelib.idl +0 -0
  121. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_DISPPARAMS.py +0 -0
  122. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_avmc.py +0 -0
  123. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_casesensitivity.py +0 -0
  124. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_createwrappers.py +0 -0
  125. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dict.py +0 -0
  126. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dispinterface.py +0 -0
  127. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_excel.py +0 -0
  128. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_jscript.js +0 -0
  129. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_pump_events.py +0 -0
  130. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_safearray.py +0 -0
  131. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_server.py +0 -0
  132. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_showevents.py +0 -0
  133. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_w_getopt.py +0 -0
  134. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_win32com_interop.py +0 -0
  135. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_wmi.py +0 -0
  136. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/urlhist.tlb +0 -0
  137. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/__init__.py +0 -0
  138. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/__init__.py +0 -0
  139. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/modulenamer.py +0 -0
  140. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/packing.py +0 -0
  141. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/util.py +0 -0
  142. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/dependency_links.txt +0 -0
  143. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/entry_points.txt +0 -0
  144. {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/top_level.txt +0 -0
  145. {comtypes-1.4.9 → comtypes-1.4.10}/setup.cfg +0 -0
  146. {comtypes-1.4.9 → comtypes-1.4.10}/setup.py +0 -0
@@ -1,11 +1,17 @@
1
- from ctypes import c_char_p, c_int, c_short, c_wchar_p
2
- from ctypes import POINTER
3
- from ctypes import byref, create_string_buffer, create_unicode_buffer
4
- from ctypes.wintypes import DWORD, WIN32_FIND_DATAA, WIN32_FIND_DATAW, MAX_PATH
5
- from typing import Tuple, TYPE_CHECKING, Literal
6
-
7
- from comtypes import IUnknown, GUID, COMMETHOD, HRESULT, CoClass
1
+ from ctypes import (
2
+ POINTER,
3
+ byref,
4
+ c_char_p,
5
+ c_int,
6
+ c_short,
7
+ c_wchar_p,
8
+ create_string_buffer,
9
+ create_unicode_buffer,
10
+ )
11
+ from ctypes.wintypes import DWORD, MAX_PATH, WIN32_FIND_DATAA, WIN32_FIND_DATAW
12
+ from typing import TYPE_CHECKING, Literal, Tuple
8
13
 
14
+ from comtypes import COMMETHOD, GUID, HRESULT, CoClass, IUnknown
9
15
 
10
16
  if TYPE_CHECKING:
11
17
  from comtypes import hints # type: ignore
@@ -1,8 +1,11 @@
1
- from ctypes import Array, c_ubyte, c_ulong, HRESULT, POINTER, pointer
2
- from typing import Tuple, TYPE_CHECKING
1
+ from ctypes import HRESULT, POINTER, c_ubyte, c_ulong, pointer
2
+ from typing import TYPE_CHECKING, Tuple
3
3
 
4
4
  from comtypes import COMMETHOD, GUID, IUnknown
5
5
 
6
+ if TYPE_CHECKING:
7
+ from ctypes import Array as _CArrayType
8
+
6
9
 
7
10
  class ISequentialStream(IUnknown):
8
11
  """Defines methods for the stream objects in sequence."""
@@ -38,7 +41,7 @@ class ISequentialStream(IUnknown):
38
41
  ),
39
42
  ]
40
43
 
41
- def RemoteRead(self, cb: int) -> Tuple["Array[c_ubyte]", int]:
44
+ def RemoteRead(self, cb: int) -> Tuple["_CArrayType[c_ubyte]", int]:
42
45
  """Reads a specified number of bytes from the stream object into memory
43
46
  starting at the current seek pointer.
44
47
  """
@@ -51,7 +54,7 @@ class ISequentialStream(IUnknown):
51
54
 
52
55
  if TYPE_CHECKING:
53
56
 
54
- def RemoteWrite(self, pv: "Array[c_ubyte]", cb: int) -> int:
57
+ def RemoteWrite(self, pv: "_CArrayType[c_ubyte]", cb: int) -> int:
55
58
  """Writes a specified number of bytes into the stream object starting at
56
59
  the current seek pointer.
57
60
  """
@@ -1,5 +1,6 @@
1
- import sys, os
2
1
  import logging
2
+ import os
3
+ import sys
3
4
 
4
5
  logging.basicConfig()
5
6
  ##logging.basicConfig(level=logging.DEBUG)
@@ -7,14 +8,14 @@ logging.basicConfig()
7
8
 
8
9
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), r"..\..")))
9
10
 
10
- import ctypes
11
11
  import comtypes
12
- from comtypes.hresult import *
13
12
  import comtypes.client
13
+ import comtypes.connectionpoints
14
14
  import comtypes.errorinfo
15
15
  import comtypes.server
16
16
  import comtypes.server.connectionpoints
17
17
  import comtypes.typeinfo
18
+ from comtypes.hresult import S_OK
18
19
 
19
20
  ################################################################
20
21
 
@@ -30,6 +31,7 @@ if not hasattr(sys, "frozen"):
30
31
 
31
32
  # Import the wrapper
32
33
  from comtypes.gen import TestComServerLib
34
+ from comtypes.gen.TestComServerLib import ITestComServer # noqa
33
35
 
34
36
  ################################################################
35
37
 
@@ -151,7 +153,4 @@ if __name__ == "__main__":
151
153
  import traceback
152
154
 
153
155
  traceback.print_exc()
154
- if sys.version_info >= (3, 0):
155
- input()
156
- else:
157
- raw_input()
156
+ input()
@@ -1,5 +1,6 @@
1
- import sys, os
2
1
  import logging
2
+ import os
3
+ import sys
3
4
 
4
5
  logging.basicConfig()
5
6
  ##logging.basicConfig(level=logging.DEBUG)
@@ -9,8 +10,9 @@ logging.basicConfig()
9
10
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), r"..\..")))
10
11
 
11
12
  import comtypes
12
- from comtypes.hresult import S_OK
13
+ import comtypes.connectionpoints
13
14
  import comtypes.server.connectionpoints
15
+ from comtypes.hresult import S_OK
14
16
 
15
17
  ################################################################
16
18
 
@@ -119,8 +119,8 @@ def usage():
119
119
 
120
120
  def test_with_refcounts(runner, verbosity, testcase):
121
121
  """Run testcase several times, tracking reference counts."""
122
- import gc
123
122
  import ctypes
123
+ import gc
124
124
 
125
125
  ptc = ctypes._pointer_type_cache.copy()
126
126
  cfc = ctypes._c_functype_cache.copy()
@@ -0,0 +1,72 @@
1
+ import gc
2
+ from ctypes import POINTER, Structure, WinDLL, WinError, byref, c_size_t, sizeof
3
+ from ctypes.wintypes import BOOL, DWORD, HANDLE
4
+
5
+ ################################################################
6
+
7
+
8
+ class PROCESS_MEMORY_COUNTERS(Structure):
9
+ _fields_ = [
10
+ ("cb", DWORD),
11
+ ("PageFaultCount", DWORD),
12
+ ("PeakWorkingSetSize", c_size_t),
13
+ ("WorkingSetSize", c_size_t),
14
+ ("QuotaPeakPagedPoolUsage", c_size_t),
15
+ ("QuotaPagedPoolUsage", c_size_t),
16
+ ("QuotaPeakNonPagedPoolUsage", c_size_t),
17
+ ("QuotaNonPagedPoolUsage", c_size_t),
18
+ ("PagefileUsage", c_size_t),
19
+ ("PeakPagefileUsage", c_size_t),
20
+ ]
21
+
22
+ def __init__(self):
23
+ self.cb = sizeof(self)
24
+
25
+ def dump(self):
26
+ for n, _ in self._fields_[2:]:
27
+ print(n, getattr(self, n) / 1e6)
28
+
29
+
30
+ _psapi = WinDLL("psapi")
31
+
32
+ _GetProcessMemoryInfo = _psapi.GetProcessMemoryInfo
33
+ _GetProcessMemoryInfo.argtypes = [HANDLE, POINTER(PROCESS_MEMORY_COUNTERS), DWORD]
34
+ _GetProcessMemoryInfo.restype = BOOL
35
+
36
+
37
+ def wss():
38
+ # Return the working set size (memory used by process)
39
+ pmi = PROCESS_MEMORY_COUNTERS()
40
+ if not _GetProcessMemoryInfo(-1, byref(pmi), sizeof(pmi)):
41
+ raise WinError()
42
+ return pmi.WorkingSetSize
43
+
44
+
45
+ LOOPS = 10, 1000
46
+
47
+
48
+ def find_memleak(func, loops=LOOPS):
49
+ # call 'func' several times, so that memory consumption
50
+ # stabilizes:
51
+ for j in range(loops[0]):
52
+ for k in range(loops[1]):
53
+ func()
54
+ gc.collect()
55
+ gc.collect()
56
+ gc.collect()
57
+ bytes = wss()
58
+ # call 'func' several times, recording the difference in
59
+ # memory consumption before and after the call. Repeat this a
60
+ # few times, and return a list containing the memory
61
+ # consumption differences.
62
+ for j in range(loops[0]):
63
+ for k in range(loops[1]):
64
+ func()
65
+ gc.collect()
66
+ gc.collect()
67
+ gc.collect()
68
+ # return the increased in process size
69
+ result = wss() - bytes
70
+ # Sometimes the process size did decrease, we do not report leaks
71
+ # in this case:
72
+ return max(result, 0)
@@ -1,4 +1,5 @@
1
1
  import sys
2
+
2
3
  import comtypes.test
3
4
 
4
5
 
@@ -1,6 +1,7 @@
1
1
  # all the unittests can be converted to exe-files.
2
- from distutils.core import setup
3
2
  import glob
3
+ from distutils.core import setup
4
+
4
5
  import py2exe
5
6
 
6
7
  setup(name="test_*", console=glob.glob("test_*.py"))
@@ -1,5 +1,6 @@
1
1
  import unittest
2
- from ctypes import WINFUNCTYPE, c_uint, c_void_p, oledll, windll
2
+ from ctypes import WinDLL
3
+ from ctypes.wintypes import UINT
3
4
 
4
5
  from comtypes import BSTR
5
6
  from comtypes.test.find_memleak import find_memleak
@@ -24,23 +25,12 @@ class Test(unittest.TestCase):
24
25
 
25
26
  self.check_leaks(doit)
26
27
 
27
- def test_paramflags(self):
28
- prototype = WINFUNCTYPE(c_void_p, BSTR)
29
- func = prototype(("SysStringLen", oledll.oleaut32))
30
- func.restype = c_void_p
31
- func.argtypes = (BSTR,)
32
-
33
- def doit():
34
- func("abcdef")
35
- func("abc xyz")
36
- func(BSTR("abc def"))
37
-
38
- self.check_leaks(doit)
39
-
40
28
  def test_inargs(self):
41
- SysStringLen = windll.oleaut32.SysStringLen
42
- SysStringLen.argtypes = (BSTR,)
43
- SysStringLen.restype = c_uint
29
+ oleaut32 = WinDLL("oleaut32")
30
+
31
+ SysStringLen = oleaut32.SysStringLen
32
+ SysStringLen.argtypes = [BSTR]
33
+ SysStringLen.restype = UINT
44
34
 
45
35
  self.assertEqual(SysStringLen("abc xyz"), 7)
46
36
 
@@ -1,4 +1,5 @@
1
1
  import unittest
2
+
2
3
  from comtypes import GUID
3
4
 
4
5
 
@@ -1,5 +1,6 @@
1
1
  import unittest
2
2
  from ctypes import POINTER
3
+
3
4
  import comtypes
4
5
  from comtypes.client import CreateObject, GetModule
5
6
 
@@ -3,11 +3,12 @@
3
3
  # connected, the driver is used in simulation mode.
4
4
 
5
5
  import unittest
6
- from comtypes.test import ResourceDenied
7
- from comtypes.client import CreateObject
6
+ from ctypes import POINTER, c_double
7
+
8
8
  from comtypes import GUID
9
+ from comtypes.client import CreateObject
9
10
  from comtypes.safearray import _midlSAFEARRAY
10
- from ctypes import c_double, POINTER
11
+ from comtypes.test import ResourceDenied
11
12
 
12
13
  try:
13
14
  GUID.from_progid("Agilent546XX.Agilent546XX")
@@ -1,7 +1,9 @@
1
1
  ##import ut
2
2
  import unittest as ut
3
- from ctypes import windll, POINTER, byref, HRESULT
4
- from comtypes import IUnknown, STDMETHOD, GUID
3
+ from ctypes import HRESULT, POINTER, byref
4
+
5
+ from comtypes import GUID, STDMETHOD, IUnknown
6
+ from comtypes.typeinfo import ICreateTypeLib2, _CreateTypeLib2
5
7
 
6
8
  # XXX leaks references!
7
9
 
@@ -20,8 +22,10 @@ class BasicTest(ut.TestCase):
20
22
  POINTER(IUnknown)()
21
23
 
22
24
  def test_refcounts(self):
23
- p = POINTER(IUnknown)()
24
- windll.oleaut32.CreateTypeLib2(1, "blabla", byref(p))
25
+ # Since all COM interfaces derive from IUnknown and have the same reference counting behavior, any interface
26
+ # — whether ICreateTypeLib2 or otherwise — could be used for this test.
27
+ p = POINTER(ICreateTypeLib2)()
28
+ _CreateTypeLib2(1, "blabla", byref(p))
25
29
  # initial refcount is 2
26
30
  for i in range(2, 10):
27
31
  self.assertEqual(p.AddRef(), i)
@@ -29,8 +33,10 @@ class BasicTest(ut.TestCase):
29
33
  self.assertEqual(p.Release(), i)
30
34
 
31
35
  def test_qi(self):
32
- p = POINTER(IUnknown)()
33
- windll.oleaut32.CreateTypeLib2(1, "blabla", byref(p))
36
+ # Since all COM interfaces derive from IUnknown and have the same QueryInterface behavior, any interface
37
+ # — whether ICreateTypeLib2 or otherwise — could be used for this test.
38
+ p = POINTER(ICreateTypeLib2)()
39
+ _CreateTypeLib2(1, "blabla", byref(p))
34
40
  self.assertEqual(p.AddRef(), 2)
35
41
  self.assertEqual(p.Release(), 1)
36
42
 
@@ -4,8 +4,8 @@ Test for the ``comtypes.clear_cache`` module.
4
4
 
5
5
  import contextlib
6
6
  import runpy
7
- from unittest.mock import patch, call
8
7
  from unittest import TestCase
8
+ from unittest.mock import call, patch
9
9
 
10
10
  from comtypes.client import _find_gen_dir
11
11
 
@@ -1,11 +1,11 @@
1
1
  import contextlib
2
- from ctypes import POINTER, byref
3
2
  import os
4
3
  import sys
5
4
  import unittest as ut
5
+ from ctypes import POINTER, byref
6
6
 
7
7
  import comtypes.client
8
- from comtypes import COSERVERINFO, CLSCTX_INPROC_SERVER
8
+ from comtypes import CLSCTX_INPROC_SERVER, COSERVERINFO
9
9
 
10
10
  # create the typelib wrapper and import it
11
11
  comtypes.client.GetModule("scrrun.dll")
@@ -2,8 +2,8 @@ import ctypes
2
2
  import unittest as ut
3
3
  from unittest import mock
4
4
 
5
- from comtypes import automation, COMError, IUnknown
6
- from comtypes.client import CreateObject, dynamic, GetModule, lazybind
5
+ from comtypes import COMError, IUnknown, automation
6
+ from comtypes.client import CreateObject, GetModule, dynamic, lazybind
7
7
 
8
8
 
9
9
  class Test_Dispatch_Function(ut.TestCase):
@@ -1,12 +1,12 @@
1
1
  import contextlib
2
2
  import importlib
3
- from pathlib import Path
4
3
  import shutil
5
4
  import sys
6
5
  import tempfile
7
6
  import types
8
- from typing import Iterator
9
7
  import unittest as ut
8
+ from pathlib import Path
9
+ from typing import Iterator
10
10
  from unittest import mock
11
11
 
12
12
  import comtypes
@@ -1,7 +1,7 @@
1
1
  import unittest
2
- from comtypes.client import CreateObject
3
2
  from ctypes import ArgumentError
4
3
 
4
+ from comtypes.client import CreateObject
5
5
  from comtypes.test.find_memleak import find_memleak
6
6
 
7
7
 
@@ -3,9 +3,9 @@ import unittest as ut
3
3
  from ctypes import POINTER, byref, pointer
4
4
  from unittest import mock
5
5
 
6
- import comtypes
7
6
  import comtypes.client
8
- from comtypes import COMObject, IUnknown, hresult
7
+ from comtypes import CLSCTX_SERVER, COMObject, IUnknown, hresult
8
+ from comtypes._post_coinit.misc import _CoCreateInstance
9
9
  from comtypes.automation import IDispatch
10
10
 
11
11
  comtypes.client.GetModule("UIAutomationCore.dll")
@@ -54,10 +54,10 @@ class Test_IUnknown_QueryInterface(ut.TestCase):
54
54
 
55
55
  def test_valid_pointer(self):
56
56
  ptr = ctypes.c_void_p()
57
- ctypes.oledll.ole32.CoCreateInstance(
57
+ _CoCreateInstance(
58
58
  byref(scrrun.Dictionary._reg_clsid_),
59
59
  None,
60
- comtypes.CLSCTX_SERVER,
60
+ CLSCTX_SERVER,
61
61
  byref(scrrun.IDictionary._iid_),
62
62
  byref(ptr),
63
63
  )
@@ -3,10 +3,11 @@ import unittest
3
3
  from ctypes import pointer
4
4
  from typing import Any
5
5
 
6
+ import comtypes.server
6
7
  import comtypes.test.TestComServer
7
8
  from comtypes import BSTR
8
9
  from comtypes.automation import VARIANT, _midlSAFEARRAY
9
- from comtypes.client import CreateObject
10
+ from comtypes.client import CreateObject, GetActiveObject
10
11
  from comtypes.server.register import register, unregister
11
12
  from comtypes.test.find_memleak import find_memleak
12
13
 
@@ -171,6 +172,35 @@ class TestLocalServer_win32com(BaseServerTest, unittest.TestCase):
171
172
  pass
172
173
 
173
174
 
175
+ class ActiveObjTest(unittest.TestCase):
176
+ def get_active_object(self) -> comtypes.test.TestComServer.ITestComServer:
177
+ return GetActiveObject(
178
+ comtypes.test.TestComServer.TestComServer,
179
+ interface=comtypes.test.TestComServer.ITestComServer,
180
+ )
181
+
182
+ def _doit(self, weak: bool):
183
+ comobj = comtypes.test.TestComServer.TestComServer()
184
+ with self.assertRaises(OSError):
185
+ self.get_active_object()
186
+ handle = comtypes.server.RegisterActiveObject(comobj, weak=weak)
187
+ activeobj = self.get_active_object()
188
+ self.assertEqual(activeobj.MixedInOut(2, 4), (3, 5))
189
+ self.assertEqual(activeobj.AddRef(), 3)
190
+ self.assertEqual(activeobj.Release(), 2)
191
+ punk = comobj.QueryInterface(comtypes.test.TestComServer.ITestComServer)
192
+ self.assertEqual(activeobj, punk)
193
+ comtypes.server.RevokeActiveObject(handle)
194
+ with self.assertRaises(OSError):
195
+ self.get_active_object()
196
+
197
+ def test_activeobj_weak_registration(self):
198
+ self._doit(weak=True)
199
+
200
+ def test_activeobj_strong_registration(self):
201
+ self._doit(weak=False)
202
+
203
+
174
204
  class VariantTest(unittest.TestCase):
175
205
  def test_UDT(self):
176
206
  from comtypes.gen.TestComServerLib import MYCOLOR
@@ -1,10 +1,10 @@
1
1
  # coding: utf-8
2
2
 
3
3
  import unittest
4
+ from ctypes import byref, pointer
4
5
 
5
6
  from comtypes import CLSCTX_LOCAL_SERVER
6
7
  from comtypes.client import CreateObject, GetModule
7
- from ctypes import byref, pointer
8
8
 
9
9
  ComtypesCppTestSrvLib_GUID = "{07D2AEE5-1DF8-4D2C-953A-554ADFD25F99}"
10
10
 
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
- from ctypes import byref, c_double, pointer
4
3
  import unittest
4
+ from ctypes import byref, c_double, pointer
5
5
 
6
6
  import comtypes
7
7
  import comtypes.safearray
@@ -1,4 +1,5 @@
1
1
  import unittest
2
+
2
3
  from comtypes.automation import IDispatch
3
4
  from comtypes.client import CreateObject, GetModule
4
5
  from comtypes.client.lazybind import Dispatch
@@ -4,15 +4,14 @@ import os
4
4
  import sys
5
5
  import tempfile
6
6
  import types
7
- from typing import Iterator
8
7
  import unittest
8
+ from typing import Iterator
9
9
  from unittest import mock
10
10
 
11
11
  import comtypes
12
12
  import comtypes.client
13
13
  import comtypes.gen
14
14
 
15
-
16
15
  IMGBASE = os.path.splitext(os.path.basename(sys.executable))[0]
17
16
 
18
17
 
@@ -8,9 +8,9 @@ import comtypes.test
8
8
  try:
9
9
  # pass Word libUUID
10
10
  comtypes.client.GetModule(("{00020905-0000-0000-C000-000000000046}",))
11
- IMPORT_FAILED = False
11
+ IMPORT_WORD_FAILED = False
12
12
  except (ImportError, OSError):
13
- IMPORT_FAILED = True
13
+ IMPORT_WORD_FAILED = True
14
14
 
15
15
 
16
16
  ################################################################
@@ -24,8 +24,8 @@ except (ImportError, OSError):
24
24
  ################################################################
25
25
 
26
26
 
27
- @unittest.skipIf(IMPORT_FAILED, "This depends on Word.")
28
- class Test(unittest.TestCase):
27
+ @unittest.skipIf(IMPORT_WORD_FAILED, "This depends on Word.")
28
+ class Test_Word(unittest.TestCase):
29
29
  def setUp(self):
30
30
  try:
31
31
  comtypes.client.GetActiveObject("Word.Application")
@@ -1,5 +1,6 @@
1
1
  import unittest as ut
2
- from ctypes import Structure, c_long, c_uint, c_ulong
2
+ from ctypes import POINTER, Structure, WinDLL, byref, c_long, c_uint, c_ulong
3
+ from ctypes.wintypes import BOOL, HWND, LPLONG, UINT
3
4
 
4
5
  from comtypes.client import CreateObject, GetEvents
5
6
 
@@ -58,14 +59,26 @@ class MSG(Structure):
58
59
 
59
60
 
60
61
  def PumpWaitingMessages():
61
- from ctypes import byref, windll
62
+ _user32 = WinDLL("user32")
63
+
64
+ _PeekMessageA = _user32.PeekMessageA
65
+ _PeekMessageA.argtypes = [POINTER(MSG), HWND, UINT, UINT, UINT]
66
+ _PeekMessageA.restype = BOOL
67
+
68
+ _TranslateMessage = _user32.TranslateMessage
69
+ _TranslateMessage.argtypes = [POINTER(MSG)]
70
+ _TranslateMessage.restype = BOOL
71
+
72
+ LRESULT = LPLONG
73
+ _DispatchMessageA = _user32.DispatchMessageA
74
+ _DispatchMessageA.argtypes = [POINTER(MSG)]
75
+ _DispatchMessageA.restype = LRESULT
62
76
 
63
- user32 = windll.user32
64
77
  msg = MSG()
65
78
  PM_REMOVE = 0x0001
66
- while user32.PeekMessageA(byref(msg), 0, 0, 0, PM_REMOVE):
67
- user32.TranslateMessage(byref(msg))
68
- user32.DispatchMessageA(byref(msg))
79
+ while _PeekMessageA(byref(msg), 0, 0, 0, PM_REMOVE):
80
+ _TranslateMessage(byref(msg))
81
+ _DispatchMessageA(byref(msg))
69
82
 
70
83
 
71
84
  class Test(ut.TestCase):
@@ -1,9 +1,9 @@
1
1
  import contextlib
2
2
  import unittest as ut
3
-
4
3
  from ctypes import POINTER
5
- from comtypes import GUID
4
+
6
5
  import comtypes.client
6
+ from comtypes import GUID
7
7
 
8
8
 
9
9
  class Test_IEnum(ut.TestCase):
@@ -1,9 +1,9 @@
1
1
  import contextlib
2
2
  import unittest as ut
3
+ from ctypes import HRESULT, POINTER, WinDLL, c_uint32, pointer
3
4
 
4
- from ctypes import POINTER, pointer, windll
5
- from comtypes import GUID
6
5
  import comtypes.client
6
+ from comtypes import GUID
7
7
 
8
8
 
9
9
  class Test_IMFAttributes(ut.TestCase):
@@ -12,8 +12,18 @@ class Test_IMFAttributes(ut.TestCase):
12
12
  comtypes.client.GetModule("msvidctl.dll")
13
13
  from comtypes.gen import MSVidCtlLib
14
14
 
15
+ _mfplat = WinDLL("mfplat")
16
+
17
+ UINT32 = c_uint32
18
+ _MFCreateAttributes = _mfplat.MFCreateAttributes
19
+ _MFCreateAttributes.argtypes = [
20
+ POINTER(POINTER(MSVidCtlLib.IMFAttributes)),
21
+ UINT32,
22
+ ]
23
+ _MFCreateAttributes.restype = HRESULT
24
+
15
25
  imf_attrs = POINTER(MSVidCtlLib.IMFAttributes)()
16
- hres = windll.mfplat.MFCreateAttributes(pointer(imf_attrs), 2)
26
+ hres = _MFCreateAttributes(pointer(imf_attrs), 2)
17
27
  self.assertEqual(hres, 0)
18
28
 
19
29
  MF_TRANSCODE_ADJUST_PROFILE = GUID("{9c37c21b-060f-487c-a690-80d7f50d1c72}")
@@ -4,8 +4,8 @@ from typing import TYPE_CHECKING, Any, Callable, List, NamedTuple, Tuple, Type
4
4
  from unittest.mock import MagicMock
5
5
 
6
6
  import comtypes
7
+ from comtypes import IUnknown
7
8
  from comtypes._memberspec import _fix_inout_args
8
- from comtypes.client import IUnknown
9
9
 
10
10
  if TYPE_CHECKING:
11
11
  from comtypes._memberspec import _ArgSpecElmType
@@ -1,13 +1,13 @@
1
1
  # coding: utf-8
2
2
 
3
- from ctypes import c_int, pointer, HRESULT, POINTER
4
3
  import unittest
4
+ from ctypes import HRESULT, POINTER, c_int, pointer
5
5
 
6
6
  import comtypes
7
7
  import comtypes.safearray
8
+ import comtypes.typeinfo
8
9
  from comtypes import CLSCTX_INPROC_SERVER, CLSCTX_LOCAL_SERVER
9
10
  from comtypes.client import CreateObject, GetModule
10
- import comtypes.typeinfo
11
11
 
12
12
  GetModule("UIAutomationCore.dll")
13
13
  from comtypes.gen.UIAutomationClient import CUIAutomation, IUIAutomation
@@ -16,8 +16,10 @@ ComtypesCppTestSrvLib_GUID = "{07D2AEE5-1DF8-4D2C-953A-554ADFD25F99}"
16
16
 
17
17
  try:
18
18
  GetModule((ComtypesCppTestSrvLib_GUID, 1, 0, 0))
19
- from comtypes.gen.ComtypesCppTestSrvLib import StructRecordParamTest
20
- from comtypes.gen.ComtypesCppTestSrvLib import IDispSafearrayParamTest
19
+ from comtypes.gen.ComtypesCppTestSrvLib import (
20
+ IDispSafearrayParamTest,
21
+ StructRecordParamTest,
22
+ )
21
23
 
22
24
  IMPORT_FAILED = False
23
25
  except (ImportError, OSError):