comtypes 1.4.8__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 (154) hide show
  1. {comtypes-1.4.8 → comtypes-1.4.10}/CHANGES.txt +40 -0
  2. {comtypes-1.4.8/comtypes.egg-info → comtypes-1.4.10}/PKG-INFO +4 -3
  3. {comtypes-1.4.8 → comtypes-1.4.10}/README.md +1 -1
  4. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/GUID.py +38 -16
  5. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/__init__.py +36 -16
  6. comtypes-1.4.10/comtypes/_comobject.py +562 -0
  7. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_memberspec.py +93 -13
  8. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_meta.py +1 -0
  9. comtypes-1.4.10/comtypes/_post_coinit/_cominterface_meta_patcher.py +152 -0
  10. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/bstr.py +12 -5
  11. comtypes-1.4.8/comtypes/_py_instance_method.py → comtypes-1.4.10/comtypes/_post_coinit/instancemethod.py +1 -2
  12. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/misc.py +60 -25
  13. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/unknwn.py +26 -176
  14. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_safearray.py +3 -4
  15. comtypes-1.4.10/comtypes/_vtbl.py +448 -0
  16. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/automation.py +46 -49
  17. comtypes-1.4.10/comtypes/client/__init__.py +42 -0
  18. comtypes-1.4.10/comtypes/client/_activeobj.py +46 -0
  19. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_code_cache.py +10 -5
  20. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_constants.py +1 -1
  21. comtypes-1.4.10/comtypes/client/_create.py +147 -0
  22. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_events.py +58 -13
  23. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/_generate.py +7 -11
  24. comtypes-1.4.10/comtypes/client/_managing.py +114 -0
  25. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/dynamic.py +2 -3
  26. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/client/lazybind.py +12 -13
  27. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/connectionpoints.py +2 -1
  28. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/errorinfo.py +22 -9
  29. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/git.py +5 -5
  30. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/hints.pyi +7 -15
  31. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/logutil.py +15 -3
  32. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/messageloop.py +1 -1
  33. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/persist.py +3 -5
  34. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/safearray.py +17 -5
  35. comtypes-1.4.10/comtypes/server/__init__.py +104 -0
  36. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/automation.py +1 -2
  37. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/connectionpoints.py +5 -5
  38. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/inprocserver.py +25 -17
  39. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/server/localserver.py +49 -19
  40. comtypes-1.4.10/comtypes/server/register.py +478 -0
  41. comtypes-1.4.10/comtypes/server/w_getopt.py +48 -0
  42. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/shelllink.py +16 -33
  43. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/stream.py +7 -4
  44. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestComServer.py +6 -7
  45. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestDispServer.py +4 -2
  46. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/__init__.py +10 -12
  47. comtypes-1.4.10/comtypes/test/find_memleak.py +72 -0
  48. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/runtests.py +1 -0
  49. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/setup.py +2 -1
  50. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_BSTR.py +10 -23
  51. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_GUID.py +1 -0
  52. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_QueryService.py +1 -0
  53. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_agilent.py +4 -3
  54. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_avmc.py +1 -1
  55. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_basic.py +12 -6
  56. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_casesensitivity.py +3 -5
  57. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_clear_cache.py +1 -1
  58. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_client.py +2 -2
  59. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_client_dynamic.py +2 -2
  60. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_client_regenerate_modules.py +2 -2
  61. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_collections.py +4 -4
  62. comtypes-1.4.10/comtypes/test/test_comobject.py +146 -0
  63. comtypes-1.4.10/comtypes/test/test_comserver.py +349 -0
  64. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_createwrappers.py +2 -4
  65. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dispifc_records.py +1 -1
  66. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dispifc_safearrays.py +1 -1
  67. comtypes-1.4.10/comtypes/test/test_dispinterface.py +153 -0
  68. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dyndispatch.py +1 -0
  69. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_excel.py +22 -12
  70. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_findgendir.py +1 -2
  71. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_getactiveobj.py +4 -4
  72. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_ie.py +19 -9
  73. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_ienum.py +2 -2
  74. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_imfattributes.py +13 -3
  75. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_inout_args.py +8 -5
  76. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_midl_safearray_create.py +14 -4
  77. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_monikers.py +23 -9
  78. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_msscript.py +2 -1
  79. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_npsupport.py +4 -4
  80. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_outparam.py +37 -14
  81. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_persist.py +2 -4
  82. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_recordinfo.py +1 -1
  83. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_safearray.py +1 -90
  84. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_sapi.py +4 -1
  85. comtypes-1.4.10/comtypes/test/test_server.py +350 -0
  86. comtypes-1.4.10/comtypes/test/test_server_register.py +524 -0
  87. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_shelllink.py +2 -3
  88. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_showevents.py +7 -17
  89. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_storage.py +12 -6
  90. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_stream.py +16 -5
  91. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_subinterface.py +4 -2
  92. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_typeannotator.py +1 -2
  93. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_typeinfo.py +19 -7
  94. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_urlhistory.py +7 -4
  95. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_variant.py +3 -19
  96. comtypes-1.4.10/comtypes/test/test_w_getopt.py +29 -0
  97. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_win32com_interop.py +80 -36
  98. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_wmi.py +0 -3
  99. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_word.py +1 -1
  100. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/codegenerator.py +166 -440
  101. comtypes-1.4.10/comtypes/tools/codegenerator/comments.py +79 -0
  102. comtypes-1.4.10/comtypes/tools/codegenerator/heads.py +192 -0
  103. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/helpers.py +11 -14
  104. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/namespaces.py +13 -5
  105. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/packing.py +4 -4
  106. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/typeannotator.py +19 -9
  107. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/tlbparser.py +22 -23
  108. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/typedesc.py +4 -8
  109. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/typedesc_base.py +2 -2
  110. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/typeinfo.py +159 -63
  111. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/viewobject.py +3 -9
  112. {comtypes-1.4.8 → comtypes-1.4.10/comtypes.egg-info}/PKG-INFO +4 -3
  113. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/SOURCES.txt +11 -3
  114. {comtypes-1.4.8 → comtypes-1.4.10}/pyproject.toml +12 -19
  115. comtypes-1.4.8/comtypes/_comobject.py +0 -833
  116. comtypes-1.4.8/comtypes/_idl_stuff.py +0 -67
  117. comtypes-1.4.8/comtypes/client/__init__.py +0 -323
  118. comtypes-1.4.8/comtypes/server/__init__.py +0 -70
  119. comtypes-1.4.8/comtypes/server/register.py +0 -431
  120. comtypes-1.4.8/comtypes/server/w_getopt.py +0 -75
  121. comtypes-1.4.8/comtypes/test/find_memleak.py +0 -76
  122. comtypes-1.4.8/comtypes/test/test_comserver.py +0 -239
  123. comtypes-1.4.8/comtypes/test/test_dispinterface.py +0 -137
  124. comtypes-1.4.8/comtypes/test/test_propputref.py +0 -40
  125. comtypes-1.4.8/comtypes/test/test_server.py +0 -354
  126. {comtypes-1.4.8 → comtypes-1.4.10}/LICENSE.txt +0 -0
  127. {comtypes-1.4.8 → comtypes-1.4.10}/MANIFEST.in +0 -0
  128. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_npsupport.py +0 -0
  129. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_post_coinit/__init__.py +0 -0
  130. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/_tlib_version_checker.py +0 -0
  131. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/clear_cache.py +0 -0
  132. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/hresult.py +0 -0
  133. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/patcher.py +0 -0
  134. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestComServer.idl +0 -0
  135. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestComServer.tlb +0 -0
  136. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestDispServer.idl +0 -0
  137. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/TestDispServer.tlb +0 -0
  138. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/mylib.idl +0 -0
  139. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/mylib.tlb +0 -0
  140. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/mytypelib.idl +0 -0
  141. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_DISPPARAMS.py +0 -0
  142. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_dict.py +0 -0
  143. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_jscript.js +0 -0
  144. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/test_pump_events.py +0 -0
  145. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/test/urlhist.tlb +0 -0
  146. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/__init__.py +0 -0
  147. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/__init__.py +0 -0
  148. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/tools/codegenerator/modulenamer.py +0 -0
  149. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes/util.py +0 -0
  150. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/dependency_links.txt +0 -0
  151. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/entry_points.txt +0 -0
  152. {comtypes-1.4.8 → comtypes-1.4.10}/comtypes.egg-info/top_level.txt +0 -0
  153. {comtypes-1.4.8 → comtypes-1.4.10}/setup.cfg +0 -0
  154. {comtypes-1.4.8 → comtypes-1.4.10}/setup.py +0 -0
