MCPcopy Create free account
hub / github.com/enthought/comtypes / ParseDispatch

Method ParseDispatch

comtypes/tools/tlbparser.py:326–404  ·  view source on GitHub ↗
(
        self, tinfo: typeinfo.ITypeInfo, ta: typeinfo.TYPEATTR
    )

Source from the content-addressed store, hash-verified

324
325 # TKIND_DISPATCH = 4
326 def ParseDispatch(
327 self, tinfo: typeinfo.ITypeInfo, ta: typeinfo.TYPEATTR
328 ) -> typedesc.DispInterface:
329 itf_name, doc = tinfo.GetDocumentation(-1)[0:2]
330 assert ta.cImplTypes == 1
331 hr = tinfo.GetRefTypeOfImplType(0)
332 tibase = tinfo.GetRefTypeInfo(hr)
333 base = self.parse_typeinfo(tibase)
334 iid = str(ta.guid)
335 idlflags = self.interface_type_flags(ta.wTypeFlags)
336 doc = str(doc.split("\0")[0]) if doc is not None else doc
337 itf = typedesc.DispInterface(itf_name, base, iid, idlflags, doc)
338 self._register(itf_name, itf)
339
340 # This code can only handle pure dispinterfaces. Dual
341 # interfaces are parsed in ParseInterface().
342 assert ta.wTypeFlags & typeinfo.TYPEFLAG_FDUAL == 0
343
344 for i in range(ta.cVars):
345 vd = tinfo.GetVarDesc(i)
346 assert vd.varkind == typeinfo.VAR_DISPATCH
347 var_name, var_doc = tinfo.GetDocumentation(vd.memid)[0:2]
348 typ = self.make_type(vd.elemdescVar.tdesc, tinfo)
349 mth = typedesc.DispProperty(
350 vd.memid, var_name, typ, self.var_flags(vd.wVarFlags), var_doc
351 )
352 itf.add_member(mth)
353
354 # At least the EXCEL typelib lists the IUnknown and IDispatch
355 # methods even for this kind of interface. I didn't find any
356 # indication about these methods in the various flags, so we
357 # have to exclude them by name.
358 # CLF: 12/14/2012 Do this in a way that does not exclude other methods.
359 # I have encountered typlibs where only "QueryInterface", "AddRef"
360 # and "Release" are to be skipped.
361 ignored_names = set(
362 [
363 "QueryInterface",
364 "AddRef",
365 "Release",
366 "GetTypeInfoCount",
367 "GetTypeInfo",
368 "GetIDsOfNames",
369 "Invoke",
370 ]
371 )
372
373 for i in range(ta.cFuncs):
374 fd = tinfo.GetFuncDesc(i)
375 func_name, func_doc = tinfo.GetDocumentation(fd.memid)[:2]
376 if func_name in ignored_names:
377 continue
378 assert fd.funckind == typeinfo.FUNC_DISPATCH
379
380 returns = self.make_type(fd.elemdescFunc.tdesc, tinfo)
381 names = tinfo.GetNames(fd.memid, fd.cParams + 1)
382 names.append("rhs")
383 names = names[: fd.cParams + 1]

Callers 1

parse_typeinfoMethod · 0.95

Calls 15

parse_typeinfoMethod · 0.95
interface_type_flagsMethod · 0.95
_registerMethod · 0.95
make_typeMethod · 0.95
var_flagsMethod · 0.95
add_memberMethod · 0.95
func_flagsMethod · 0.95
inv_kindMethod · 0.95
param_flagsMethod · 0.95
add_argumentMethod · 0.95
GetRefTypeOfImplTypeMethod · 0.80
GetRefTypeInfoMethod · 0.80

Tested by

no test coverage detected