comtypes 1.1.14__zip → 1.2.1__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.
- {comtypes-1.1.14 → comtypes-1.2.1}/CHANGES.txt +37 -0
- comtypes-1.2.1/PKG-INFO +79 -0
- comtypes-1.2.1/README.md +59 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/__init__.py +302 -555
- comtypes-1.2.1/comtypes/_memberspec.py +520 -0
- comtypes-1.2.1/comtypes/_npsupport.py +143 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/automation.py +99 -11
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/client/__init__.py +80 -26
- comtypes-1.2.1/comtypes/client/_generate.py +274 -0
- comtypes-1.2.1/comtypes/hints.pyi +26 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/persist.py +14 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/safearray.py +22 -21
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/__init__.py +0 -7
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_client.py +35 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_dict.py +0 -4
- comtypes-1.2.1/comtypes/test/test_npsupport.py +343 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_safearray.py +2 -235
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_variant.py +6 -59
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/tools/codegenerator.py +454 -337
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/tools/tlbparser.py +56 -75
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/tools/typedesc.py +31 -3
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/tools/typedesc_base.py +28 -1
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/typeinfo.py +291 -121
- comtypes-1.2.1/comtypes.egg-info/PKG-INFO +79 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes.egg-info/SOURCES.txt +4 -1
- {comtypes-1.1.14 → comtypes-1.2.1}/setup.cfg +0 -1
- {comtypes-1.1.14 → comtypes-1.2.1}/setup.py +15 -8
- comtypes-1.1.14/PKG-INFO +0 -50
- comtypes-1.1.14/README.md +0 -31
- comtypes-1.1.14/comtypes/client/_generate.py +0 -257
- comtypes-1.1.14/comtypes/npsupport.py +0 -125
- comtypes-1.1.14/comtypes.egg-info/PKG-INFO +0 -50
- {comtypes-1.1.14 → comtypes-1.2.1}/LICENSE.txt +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/MANIFEST.in +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/clear_comtypes_cache.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/GUID.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/_comobject.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/_meta.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/_safearray.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/client/_code_cache.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/client/_constants.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/client/_events.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/client/dynamic.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/client/lazybind.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/connectionpoints.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/errorinfo.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/git.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/hresult.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/logutil.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/messageloop.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/patcher.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/__init__.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/automation.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/connectionpoints.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/inprocserver.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/localserver.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/register.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/server/w_getopt.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/shelllink.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/TestComServer.idl +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/TestComServer.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/TestComServer.tlb +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/TestDispServer.idl +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/TestDispServer.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/TestDispServer.tlb +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/find_memleak.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/mylib.idl +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/mytypelib.idl +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/runtests.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/setup.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_BSTR.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_DISPPARAMS.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_GUID.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_QueryService.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_agilent.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_avmc.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_basic.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_casesensitivity.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_collections.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_comserver.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_createwrappers.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_dispinterface.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_dyndispatch.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_excel.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_findgendir.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_getactiveobj.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_ie.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_jscript.js +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_msscript.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_outparam.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_propputref.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_pump_events.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_sapi.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_server.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_showevents.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_subinterface.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_typeinfo.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_urlhistory.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_win32com_interop.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_wmi.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/test/test_word.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/tools/__init__.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/util.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes/viewobject.py +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes.egg-info/dependency_links.txt +0 -0
- {comtypes-1.1.14 → comtypes-1.2.1}/comtypes.egg-info/top_level.txt +0 -0
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
from __future__ import print_function
|
|
2
2
|
import os
|
|
3
3
|
import sys
|
|
4
|
-
from ctypes import windll
|
|
5
|
-
|
|
6
|
-
from
|
|
7
|
-
from ctypes import alignment
|
|
8
|
-
|
|
9
|
-
from comtypes import automation
|
|
10
|
-
from comtypes import typeinfo
|
|
11
|
-
from comtypes import COMError
|
|
4
|
+
from ctypes import alignment, c_void_p, sizeof, windll
|
|
5
|
+
|
|
6
|
+
from comtypes import automation, COMError, TYPE_CHECKING, typeinfo
|
|
12
7
|
from comtypes.tools import typedesc
|
|
13
8
|
from comtypes.client._code_cache import _get_module_filename
|
|
14
9
|
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from typing import (
|
|
12
|
+
Any, Callable, Dict, List, Optional, Type, TypeVar, Tuple,
|
|
13
|
+
Union as _UnionT,
|
|
14
|
+
)
|
|
15
|
+
from ctypes import _CData, _Pointer
|
|
16
|
+
from comtypes import hints
|
|
17
|
+
|
|
15
18
|
|
|
16
19
|
# Is the process 64-bit?
|
|
17
20
|
is_64bits = sys.maxsize > 2**32
|
|
@@ -105,25 +108,26 @@ COMTYPES = {
|
|
|
105
108
|
################################################################
|
|
106
109
|
|
|
107
110
|
class Parser(object):
|
|
111
|
+
if TYPE_CHECKING:
|
|
112
|
+
tlib = hints.AnnoField() # type: typeinfo.ITypeLib
|
|
113
|
+
items = hints.AnnoField() # type: Dict[str, Any]
|
|
108
114
|
|
|
109
115
|
def make_type(self, tdesc, tinfo):
|
|
110
|
-
|
|
116
|
+
# type: (typeinfo.TYPEDESC, typeinfo.ITypeInfo) -> Any
|
|
117
|
+
if tdesc.vt in COMTYPES:
|
|
111
118
|
return COMTYPES[tdesc.vt]
|
|
112
|
-
except KeyError:
|
|
113
|
-
pass
|
|
114
|
-
|
|
115
119
|
if tdesc.vt == automation.VT_CARRAY:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
arraydesc = tdesc._.lpadesc[0] # type: typeinfo.tagARRAYDESC
|
|
121
|
+
typ = self.make_type(arraydesc.tdescElem, tinfo)
|
|
122
|
+
for i in range(arraydesc.cDims):
|
|
123
|
+
typ = typedesc.ArrayType(
|
|
124
|
+
typ, arraydesc.rgbounds[i].lLbound, arraydesc.rgbounds[i].cElements-1
|
|
125
|
+
)
|
|
121
126
|
return typ
|
|
122
|
-
|
|
123
127
|
elif tdesc.vt == automation.VT_PTR:
|
|
124
|
-
|
|
128
|
+
ptrdesc = tdesc._.lptdesc[0] # type: typeinfo.TYPEDESC
|
|
129
|
+
typ = self.make_type(ptrdesc, tinfo)
|
|
125
130
|
return PTR(typ)
|
|
126
|
-
|
|
127
131
|
elif tdesc.vt == automation.VT_USERDEFINED:
|
|
128
132
|
try:
|
|
129
133
|
ti = tinfo.GetRefTypeInfo(tdesc._.hreftype)
|
|
@@ -136,26 +140,24 @@ class Parser(object):
|
|
|
136
140
|
(tlib_name, details, type_name)
|
|
137
141
|
import warnings
|
|
138
142
|
warnings.warn(message, UserWarning);
|
|
139
|
-
result = typedesc.Structure(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
size=0)
|
|
143
|
+
result = typedesc.Structure(
|
|
144
|
+
type_name, align=8, members=[], bases=[], size=0
|
|
145
|
+
)
|
|
143
146
|
return result
|
|
144
147
|
result = self.parse_typeinfo(ti)
|
|
145
148
|
assert result is not None, ti.GetDocumentation(-1)[0]
|
|
146
149
|
return result
|
|
147
|
-
|
|
148
150
|
elif tdesc.vt == automation.VT_SAFEARRAY:
|
|
149
151
|
# SAFEARRAY(<type>), see Don Box pp.331f
|
|
150
|
-
|
|
151
|
-
return midlSAFEARRAY(
|
|
152
|
-
|
|
152
|
+
safearraydesc = tdesc._.lptdesc[0] # type: typeinfo.TYPEDESC
|
|
153
|
+
return midlSAFEARRAY(self.make_type(safearraydesc, tinfo))
|
|
153
154
|
raise NotImplementedError(tdesc.vt)
|
|
154
155
|
|
|
155
156
|
################################################################
|
|
156
157
|
|
|
157
158
|
# TKIND_ENUM = 0
|
|
158
159
|
def ParseEnum(self, tinfo, ta):
|
|
160
|
+
# type: (typeinfo.ITypeInfo, typeinfo.TYPEATTR) -> typedesc.Enumeration
|
|
159
161
|
ta = tinfo.GetTypeAttr()
|
|
160
162
|
enum_name = tinfo.GetDocumentation(-1)[0]
|
|
161
163
|
enum = typedesc.Enumeration(enum_name, 32, 32)
|
|
@@ -165,13 +167,14 @@ class Parser(object):
|
|
|
165
167
|
vd = tinfo.GetVarDesc(i)
|
|
166
168
|
name = tinfo.GetDocumentation(vd.memid)[0]
|
|
167
169
|
assert vd.varkind == typeinfo.VAR_CONST
|
|
168
|
-
num_val = vd._.lpvarValue[0].value
|
|
170
|
+
num_val = vd._.lpvarValue[0].value # type: int
|
|
169
171
|
v = typedesc.EnumValue(name, num_val, enum)
|
|
170
172
|
enum.add_value(v)
|
|
171
173
|
return enum
|
|
172
174
|
|
|
173
175
|
# TKIND_RECORD = 1
|
|
174
176
|
def ParseRecord(self, tinfo, ta):
|
|
177
|
+
# type: (typeinfo.ITypeInfo, typeinfo.TYPEATTR) -> typedesc.Structure
|
|
175
178
|
members = [] # will be filled later
|
|
176
179
|
struct_name, doc, helpcntext, helpfile = tinfo.GetDocumentation(-1)
|
|
177
180
|
struct = typedesc.Structure(struct_name,
|
|
@@ -211,6 +214,7 @@ class Parser(object):
|
|
|
211
214
|
|
|
212
215
|
# TKIND_MODULE = 2
|
|
213
216
|
def ParseModule(self, tinfo, ta):
|
|
217
|
+
# type: (typeinfo.ITypeInfo, typeinfo.TYPEATTR) -> None
|
|
214
218
|
assert 0 == ta.cImplTypes
|
|
215
219
|
# functions
|
|
216
220
|
for i in range(ta.cFuncs):
|
|
@@ -253,6 +257,7 @@ class Parser(object):
|
|
|
253
257
|
|
|
254
258
|
# TKIND_INTERFACE = 3
|
|
255
259
|
def ParseInterface(self, tinfo, ta):
|
|
260
|
+
# type: (typeinfo.ITypeInfo, typeinfo.TYPEATTR) -> Optional[typedesc.ComInterface]
|
|
256
261
|
itf_name, itf_doc = tinfo.GetDocumentation(-1)[0:2]
|
|
257
262
|
assert ta.cImplTypes <= 1
|
|
258
263
|
if ta.cImplTypes == 0 and itf_name != "IUnknown":
|
|
@@ -284,7 +289,6 @@ class Parser(object):
|
|
|
284
289
|
members = []
|
|
285
290
|
for i in range(ta.cFuncs):
|
|
286
291
|
fd = tinfo.GetFuncDesc(i)
|
|
287
|
-
## func_name = tinfo.GetDocumentation(fd.memid)[0]
|
|
288
292
|
func_name, func_doc = tinfo.GetDocumentation(fd.memid)[:2]
|
|
289
293
|
assert fd.funckind == typeinfo.FUNC_PUREVIRTUAL
|
|
290
294
|
returns = self.make_type(fd.elemdescFunc.tdesc, tinfo)
|
|
@@ -295,7 +299,6 @@ class Parser(object):
|
|
|
295
299
|
flags = self.func_flags(fd.wFuncFlags)
|
|
296
300
|
flags += self.inv_kind(fd.invkind)
|
|
297
301
|
mth = typedesc.ComMethod(fd.invkind, fd.memid, func_name, returns, flags, func_doc)
|
|
298
|
-
mth.oVft = fd.oVft
|
|
299
302
|
for p in range(fd.cParams):
|
|
300
303
|
typ = self.make_type(fd.lprgelemdescParam[p].tdesc, tinfo)
|
|
301
304
|
name = names[p+1]
|
|
@@ -303,7 +306,7 @@ class Parser(object):
|
|
|
303
306
|
if flags & typeinfo.PARAMFLAG_FHASDEFAULT:
|
|
304
307
|
# XXX should be handled by VARIANT itself
|
|
305
308
|
var = fd.lprgelemdescParam[p]._.paramdesc.pparamdescex[0].varDefaultValue
|
|
306
|
-
default = var.value
|
|
309
|
+
default = var.value # type: Any
|
|
307
310
|
else:
|
|
308
311
|
default = None
|
|
309
312
|
mth.add_argument(typ, name, self.param_flags(flags), default)
|
|
@@ -317,6 +320,7 @@ class Parser(object):
|
|
|
317
320
|
|
|
318
321
|
# TKIND_DISPATCH = 4
|
|
319
322
|
def ParseDispatch(self, tinfo, ta):
|
|
323
|
+
# type: (typeinfo.ITypeInfo, typeinfo.TYPEATTR) -> typedesc.DispInterface
|
|
320
324
|
itf_name, doc = tinfo.GetDocumentation(-1)[0:2]
|
|
321
325
|
assert ta.cImplTypes == 1
|
|
322
326
|
|
|
@@ -372,20 +376,21 @@ class Parser(object):
|
|
|
372
376
|
flags += self.inv_kind(fd.invkind)
|
|
373
377
|
mth = typedesc.DispMethod(fd.memid, fd.invkind, func_name, returns, flags, func_doc)
|
|
374
378
|
for p in range(fd.cParams):
|
|
375
|
-
|
|
379
|
+
descparam = fd.lprgelemdescParam[p]
|
|
380
|
+
typ = self.make_type(descparam.tdesc, tinfo)
|
|
376
381
|
name = names[p+1]
|
|
377
|
-
flags =
|
|
382
|
+
flags = descparam._.paramdesc.wParamFlags
|
|
378
383
|
if flags & typeinfo.PARAMFLAG_FHASDEFAULT:
|
|
379
|
-
var =
|
|
380
|
-
default = var.value
|
|
384
|
+
var = descparam._.paramdesc.pparamdescex[0].varDefaultValue # type: ignore
|
|
385
|
+
default = var.value # type: Any
|
|
381
386
|
else:
|
|
382
387
|
default = None
|
|
383
388
|
mth.add_argument(typ, name, self.param_flags(flags), default)
|
|
384
389
|
itf.members.append(mth)
|
|
385
|
-
|
|
386
390
|
return itf
|
|
387
391
|
|
|
388
392
|
def inv_kind(self, invkind):
|
|
393
|
+
# type: (int) -> List[str]
|
|
389
394
|
NAMES = {automation.DISPATCH_METHOD: [],
|
|
390
395
|
automation.DISPATCH_PROPERTYPUT: ["propput"],
|
|
391
396
|
automation.DISPATCH_PROPERTYPUTREF: ["propputref"],
|
|
@@ -393,6 +398,7 @@ class Parser(object):
|
|
|
393
398
|
return NAMES[invkind]
|
|
394
399
|
|
|
395
400
|
def func_flags(self, flags):
|
|
401
|
+
# type: (int) -> List[str]
|
|
396
402
|
# map FUNCFLAGS values to idl attributes
|
|
397
403
|
NAMES = {typeinfo.FUNCFLAG_FRESTRICTED: "restricted",
|
|
398
404
|
typeinfo.FUNCFLAG_FSOURCE: "source",
|
|
@@ -410,6 +416,7 @@ class Parser(object):
|
|
|
410
416
|
return [NAMES[bit] for bit in NAMES if bit & flags]
|
|
411
417
|
|
|
412
418
|
def param_flags(self, flags):
|
|
419
|
+
# type: (int) -> List[str]
|
|
413
420
|
# map PARAMFLAGS values to idl attributes
|
|
414
421
|
NAMES = {typeinfo.PARAMFLAG_FIN: "in",
|
|
415
422
|
typeinfo.PARAMFLAG_FOUT: "out",
|
|
@@ -422,6 +429,7 @@ class Parser(object):
|
|
|
422
429
|
return [NAMES[bit] for bit in NAMES if bit & flags]
|
|
423
430
|
|
|
424
431
|
def coclass_type_flags(self, flags):
|
|
432
|
+
# type: (int) -> List[str]
|
|
425
433
|
# map TYPEFLAGS values to idl attributes
|
|
426
434
|
NAMES = {typeinfo.TYPEFLAG_FAPPOBJECT: "appobject",
|
|
427
435
|
# typeinfo.TYPEFLAG_FCANCREATE:
|
|
@@ -444,6 +452,7 @@ class Parser(object):
|
|
|
444
452
|
[NEGATIVE_NAMES[bit] for bit in NEGATIVE_NAMES if not (bit & flags)]
|
|
445
453
|
|
|
446
454
|
def interface_type_flags(self, flags):
|
|
455
|
+
# type: (int) -> List[str]
|
|
447
456
|
# map TYPEFLAGS values to idl attributes
|
|
448
457
|
NAMES = {typeinfo.TYPEFLAG_FAPPOBJECT: "appobject",
|
|
449
458
|
# typeinfo.TYPEFLAG_FCANCREATE:
|
|
@@ -466,6 +475,7 @@ class Parser(object):
|
|
|
466
475
|
[NEGATIVE_NAMES[bit] for bit in NEGATIVE_NAMES if not (bit & flags)]
|
|
467
476
|
|
|
468
477
|
def var_flags(self, flags):
|
|
478
|
+
# type: (int) -> List[str]
|
|
469
479
|
NAMES = {typeinfo.VARFLAG_FREADONLY: "readonly",
|
|
470
480
|
typeinfo.VARFLAG_FSOURCE: "source",
|
|
471
481
|
typeinfo.VARFLAG_FBINDABLE: "bindable",
|
|
@@ -482,9 +492,9 @@ class Parser(object):
|
|
|
482
492
|
}
|
|
483
493
|
return [NAMES[bit] for bit in NAMES if bit & flags]
|
|
484
494
|
|
|
485
|
-
|
|
486
495
|
# TKIND_COCLASS = 5
|
|
487
496
|
def ParseCoClass(self, tinfo, ta):
|
|
497
|
+
# type: (typeinfo.ITypeInfo, typeinfo.TYPEATTR) -> typedesc.CoClass
|
|
488
498
|
# possible ta.wTypeFlags: helpstring, helpcontext, licensed,
|
|
489
499
|
# version, control, hidden, and appobject
|
|
490
500
|
coclass_name, doc = tinfo.GetDocumentation(-1)[0:2]
|
|
@@ -507,6 +517,7 @@ class Parser(object):
|
|
|
507
517
|
|
|
508
518
|
# TKIND_ALIAS = 6
|
|
509
519
|
def ParseAlias(self, tinfo, ta):
|
|
520
|
+
# type: (typeinfo.ITypeInfo, typeinfo.TYPEATTR) -> typedesc.Typedef
|
|
510
521
|
name = tinfo.GetDocumentation(-1)[0]
|
|
511
522
|
typ = self.make_type(ta.tdescAlias, tinfo)
|
|
512
523
|
alias = typedesc.Typedef(name, typ)
|
|
@@ -515,6 +526,7 @@ class Parser(object):
|
|
|
515
526
|
|
|
516
527
|
# TKIND_UNION = 7
|
|
517
528
|
def ParseUnion(self, tinfo, ta):
|
|
529
|
+
# type: (typeinfo.ITypeInfo, typeinfo.TYPEATTR) -> typedesc.Union
|
|
518
530
|
union_name, doc, helpcntext, helpfile = tinfo.GetDocumentation(-1)
|
|
519
531
|
members = []
|
|
520
532
|
union = typedesc.Union(union_name,
|
|
@@ -549,6 +561,7 @@ class Parser(object):
|
|
|
549
561
|
################################################################
|
|
550
562
|
|
|
551
563
|
def _typelib_module(self, tlib=None):
|
|
564
|
+
# type: (Optional[typeinfo.ITypeLib]) -> str
|
|
552
565
|
if tlib is None:
|
|
553
566
|
tlib = self.tlib
|
|
554
567
|
# return a string that uniquely identifies a typelib.
|
|
@@ -556,6 +569,7 @@ class Parser(object):
|
|
|
556
569
|
return str(tlib.GetLibAttr())
|
|
557
570
|
|
|
558
571
|
def _register(self, name, value, tlib=None):
|
|
572
|
+
# type: (Optional[str], Any, Optional[typeinfo.ITypeLib]) -> None
|
|
559
573
|
modname = self._typelib_module(tlib)
|
|
560
574
|
fullname = "%s.%s" % (modname, name)
|
|
561
575
|
if fullname in self.items:
|
|
@@ -567,6 +581,7 @@ class Parser(object):
|
|
|
567
581
|
self.items[fullname] = value
|
|
568
582
|
|
|
569
583
|
def parse_typeinfo(self, tinfo):
|
|
584
|
+
# type: (typeinfo.ITypeInfo) -> Any
|
|
570
585
|
name = tinfo.GetDocumentation(-1)[0]
|
|
571
586
|
modname = self._typelib_module()
|
|
572
587
|
try:
|
|
@@ -579,11 +594,9 @@ class Parser(object):
|
|
|
579
594
|
ta = tinfo.GetTypeAttr()
|
|
580
595
|
size = ta.cbSizeInstance * 8
|
|
581
596
|
align = ta.cbAlignment * 8
|
|
582
|
-
typ = typedesc.External(
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
align,
|
|
586
|
-
tlib.GetDocumentation(-1)[:2])
|
|
597
|
+
typ = typedesc.External(
|
|
598
|
+
tlib, name, size, align, tlib.GetDocumentation(-1)[:2]
|
|
599
|
+
)
|
|
587
600
|
self._register(name, typ, tlib)
|
|
588
601
|
return typ
|
|
589
602
|
|
|
@@ -730,36 +743,4 @@ def _py2exe_hint():
|
|
|
730
743
|
import comtypes.typeinfo
|
|
731
744
|
import comtypes.automation
|
|
732
745
|
|
|
733
|
-
def generate_module(tlib, ofi, pathname):
|
|
734
|
-
known_symbols = {}
|
|
735
|
-
for name in ("comtypes.persist",
|
|
736
|
-
"comtypes.typeinfo",
|
|
737
|
-
"comtypes.automation",
|
|
738
|
-
"comtypes._others",
|
|
739
|
-
"comtypes",
|
|
740
|
-
"ctypes.wintypes",
|
|
741
|
-
"ctypes"):
|
|
742
|
-
try:
|
|
743
|
-
mod = __import__(name)
|
|
744
|
-
except ImportError:
|
|
745
|
-
if name == "comtypes._others":
|
|
746
|
-
continue
|
|
747
|
-
raise
|
|
748
|
-
for submodule in name.split(".")[1:]:
|
|
749
|
-
mod = getattr(mod, submodule)
|
|
750
|
-
for name in mod.__dict__:
|
|
751
|
-
known_symbols[name] = mod.__name__
|
|
752
|
-
p = TypeLibParser(tlib)
|
|
753
|
-
if pathname is None:
|
|
754
|
-
pathname = get_tlib_filename(tlib)
|
|
755
|
-
items = p.parse()
|
|
756
|
-
|
|
757
|
-
from .codegenerator import Generator
|
|
758
|
-
|
|
759
|
-
gen = Generator(ofi,
|
|
760
|
-
known_symbols=known_symbols,
|
|
761
|
-
)
|
|
762
|
-
|
|
763
|
-
gen.generate_code(list(items.values()), filename=pathname)
|
|
764
|
-
|
|
765
746
|
# -eof-
|
|
@@ -2,10 +2,17 @@
|
|
|
2
2
|
# in typedesc_base
|
|
3
3
|
|
|
4
4
|
import ctypes
|
|
5
|
+
from comtypes import TYPE_CHECKING
|
|
6
|
+
from comtypes.typeinfo import ITypeLib, TLIBATTR
|
|
5
7
|
from comtypes.tools.typedesc_base import *
|
|
6
8
|
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from typing import Any, List, Optional, Tuple, Union as _UnionT
|
|
11
|
+
|
|
12
|
+
|
|
7
13
|
class TypeLib(object):
|
|
8
14
|
def __init__(self, name, guid, major, minor, doc=None):
|
|
15
|
+
# type: (str, str, int, int, Optional[str]) -> None
|
|
9
16
|
self.name = name
|
|
10
17
|
self.guid = guid
|
|
11
18
|
self.major = major
|
|
@@ -17,12 +24,14 @@ class TypeLib(object):
|
|
|
17
24
|
|
|
18
25
|
class Constant(object):
|
|
19
26
|
def __init__(self, name, typ, value):
|
|
27
|
+
# type: (str, _UnionT[Typedef, FundamentalType], Any) -> None
|
|
20
28
|
self.name = name
|
|
21
29
|
self.typ = typ
|
|
22
30
|
self.value = value
|
|
23
31
|
|
|
24
32
|
class External(object):
|
|
25
33
|
def __init__(self, tlib, name, size, align, docs=None):
|
|
34
|
+
# type: (ITypeLib, str, int, int, Optional[Tuple[str, str]]) -> None
|
|
26
35
|
# the type library containing the symbol
|
|
27
36
|
self.tlib = tlib
|
|
28
37
|
# name of symbol
|
|
@@ -33,45 +42,52 @@ class External(object):
|
|
|
33
42
|
self.docs = docs
|
|
34
43
|
|
|
35
44
|
def get_head(self):
|
|
45
|
+
# type: () -> External
|
|
36
46
|
# codegen might call this
|
|
37
47
|
return self
|
|
38
48
|
|
|
39
49
|
class SAFEARRAYType(object):
|
|
40
50
|
def __init__(self, typ):
|
|
51
|
+
# type: (Any) -> None
|
|
41
52
|
self.typ = typ
|
|
42
53
|
self.align = self.size = ctypes.sizeof(ctypes.c_void_p) * 8
|
|
43
54
|
|
|
44
55
|
class ComMethod(object):
|
|
45
56
|
# custom COM method, parsed from typelib
|
|
46
57
|
def __init__(self, invkind, memid, name, returns, idlflags, doc):
|
|
58
|
+
# type: (int, int, str, Any, List[str], Optional[str]) -> None
|
|
47
59
|
self.invkind = invkind
|
|
48
60
|
self.name = name
|
|
49
61
|
self.returns = returns
|
|
50
62
|
self.idlflags = idlflags
|
|
51
63
|
self.memid = memid
|
|
52
64
|
self.doc = doc
|
|
53
|
-
self.arguments = []
|
|
65
|
+
self.arguments = [] # type: List[Tuple[Any, str, List[str], Optional[Any]]]
|
|
54
66
|
|
|
55
67
|
def add_argument(self, typ, name, idlflags, default):
|
|
68
|
+
# type: (Any, str, List[str], Optional[Any]) -> None
|
|
56
69
|
self.arguments.append((typ, name, idlflags, default))
|
|
57
70
|
|
|
58
71
|
class DispMethod(object):
|
|
59
72
|
# dispatchable COM method, parsed from typelib
|
|
60
73
|
def __init__(self, dispid, invkind, name, returns, idlflags, doc):
|
|
74
|
+
# type: (int, int, str, Any, List[str], Optional[str]) -> None
|
|
61
75
|
self.dispid = dispid
|
|
62
76
|
self.invkind = invkind
|
|
63
77
|
self.name = name
|
|
64
78
|
self.returns = returns
|
|
65
79
|
self.idlflags = idlflags
|
|
66
80
|
self.doc = doc
|
|
67
|
-
self.arguments = []
|
|
81
|
+
self.arguments = [] # type: List[Tuple[Any, str, List[str], Optional[Any]]]
|
|
68
82
|
|
|
69
83
|
def add_argument(self, typ, name, idlflags, default):
|
|
84
|
+
# type: (Any, str, List[str], Optional[Any]) -> None
|
|
70
85
|
self.arguments.append((typ, name, idlflags, default))
|
|
71
86
|
|
|
72
87
|
class DispProperty(object):
|
|
73
88
|
# dispatchable COM property, parsed from typelib
|
|
74
89
|
def __init__(self, dispid, name, typ, idlflags, doc):
|
|
90
|
+
# type: (int, str, Any, List[str], Optional[Any]) -> None
|
|
75
91
|
self.dispid = dispid
|
|
76
92
|
self.name = name
|
|
77
93
|
self.typ = typ
|
|
@@ -80,14 +96,17 @@ class DispProperty(object):
|
|
|
80
96
|
|
|
81
97
|
class DispInterfaceHead(object):
|
|
82
98
|
def __init__(self, itf):
|
|
99
|
+
# type: (DispInterface) -> None
|
|
83
100
|
self.itf = itf
|
|
84
101
|
|
|
85
102
|
class DispInterfaceBody(object):
|
|
86
103
|
def __init__(self, itf):
|
|
104
|
+
# type: (DispInterface) -> None
|
|
87
105
|
self.itf = itf
|
|
88
106
|
|
|
89
107
|
class DispInterface(object):
|
|
90
108
|
def __init__(self, name, members, base, iid, idlflags):
|
|
109
|
+
# type: (str, List[_UnionT[DispMethod, DispProperty]], Any, str, List[str]) -> None
|
|
91
110
|
self.name = name
|
|
92
111
|
self.members = members
|
|
93
112
|
self.base = base
|
|
@@ -97,21 +116,26 @@ class DispInterface(object):
|
|
|
97
116
|
self.itf_body = DispInterfaceBody(self)
|
|
98
117
|
|
|
99
118
|
def get_body(self):
|
|
119
|
+
# type: () -> DispInterfaceBody
|
|
100
120
|
return self.itf_body
|
|
101
121
|
|
|
102
122
|
def get_head(self):
|
|
123
|
+
# type: () -> DispInterfaceHead
|
|
103
124
|
return self.itf_head
|
|
104
125
|
|
|
105
126
|
class ComInterfaceHead(object):
|
|
106
127
|
def __init__(self, itf):
|
|
128
|
+
# type: (ComInterface) -> None
|
|
107
129
|
self.itf = itf
|
|
108
130
|
|
|
109
131
|
class ComInterfaceBody(object):
|
|
110
132
|
def __init__(self, itf):
|
|
133
|
+
# type: (ComInterface) -> None
|
|
111
134
|
self.itf = itf
|
|
112
135
|
|
|
113
136
|
class ComInterface(object):
|
|
114
137
|
def __init__(self, name, members, base, iid, idlflags):
|
|
138
|
+
# type: (str, List[ComMethod], Any, str, List[str]) -> None
|
|
115
139
|
self.name = name
|
|
116
140
|
self.members = members
|
|
117
141
|
self.base = base
|
|
@@ -121,18 +145,22 @@ class ComInterface(object):
|
|
|
121
145
|
self.itf_body = ComInterfaceBody(self)
|
|
122
146
|
|
|
123
147
|
def get_body(self):
|
|
148
|
+
# type: () -> ComInterfaceBody
|
|
124
149
|
return self.itf_body
|
|
125
150
|
|
|
126
151
|
def get_head(self):
|
|
152
|
+
# type: () -> ComInterfaceHead
|
|
127
153
|
return self.itf_head
|
|
128
154
|
|
|
129
155
|
class CoClass(object):
|
|
130
156
|
def __init__(self, name, clsid, idlflags, tlibattr):
|
|
157
|
+
# type: (str, str, List[str], TLIBATTR) -> None
|
|
131
158
|
self.name = name
|
|
132
159
|
self.clsid = clsid
|
|
133
160
|
self.idlflags = idlflags
|
|
134
161
|
self.tlibattr = tlibattr
|
|
135
|
-
self.interfaces = []
|
|
162
|
+
self.interfaces = [] # type: List[Tuple[Any, int]]
|
|
136
163
|
|
|
137
164
|
def add_interface(self, itf, idlflags):
|
|
165
|
+
# type: (Any, int) -> None
|
|
138
166
|
self.interfaces.append((itf, idlflags))
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# typedesc.py - classes representing C type descriptions
|
|
2
2
|
|
|
3
|
+
import comtypes
|
|
4
|
+
from comtypes import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from typing import Any, List, Optional, Tuple, Union as _UnionT, SupportsInt
|
|
8
|
+
|
|
9
|
+
|
|
3
10
|
class Argument(object):
|
|
4
11
|
"a Parameter in the argument list of a callable (Function, Method, ...)"
|
|
5
12
|
def __init__(self, atype, name):
|
|
@@ -111,6 +118,7 @@ class Typedef(object):
|
|
|
111
118
|
class ArrayType(object):
|
|
112
119
|
location = None
|
|
113
120
|
def __init__(self, typ, min, max):
|
|
121
|
+
# type: (Any, int, int) -> None
|
|
114
122
|
self.typ = typ
|
|
115
123
|
self.min = min
|
|
116
124
|
self.max = max
|
|
@@ -118,27 +126,41 @@ class ArrayType(object):
|
|
|
118
126
|
class StructureHead(object):
|
|
119
127
|
location = None
|
|
120
128
|
def __init__(self, struct):
|
|
129
|
+
# type: (_Struct_Union_Base) -> None
|
|
121
130
|
self.struct = struct
|
|
122
131
|
|
|
123
132
|
class StructureBody(object):
|
|
124
133
|
location = None
|
|
125
134
|
def __init__(self, struct):
|
|
135
|
+
# type: (_Struct_Union_Base) -> None
|
|
126
136
|
self.struct = struct
|
|
127
137
|
|
|
128
138
|
class _Struct_Union_Base(object):
|
|
139
|
+
if TYPE_CHECKING:
|
|
140
|
+
name = comtypes.hints.AnnoField() # type: str
|
|
141
|
+
align = comtypes.hints.AnnoField() # type: int
|
|
142
|
+
members = comtypes.hints.AnnoField() # type: List[_UnionT[Field, Method, Constructor]]
|
|
143
|
+
bases = comtypes.hints.AnnoField() # type: List[_Struct_Union_Base]
|
|
144
|
+
artificial = comtypes.hints.AnnoField() # type: Optional[Any]
|
|
145
|
+
size = comtypes.hints.AnnoField() # type: Optional[int]
|
|
146
|
+
_recordinfo_ = comtypes.hints.AnnoField() # type: Tuple[str, int, int, int, str]
|
|
147
|
+
|
|
129
148
|
location = None
|
|
130
149
|
def __init__(self):
|
|
131
150
|
self.struct_body = StructureBody(self)
|
|
132
151
|
self.struct_head = StructureHead(self)
|
|
133
152
|
|
|
134
153
|
def get_body(self):
|
|
154
|
+
# type: () -> StructureBody
|
|
135
155
|
return self.struct_body
|
|
136
156
|
|
|
137
157
|
def get_head(self):
|
|
158
|
+
# type: () -> StructureHead
|
|
138
159
|
return self.struct_head
|
|
139
160
|
|
|
140
161
|
class Structure(_Struct_Union_Base):
|
|
141
162
|
def __init__(self, name, align, members, bases, size, artificial=None):
|
|
163
|
+
# type: (str, SupportsInt, List[Field], List[Any], Optional[SupportsInt], Optional[Any]) -> None
|
|
142
164
|
self.name = name
|
|
143
165
|
self.align = int(align)
|
|
144
166
|
self.members = members
|
|
@@ -152,6 +174,7 @@ class Structure(_Struct_Union_Base):
|
|
|
152
174
|
|
|
153
175
|
class Union(_Struct_Union_Base):
|
|
154
176
|
def __init__(self, name, align, members, bases, size, artificial=None):
|
|
177
|
+
# type: (str, SupportsInt, List[Field], List[Any], Optional[SupportsInt], Optional[Any]) -> None
|
|
155
178
|
self.name = name
|
|
156
179
|
self.align = int(align)
|
|
157
180
|
self.members = members
|
|
@@ -165,6 +188,7 @@ class Union(_Struct_Union_Base):
|
|
|
165
188
|
|
|
166
189
|
class Field(object):
|
|
167
190
|
def __init__(self, name, typ, bits, offset):
|
|
191
|
+
# type: (str, Any, Optional[Any], SupportsInt) -> None
|
|
168
192
|
self.name = name
|
|
169
193
|
self.typ = typ
|
|
170
194
|
self.bits = bits
|
|
@@ -179,16 +203,19 @@ class CvQualifiedType(object):
|
|
|
179
203
|
class Enumeration(object):
|
|
180
204
|
location = None
|
|
181
205
|
def __init__(self, name, size, align):
|
|
206
|
+
# type: (str, SupportsInt, SupportsInt) -> None
|
|
182
207
|
self.name = name
|
|
183
208
|
self.size = int(size)
|
|
184
209
|
self.align = int(align)
|
|
185
|
-
self.values = []
|
|
210
|
+
self.values = [] # type: List[EnumValue]
|
|
186
211
|
|
|
187
212
|
def add_value(self, v):
|
|
213
|
+
# type: (EnumValue) -> None
|
|
188
214
|
self.values.append(v)
|
|
189
215
|
|
|
190
216
|
class EnumValue(object):
|
|
191
217
|
def __init__(self, name, value, enumeration):
|
|
218
|
+
# type: (str, int, Enumeration) -> None
|
|
192
219
|
self.name = name
|
|
193
220
|
self.value = value
|
|
194
221
|
self.enumeration = enumeration
|