@@ -1,34 +1,24 @@
1
1
  # https://learn.microsoft.com/en-us/windows/win32/api/unknwn/
2
2
 
3
- from ctypes import byref, c_ulong, c_void_p, HRESULT, POINTER
4
- from _ctypes import COMError
5
-
6
3
  import logging
7
- import sys
8
- import types
9
- from typing import ClassVar, TYPE_CHECKING, TypeVar
10
- from typing import Optional
11
- from typing import List, Type
12
-
13
- from comtypes import GUID, patcher, _ole32_nohresult, com_interface_registry
14
- from comtypes._idl_stuff import STDMETHOD
15
- from comtypes._memberspec import ComMemberGenerator, DispMemberGenerator
16
- from comtypes._memberspec import _ComMemberSpec, _DispMemberSpec
17
- from comtypes._py_instance_method import instancemethod
4
+ from ctypes import HRESULT, POINTER, byref, c_ulong, c_void_p
5
+ from typing import TYPE_CHECKING, ClassVar, List, Optional, Type, TypeVar
18
6
 
7
+ from comtypes import GUID, _CoUninitialize, com_interface_registry
8
+ from comtypes._memberspec import STDMETHOD, ComMemberGenerator, DispMemberGenerator
9
+ from comtypes._post_coinit import _cominterface_meta_patcher as _meta_patch
10
+ from comtypes._post_coinit.instancemethod import instancemethod
19
11
 
20
- _all_slice = slice(None, None, None)
12
+ if TYPE_CHECKING:
13
+ from comtypes._memberspec import _ComMemberSpec, _DispMemberSpec
21
14
 
22
15
  logger = logging.getLogger(__name__)
23
16
 
24
17
 
25
18
  def _shutdown(
26
- func=_ole32_nohresult.CoUninitialize,
19
+ func=_CoUninitialize,
27
20
  _debug=logger.debug,
28
- _exc_clear=getattr(sys, "exc_clear", lambda: None),
29
21
  ):
30
- # Make sure no COM pointers stay in exception frames.
31
- _exc_clear()
32
22
  # Sometimes, CoUninitialize, running at Python shutdown,
33
23
  # raises an exception. We suppress this when __debug__ is
34
24
  # False.
@@ -58,8 +48,8 @@ class _cominterface_meta(type):
58
48
 
59
49
  _case_insensitive_: bool
60
50
  _iid_: GUID
61
- _methods_: List[_ComMemberSpec]
62
- _disp_methods_: List[_DispMemberSpec]
51
+ _methods_: List["_ComMemberSpec"]
52
+ _disp_methods_: List["_DispMemberSpec"]
63
53
 
64
54
  # This flag is set to True by the atexit handler which calls
65
55
  # CoUninitialize.
@@ -136,68 +126,11 @@ class _cominterface_meta(type):
136
126
  _pointer_type_cache[self] = p
137
127
 
138
128
  if self._case_insensitive_:
139
- self._patch_case_insensitive_to_ptr_type(p)
140
- self._patch_reference_fix_to_ptrptr_type(POINTER(p)) # type: ignore
129
+ _meta_patch.case_insensitive(p)
130
+ _meta_patch.reference_fix(POINTER(p)) # type: ignore
141
131
 
142
132
  return self
143
133
 
144
- @staticmethod
145
- def _patch_case_insensitive_to_ptr_type(p: Type) -> None:
146
- @patcher.Patch(p)
147
- class CaseInsensitive(object):
148
- # case insensitive attributes for COM methods and properties
149
- def __getattr__(self, name):
150
- """Implement case insensitive access to methods and properties"""
151
- try:
152
- fixed_name = self.__map_case__[name.lower()]
153
- except KeyError:
154
- raise AttributeError(name) # Should we use exception-chaining?
155
- if fixed_name != name: # prevent unbounded recursion
156
- return getattr(self, fixed_name)
157
- raise AttributeError(name)
158
-
159
- # __setattr__ is pretty heavy-weight, because it is called for
160
- # EVERY attribute assignment. Settings a non-com attribute
161
- # through this function takes 8.6 usec, while without this
162
- # function it takes 0.7 sec - 12 times slower.
163
- #
164
- # How much faster would this be if implemented in C?
165
- def __setattr__(self, name, value):
166
- """Implement case insensitive access to methods and properties"""
167
- object.__setattr__(
168
- self, self.__map_case__.get(name.lower(), name), value
169
- )
170
-
171
- @staticmethod
172
- def _patch_reference_fix_to_ptrptr_type(pp: Type) -> None:
173
- @patcher.Patch(pp)
174
- class ReferenceFix(object):
175
- def __setitem__(self, index, value):
176
- # We override the __setitem__ method of the
177
- # POINTER(POINTER(interface)) type, so that the COM
178
- # reference count is managed correctly.
179
- #
180
- # This is so that we can implement COM methods that have to
181
- # return COM pointers more easily and consistent. Instead of
182
- # using CopyComPointer in the method implementation, we can
183
- # simply do:
184
- #
185
- # def GetTypeInfo(self, this, ..., pptinfo):
186
- # if not pptinfo: return E_POINTER
187
- # pptinfo[0] = a_com_interface_pointer
188
- # return S_OK
189
- if index != 0:
190
- # CopyComPointer, which is in _ctypes, does only
191
- # handle an index of 0. This code does what
192
- # CopyComPointer should do if index != 0.
193
- if bool(value):
194
- value.AddRef()
195
- super(pp, self).__setitem__(index, value) # type: ignore
196
- return
197
- from _ctypes import CopyComPointer
198
-
199
- CopyComPointer(value, self) # type: ignore
200
-
201
134
  def __setattr__(self, name, value):
202
135
  if name == "_methods_":
203
136
  # XXX I'm no longer sure why the code generator generates
@@ -225,94 +158,11 @@ class _cominterface_meta(type):
225
158
 
226
159
  # XXX These special methods should be generated by the code generator.
227
160
  if has_name("Count"):
228
-
229
- @patcher.Patch(self)
230
- class _(object):
231
- def __len__(self):
232
- "Return the the 'self.Count' property."
233
- return self.Count
234
-
161
+ _meta_patch.sized(self)
235
162
  if has_name("Item"):
236
-
237
- @patcher.Patch(self)
238
- class _(object):
239
- # 'Item' is the 'default' value. Make it available by
240
- # calling the instance (Not sure this makes sense, but
241
- # win32com does this also).
242
- def __call__(self, *args, **kw):
243
- "Return 'self.Item(*args, **kw)'"
244
- return self.Item(*args, **kw)
245
-
246
- # does this make sense? It seems that all standard typelibs I've
247
- # seen so far that support .Item also support ._NewEnum
248
- @patcher.no_replace
249
- def __getitem__(self, index):
250
- "Return 'self.Item(index)'"
251
- # Handle tuples and all-slice
252
- if isinstance(index, tuple):
253
- args = index
254
- elif index == _all_slice:
255
- args = ()
256
- else:
257
- args = (index,)
258
-
259
- try:
260
- result = self.Item(*args)
261
- except COMError as err:
262
- (hresult, text, details) = err.args
263
- if hresult == -2147352565: # DISP_E_BADINDEX
264
- raise IndexError("invalid index")
265
- else:
266
- raise
267
-
268
- # Note that result may be NULL COM pointer. There is no way
269
- # to interpret this properly, so it is returned as-is.
270
-
271
- # Hm, should we call __ctypes_from_outparam__ on the
272
- # result?
273
- return result
274
-
275
- @patcher.no_replace
276
- def __setitem__(self, index, value):
277
- "Attempt 'self.Item[index] = value'"
278
- try:
279
- self.Item[index] = value
280
- except COMError as err:
281
- (hresult, text, details) = err.args
282
- if hresult == -2147352565: # DISP_E_BADINDEX
283
- raise IndexError("invalid index")
284
- else:
285
- raise
286
- except TypeError:
287
- msg = "%r object does not support item assignment"
288
- raise TypeError(msg % type(self))
289
-
163
+ _meta_patch.callable_and_subscriptable(self)
290
164
  if has_name("_NewEnum"):
291
-
292
- @patcher.Patch(self)
293
- class _(object):
294
- def __iter__(self):
295
- "Return an iterator over the _NewEnum collection."
296
- # This method returns a pointer to _some_ _NewEnum interface.
297
- # It relies on the fact that the code generator creates next()
298
- # methods for them automatically.
299
- #
300
- # Better would maybe to return an object that
301
- # implements the Python iterator protocol, and
302
- # forwards the calls to the COM interface.
303
- enum = self._NewEnum
304
- if isinstance(enum, types.MethodType):
305
- # _NewEnum should be a propget property, with dispid -4.
306
- #
307
- # Sometimes, however, it is a method.
308
- enum = enum()
309
- if hasattr(enum, "Next"):
310
- return enum
311
- # _NewEnum returns an IUnknown pointer, QueryInterface() it to
312
- # IEnumVARIANT
313
- from comtypes.automation import IEnumVARIANT
314
-
315
- return enum.QueryInterface(IEnumVARIANT)
165
+ _meta_patch.iterator(self)
316
166
 
317
167
  def _make_case_insensitive(self):
318
168
  # The __map_case__ dictionary maps lower case names to the
@@ -325,7 +175,7 @@ class _cominterface_meta(type):
325
175
  d.update(getattr(self, "__map_case__", {}))
326
176
  self.__map_case__ = d
327
177
 
328
- def _make_dispmethods(self, methods: List[_DispMemberSpec]) -> None:
178
+ def _make_dispmethods(self, methods: List["_DispMemberSpec"]) -> None:
329
179
  if self._case_insensitive_:
330
180
  self._make_case_insensitive()
331
181
  # create dispinterface methods and properties on the interface 'self'
@@ -357,7 +207,7 @@ class _cominterface_meta(type):
357
207
  raise TypeError(f"baseinterface '{itf.__name__}' has no _methods_")
358
208
  return result
359
209
 
360
- def _make_methods(self, methods: List[_ComMemberSpec]) -> None:
210
+ def _make_methods(self, methods: List["_ComMemberSpec"]) -> None:
361
211
  if self._case_insensitive_:
362
212
  self._make_case_insensitive()
363
213
  # register com interface. we insist on an _iid_ in THIS class!
@@ -375,12 +225,12 @@ class _cominterface_meta(type):
375
225
  member_gen.add(m)
376
226
  for name, func, raw_func, is_prop in member_gen.methods():
377
227
  raw_mth = instancemethod(raw_func, None, self)
378
- setattr(self, "_%s__com_%s" % (self.__name__, name), raw_mth)
228
+ setattr(self, f"_{self.__name__}__com_{name}", raw_mth)
379
229
  mth = instancemethod(func, None, self)
380
230
  if not is_prop:
381
231
  # We install the method in the class, except when it's a property.
382
232
  # And we make sure we don't overwrite a property that's already present.
383
- mthname = name if not hasattr(self, name) else ("_%s" % name)
233
+ mthname = name if not hasattr(self, name) else f"_{name}"
384
234
  setattr(self, mthname, mth)
385
235
  # For a method, this is the real name.
386
236
  # For a property, this is the name WITHOUT the _set_ or _get_ prefix.
@@ -391,7 +241,7 @@ class _cominterface_meta(type):
391
241
  # create public properties / attribute accessors
392
242
  for name, accessor in member_gen.properties():
393
243
  # Again, we should not overwrite class attributes that are already present.
394
- propname = name if not hasattr(self, name) else ("_%s" % name)
244
+ propname = name if not hasattr(self, name) else f"_{name}"
395
245
  setattr(self, propname, accessor)
396
246
  # COM is case insensitive
397
247
  if self._case_insensitive_:
@@ -423,7 +273,7 @@ class _compointer_base(c_void_p, metaclass=_compointer_meta):
423
273
  #
424
274
  if not type(self)._com_shutting_down:
425
275
  _debug("Release %s", self)
426
- self.Release()
276
+ self.Release() # type: ignore
427
277
 
428
278
  def __eq__(self, other):
429
279
  if not isinstance(other, _compointer_base):
@@ -446,7 +296,7 @@ class _compointer_base(c_void_p, metaclass=_compointer_meta):
446
296
 
447
297
  def __repr__(self):
448
298
  ptr = super(_compointer_base, self).value
449
- return "<%s ptr=0x%x at %x>" % (self.__class__.__name__, ptr or 0, id(self))
299
+ return f"<{self.__class__.__name__} ptr=0x{ptr or 0:x} at {id(self):x}>"
450
300
 
451
301
  # This fixes the problem when there are multiple python interface types
452
302
  # wrapping the same COM interface. This could happen because some interfaces
@@ -482,8 +332,8 @@ class _compointer_base(c_void_p, metaclass=_compointer_meta):
482
332
  # a kind of QueryInterface
483
333
  return table[cls._iid_]
484
334
  except KeyError:
485
- raise TypeError("Interface %s not supported" % cls._iid_)
486
- return value.QueryInterface(cls.__com_interface__)
335
+ raise TypeError(f"Interface {cls._iid_} not supported")
336
+ return value.QueryInterface(cls.__com_interface__) # type: ignore
487
337
 
488
338
 
489
339
  ################################################################
@@ -524,7 +374,7 @@ class IUnknown(_IUnknown_Base, metaclass=_cominterface_meta):
524
374
 
525
375
  _case_insensitive_: ClassVar[bool] = False
526
376
  _iid_: ClassVar[GUID] = GUID("{00000000-0000-0000-C000-000000000046}")
527
- _methods_: ClassVar[List[_ComMemberSpec]] = [
377
+ _methods_: ClassVar[List["_ComMemberSpec"]] = [
528
378
  STDMETHOD(HRESULT, "QueryInterface", [POINTER(GUID), POINTER(c_void_p)]),
529
379
  STDMETHOD(c_ulong, "AddRef"),
530
380
  STDMETHOD(c_ulong, "Release"),
@@ -1,9 +1,9 @@
1
1
  """SAFEARRAY api functions, data types, and constants."""
2
2
 
3
- from ctypes import c_uint, c_ushort, c_void_p, POINTER, Structure, WinDLL
4
- from ctypes.wintypes import DWORD, LONG, UINT
3
+ from ctypes import POINTER, Structure, WinDLL, c_uint, c_ushort, c_void_p
4
+ from ctypes.wintypes import DWORD, LONG, UINT, USHORT
5
5
 
6
- from comtypes import HRESULT, GUID
6
+ from comtypes import GUID, HRESULT
7
7
 
8
8
  ################################################################
9
9
  # if __debug__:
@@ -19,7 +19,6 @@ from comtypes import HRESULT, GUID
19
19
 
20
20
  VARTYPE = c_ushort
21
21
  PVOID = c_void_p
22
- USHORT = c_ushort
23
22
 
24
23
  _oleaut32 = WinDLL("oleaut32")
25
24