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.
- {comtypes-1.4.9 → comtypes-1.4.10}/CHANGES.txt +19 -0
- {comtypes-1.4.9/comtypes.egg-info → comtypes-1.4.10}/PKG-INFO +3 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/GUID.py +34 -13
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/__init__.py +22 -13
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_comobject.py +69 -14
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_memberspec.py +14 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_meta.py +1 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/_cominterface_meta_patcher.py +0 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/bstr.py +12 -5
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/instancemethod.py +1 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/misc.py +59 -24
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/unknwn.py +2 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_safearray.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/automation.py +10 -4
- comtypes-1.4.10/comtypes/client/__init__.py +42 -0
- comtypes-1.4.10/comtypes/client/_activeobj.py +46 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_code_cache.py +6 -1
- comtypes-1.4.10/comtypes/client/_create.py +147 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_events.py +57 -12
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_generate.py +3 -3
- comtypes-1.4.10/comtypes/client/_managing.py +114 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/dynamic.py +2 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/lazybind.py +10 -11
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/connectionpoints.py +2 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/errorinfo.py +20 -7
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/git.py +4 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/logutil.py +15 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/messageloop.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/persist.py +3 -5
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/safearray.py +8 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/__init__.py +22 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/automation.py +1 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/connectionpoints.py +5 -5
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/inprocserver.py +6 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/localserver.py +23 -5
- comtypes-1.4.10/comtypes/server/register.py +478 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/shelllink.py +13 -7
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/stream.py +7 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestComServer.py +6 -7
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestDispServer.py +4 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/__init__.py +1 -1
- comtypes-1.4.10/comtypes/test/find_memleak.py +72 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/runtests.py +1 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/setup.py +2 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_BSTR.py +7 -17
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_GUID.py +1 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_QueryService.py +1 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_agilent.py +4 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_basic.py +12 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_clear_cache.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_client.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_client_dynamic.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_client_regenerate_modules.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_collections.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_comobject.py +4 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_comserver.py +31 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dispifc_records.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dispifc_safearrays.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dyndispatch.py +1 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_findgendir.py +1 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_getactiveobj.py +4 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_ie.py +19 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_ienum.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_imfattributes.py +13 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_inout_args.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_midl_safearray_create.py +6 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_monikers.py +23 -9
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_msscript.py +2 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_npsupport.py +4 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_outparam.py +22 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_persist.py +2 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_recordinfo.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_sapi.py +4 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_server_register.py +113 -125
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_shelllink.py +2 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_storage.py +12 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_stream.py +16 -5
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_subinterface.py +4 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_typeannotator.py +1 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_typeinfo.py +19 -7
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_urlhistory.py +7 -4
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_variant.py +3 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_word.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/codegenerator.py +167 -435
- comtypes-1.4.10/comtypes/tools/codegenerator/comments.py +79 -0
- comtypes-1.4.10/comtypes/tools/codegenerator/heads.py +192 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/helpers.py +3 -6
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/namespaces.py +13 -5
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/typeannotator.py +13 -3
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/tlbparser.py +22 -23
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/typedesc.py +3 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/typedesc_base.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/typeinfo.py +149 -42
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/viewobject.py +2 -4
- {comtypes-1.4.9 → comtypes-1.4.10/comtypes.egg-info}/PKG-INFO +3 -2
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/SOURCES.txt +5 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/pyproject.toml +11 -19
- comtypes-1.4.9/comtypes/client/__init__.py +0 -323
- comtypes-1.4.9/comtypes/server/register.py +0 -419
- comtypes-1.4.9/comtypes/test/find_memleak.py +0 -76
- {comtypes-1.4.9 → comtypes-1.4.10}/LICENSE.txt +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/MANIFEST.in +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/README.md +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_npsupport.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_post_coinit/__init__.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_tlib_version_checker.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/_vtbl.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/clear_cache.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/client/_constants.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/hints.pyi +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/hresult.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/patcher.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/server/w_getopt.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestComServer.idl +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestComServer.tlb +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestDispServer.idl +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/TestDispServer.tlb +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/mylib.idl +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/mylib.tlb +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/mytypelib.idl +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_DISPPARAMS.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_avmc.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_casesensitivity.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_createwrappers.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dict.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_dispinterface.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_excel.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_jscript.js +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_pump_events.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_safearray.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_server.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_showevents.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_w_getopt.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_win32com_interop.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/test_wmi.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/test/urlhist.tlb +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/__init__.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/__init__.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/modulenamer.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/tools/codegenerator/packing.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes/util.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/dependency_links.txt +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/entry_points.txt +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/comtypes.egg-info/top_level.txt +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/setup.cfg +0 -0
- {comtypes-1.4.9 → comtypes-1.4.10}/setup.py +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import io
|
|
2
|
+
|
|
3
|
+
from comtypes.tools import typedesc
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ComInterfaceBodyImplCommentWriter(object):
|
|
7
|
+
def __init__(self, stream: io.StringIO):
|
|
8
|
+
self.stream = stream
|
|
9
|
+
|
|
10
|
+
def write(self, body: typedesc.ComInterfaceBody) -> None:
|
|
11
|
+
print(
|
|
12
|
+
"################################################################",
|
|
13
|
+
file=self.stream,
|
|
14
|
+
)
|
|
15
|
+
print(f"# code template for {body.itf.name} implementation", file=self.stream)
|
|
16
|
+
print(f"# class {body.itf.name}_Impl(object):", file=self.stream)
|
|
17
|
+
|
|
18
|
+
methods = {}
|
|
19
|
+
for m in body.itf.members:
|
|
20
|
+
if isinstance(m, typedesc.ComMethod):
|
|
21
|
+
# m.arguments is a sequence of tuples:
|
|
22
|
+
# (argtype, argname, idlflags, docstring)
|
|
23
|
+
# Some typelibs have unnamed method parameters!
|
|
24
|
+
inargs = [a[1] or "<unnamed>" for a in m.arguments if "out" not in a[2]]
|
|
25
|
+
outargs = [a[1] or "<unnamed>" for a in m.arguments if "out" in a[2]]
|
|
26
|
+
if "propget" in m.idlflags:
|
|
27
|
+
methods.setdefault(m.name, [0, inargs, outargs, m.doc])[0] |= 1
|
|
28
|
+
elif "propput" in m.idlflags:
|
|
29
|
+
methods.setdefault(m.name, [0, inargs[:-1], inargs[-1:], m.doc])[
|
|
30
|
+
0
|
|
31
|
+
] |= 2
|
|
32
|
+
else:
|
|
33
|
+
methods[m.name] = [0, inargs, outargs, m.doc]
|
|
34
|
+
|
|
35
|
+
for name, (typ, inargs, outargs, doc) in methods.items():
|
|
36
|
+
if typ == 0: # method
|
|
37
|
+
print(
|
|
38
|
+
f"# def {name}({', '.join(['self'] + inargs)}):",
|
|
39
|
+
file=self.stream,
|
|
40
|
+
)
|
|
41
|
+
print(f"# {(doc or '-no docstring-')!r}", file=self.stream)
|
|
42
|
+
print(f"# #return {', '.join(outargs)}", file=self.stream)
|
|
43
|
+
elif typ == 1: # propget
|
|
44
|
+
print("# @property", file=self.stream)
|
|
45
|
+
print(
|
|
46
|
+
f"# def {name}({', '.join(['self'] + inargs)}):",
|
|
47
|
+
file=self.stream,
|
|
48
|
+
)
|
|
49
|
+
print(f"# {(doc or '-no docstring-')!r}", file=self.stream)
|
|
50
|
+
print(f"# #return {', '.join(outargs)}", file=self.stream)
|
|
51
|
+
elif typ == 2: # propput
|
|
52
|
+
print(
|
|
53
|
+
f"# def _set({', '.join(['self'] + inargs + outargs)}):",
|
|
54
|
+
file=self.stream,
|
|
55
|
+
)
|
|
56
|
+
print(f"# {(doc or '-no docstring-')!r}", file=self.stream)
|
|
57
|
+
print(
|
|
58
|
+
f"# {name} = property(fset = _set, doc = _set.__doc__)",
|
|
59
|
+
file=self.stream,
|
|
60
|
+
)
|
|
61
|
+
elif typ == 3: # propget + propput
|
|
62
|
+
print(
|
|
63
|
+
f"# def _get({', '.join(['self'] + inargs)}):",
|
|
64
|
+
file=self.stream,
|
|
65
|
+
)
|
|
66
|
+
print(f"# {(doc or '-no docstring-')!r}", file=self.stream)
|
|
67
|
+
print(f"# #return {', '.join(outargs)}", file=self.stream)
|
|
68
|
+
print(
|
|
69
|
+
f"# def _set({', '.join(['self'] + inargs + outargs)}):",
|
|
70
|
+
file=self.stream,
|
|
71
|
+
)
|
|
72
|
+
print(f"# {(doc or '-no docstring-')!r}", file=self.stream)
|
|
73
|
+
print(
|
|
74
|
+
f"# {name} = property(_get, _set, doc = _set.__doc__)",
|
|
75
|
+
file=self.stream,
|
|
76
|
+
)
|
|
77
|
+
else:
|
|
78
|
+
raise RuntimeError("BUG")
|
|
79
|
+
print("#", file=self.stream)
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import io
|
|
2
|
+
from typing import Optional, Sequence
|
|
3
|
+
|
|
4
|
+
from comtypes.tools import typedesc
|
|
5
|
+
from comtypes.tools.codegenerator import typeannotator
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _to_docstring(orig: str, depth: int = 1) -> str:
|
|
9
|
+
# increasing `depth` by one increases indentation by one
|
|
10
|
+
indent = " " * depth
|
|
11
|
+
# some chars are replaced to avoid causing a `SyntaxError`
|
|
12
|
+
repled = orig.replace("\\", r"\\").replace('"', r"'")
|
|
13
|
+
return f'{indent}"""{repled}"""'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class StructureHeadWriter(object):
|
|
17
|
+
def __init__(self, stream: io.StringIO) -> None:
|
|
18
|
+
self.stream = stream
|
|
19
|
+
|
|
20
|
+
def write(self, head: typedesc.StructureHead, basenames: Sequence[str]) -> None:
|
|
21
|
+
if head.struct.location:
|
|
22
|
+
print(f"# {head.struct.location}", file=self.stream)
|
|
23
|
+
if basenames:
|
|
24
|
+
method_names = [
|
|
25
|
+
m.name for m in head.struct.members if type(m) is typedesc.Method
|
|
26
|
+
]
|
|
27
|
+
print(
|
|
28
|
+
f"class {head.struct.name}({', '.join(basenames)}):",
|
|
29
|
+
file=self.stream,
|
|
30
|
+
)
|
|
31
|
+
print(
|
|
32
|
+
" _iid_ = GUID('{}') # please look up iid and fill in!",
|
|
33
|
+
file=self.stream,
|
|
34
|
+
)
|
|
35
|
+
if "Enum" in method_names:
|
|
36
|
+
print(" def __iter__(self):", file=self.stream)
|
|
37
|
+
print(" return self.Enum()", file=self.stream)
|
|
38
|
+
elif method_names == "Next Skip Reset Clone".split():
|
|
39
|
+
print(" def __iter__(self):", file=self.stream)
|
|
40
|
+
print(" return self", file=self.stream)
|
|
41
|
+
print(file=self.stream)
|
|
42
|
+
print(" def next(self):", file=self.stream)
|
|
43
|
+
print(" arr, fetched = self.Next(1)", file=self.stream)
|
|
44
|
+
print(" if fetched == 0:", file=self.stream)
|
|
45
|
+
print(" raise StopIteration", file=self.stream)
|
|
46
|
+
print(" return arr[0]", file=self.stream)
|
|
47
|
+
|
|
48
|
+
else:
|
|
49
|
+
methods = [m for m in head.struct.members if type(m) is typedesc.Method]
|
|
50
|
+
|
|
51
|
+
if methods:
|
|
52
|
+
# Hm. We cannot generate code for IUnknown...
|
|
53
|
+
print("assert 0, 'cannot generate code for IUnknown'", file=self.stream)
|
|
54
|
+
print(f"class {head.struct.name}(_com_interface):", file=self.stream)
|
|
55
|
+
print(" pass", file=self.stream)
|
|
56
|
+
elif type(head.struct) is typedesc.Structure:
|
|
57
|
+
print(f"class {head.struct.name}(Structure):", file=self.stream)
|
|
58
|
+
if hasattr(head.struct, "_recordinfo_"):
|
|
59
|
+
print(
|
|
60
|
+
f" _recordinfo_ = {head.struct._recordinfo_!r}",
|
|
61
|
+
file=self.stream,
|
|
62
|
+
)
|
|
63
|
+
else:
|
|
64
|
+
print(" pass", file=self.stream)
|
|
65
|
+
elif type(head.struct) is typedesc.Union:
|
|
66
|
+
print(f"class {head.struct.name}(Union):", file=self.stream)
|
|
67
|
+
print(" pass", file=self.stream)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class LibraryHeadWriter(object):
|
|
71
|
+
def __init__(self, stream: io.StringIO) -> None:
|
|
72
|
+
self.stream = stream
|
|
73
|
+
|
|
74
|
+
def write(self, lib: typedesc.TypeLib) -> None:
|
|
75
|
+
# Hm, in user code we have to write:
|
|
76
|
+
# class MyServer(COMObject, ...):
|
|
77
|
+
# _com_interfaces_ = [MyTypeLib.IInterface]
|
|
78
|
+
# _reg_typelib_ = MyTypeLib.Library._reg_typelib_
|
|
79
|
+
# ^^^^^^^
|
|
80
|
+
# Should the '_reg_typelib_' attribute be at top-level in the
|
|
81
|
+
# generated code, instead as being an attribute of the
|
|
82
|
+
# 'Library' symbol?
|
|
83
|
+
print("class Library(object):", file=self.stream)
|
|
84
|
+
if lib.doc:
|
|
85
|
+
print(_to_docstring(lib.doc), file=self.stream)
|
|
86
|
+
|
|
87
|
+
if lib.name:
|
|
88
|
+
print(f" name = {lib.name!r}", file=self.stream)
|
|
89
|
+
|
|
90
|
+
print(
|
|
91
|
+
f" _reg_typelib_ = ({lib.guid!r}, {lib.major!r}, {lib.minor!r})",
|
|
92
|
+
file=self.stream,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class CoClassHeadWriter(object):
|
|
97
|
+
def __init__(self, stream: io.StringIO, filename: Optional[str]) -> None:
|
|
98
|
+
self.stream = stream
|
|
99
|
+
self.filename = filename
|
|
100
|
+
|
|
101
|
+
def write(self, coclass: typedesc.CoClass) -> None:
|
|
102
|
+
print(f"class {coclass.name}(CoClass):", file=self.stream)
|
|
103
|
+
if coclass.doc:
|
|
104
|
+
print(_to_docstring(coclass.doc), file=self.stream)
|
|
105
|
+
print(f" _reg_clsid_ = GUID({coclass.clsid!r})", file=self.stream)
|
|
106
|
+
print(f" _idlflags_ = {coclass.idlflags}", file=self.stream)
|
|
107
|
+
if self.filename is not None:
|
|
108
|
+
print(" _typelib_path_ = typelib_path", file=self.stream)
|
|
109
|
+
# X print
|
|
110
|
+
# >> self.stream, "POINTER(%s).__ctypes_from_outparam__ = wrap" % coclass.name
|
|
111
|
+
|
|
112
|
+
libid = coclass.tlibattr.guid
|
|
113
|
+
wMajor, wMinor = coclass.tlibattr.wMajorVerNum, coclass.tlibattr.wMinorVerNum
|
|
114
|
+
print(
|
|
115
|
+
f" _reg_typelib_ = ({str(libid)!r}, {wMajor}, {wMinor})",
|
|
116
|
+
file=self.stream,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class ComInterfaceHeadWriter(object):
|
|
121
|
+
def __init__(self, stream: io.StringIO) -> None:
|
|
122
|
+
self.stream = stream
|
|
123
|
+
|
|
124
|
+
def _is_enuminterface(self, itf: typedesc.ComInterface) -> bool:
|
|
125
|
+
# Check if this is an IEnumXXX interface
|
|
126
|
+
if not itf.name.startswith("IEnum"):
|
|
127
|
+
return False
|
|
128
|
+
member_names = [mth.name for mth in itf.members]
|
|
129
|
+
for name in ("Next", "Skip", "Reset", "Clone"):
|
|
130
|
+
if name not in member_names:
|
|
131
|
+
return False
|
|
132
|
+
return True
|
|
133
|
+
|
|
134
|
+
def write(self, head: typedesc.ComInterfaceHead, basename: str) -> None:
|
|
135
|
+
if head.itf.base is None:
|
|
136
|
+
# we don't beed to generate IUnknown
|
|
137
|
+
return
|
|
138
|
+
|
|
139
|
+
print(f"class {head.itf.name}({basename}):", file=self.stream)
|
|
140
|
+
if head.itf.doc:
|
|
141
|
+
print(_to_docstring(head.itf.doc), file=self.stream)
|
|
142
|
+
|
|
143
|
+
print(" _case_insensitive_ = True", file=self.stream)
|
|
144
|
+
print(f" _iid_ = GUID({head.itf.iid!r})", file=self.stream)
|
|
145
|
+
print(f" _idlflags_ = {head.itf.idlflags}", file=self.stream)
|
|
146
|
+
|
|
147
|
+
if self._is_enuminterface(head.itf):
|
|
148
|
+
print(file=self.stream)
|
|
149
|
+
print(" def __iter__(self):", file=self.stream)
|
|
150
|
+
print(" return self", file=self.stream)
|
|
151
|
+
print(file=self.stream)
|
|
152
|
+
|
|
153
|
+
print(" def __next__(self):", file=self.stream)
|
|
154
|
+
print(" item, fetched = self.Next(1)", file=self.stream)
|
|
155
|
+
print(" if fetched:", file=self.stream)
|
|
156
|
+
print(" return item", file=self.stream)
|
|
157
|
+
print(" raise StopIteration", file=self.stream)
|
|
158
|
+
print(file=self.stream)
|
|
159
|
+
|
|
160
|
+
print(" def __getitem__(self, index):", file=self.stream)
|
|
161
|
+
print(" self.Reset()", file=self.stream)
|
|
162
|
+
print(" self.Skip(index)", file=self.stream)
|
|
163
|
+
print(" item, fetched = self.Next(1)", file=self.stream)
|
|
164
|
+
print(" if fetched:", file=self.stream)
|
|
165
|
+
print(" return item", file=self.stream)
|
|
166
|
+
print(" raise IndexError(index)", file=self.stream)
|
|
167
|
+
|
|
168
|
+
annotations = typeannotator.ComInterfaceMembersAnnotator(head.itf).generate()
|
|
169
|
+
if annotations:
|
|
170
|
+
print(file=self.stream)
|
|
171
|
+
print(" if TYPE_CHECKING: # commembers", file=self.stream)
|
|
172
|
+
print(annotations, file=self.stream)
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class DispInterfaceHeadWriter(object):
|
|
176
|
+
def __init__(self, stream: io.StringIO) -> None:
|
|
177
|
+
self.stream = stream
|
|
178
|
+
|
|
179
|
+
def write(self, head: typedesc.DispInterfaceHead, basename: str) -> None:
|
|
180
|
+
print(f"class {head.itf.name}({basename}):", file=self.stream)
|
|
181
|
+
if head.itf.doc:
|
|
182
|
+
print(_to_docstring(head.itf.doc), file=self.stream)
|
|
183
|
+
print(" _case_insensitive_ = True", file=self.stream)
|
|
184
|
+
print(f" _iid_ = GUID({head.itf.iid!r})", file=self.stream)
|
|
185
|
+
print(f" _idlflags_ = {head.itf.idlflags}", file=self.stream)
|
|
186
|
+
print(" _methods_ = []", file=self.stream)
|
|
187
|
+
|
|
188
|
+
annotations = typeannotator.DispInterfaceMembersAnnotator(head.itf).generate()
|
|
189
|
+
if annotations:
|
|
190
|
+
print(file=self.stream)
|
|
191
|
+
print(" if TYPE_CHECKING: # dispmembers", file=self.stream)
|
|
192
|
+
print(annotations, file=self.stream)
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import keyword
|
|
2
|
-
from typing import Any
|
|
3
|
-
from typing import List, Tuple
|
|
4
|
-
from typing import Iterator
|
|
2
|
+
from typing import Any, Iterator, List, Tuple
|
|
5
3
|
from typing import Union as _UnionT
|
|
6
4
|
|
|
7
|
-
import comtypes
|
|
8
5
|
from comtypes.tools import typedesc
|
|
9
6
|
from comtypes.tools.codegenerator.modulenamer import name_wrapper_module
|
|
10
7
|
|
|
@@ -317,7 +314,7 @@ class TypeNamer(object):
|
|
|
317
314
|
return f"CFUNCTYPE({', '.join(args)})"
|
|
318
315
|
elif isinstance(t, typedesc.CvQualifiedType):
|
|
319
316
|
# const and volatile are ignored
|
|
320
|
-
return "
|
|
317
|
+
return f"{self(t.typ)}"
|
|
321
318
|
elif isinstance(t, typedesc.FundamentalType):
|
|
322
319
|
return ctypes_names[t.name]
|
|
323
320
|
elif isinstance(t, typedesc.Structure):
|
|
@@ -328,7 +325,7 @@ class TypeNamer(object):
|
|
|
328
325
|
return "c_int" # enums are integers
|
|
329
326
|
elif isinstance(t, typedesc.EnumValue):
|
|
330
327
|
if keyword.iskeyword(t.name):
|
|
331
|
-
return t.name
|
|
328
|
+
return f"{t.name}_"
|
|
332
329
|
return t.name
|
|
333
330
|
elif isinstance(t, typedesc.External):
|
|
334
331
|
# t.symbol_name - symbol to generate
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
from collections import Counter
|
|
2
1
|
import textwrap
|
|
3
|
-
from typing import overload
|
|
4
|
-
from typing import Optional, Union as _UnionT
|
|
5
|
-
from typing import Dict, List, Set, Tuple
|
|
6
|
-
from typing import Iterator, Mapping, Sequence
|
|
7
2
|
import warnings
|
|
3
|
+
from collections import Counter
|
|
4
|
+
from typing import (
|
|
5
|
+
Dict,
|
|
6
|
+
Iterator,
|
|
7
|
+
List,
|
|
8
|
+
Mapping,
|
|
9
|
+
Optional,
|
|
10
|
+
Sequence,
|
|
11
|
+
Set,
|
|
12
|
+
Tuple,
|
|
13
|
+
overload,
|
|
14
|
+
)
|
|
15
|
+
from typing import Union as _UnionT
|
|
8
16
|
|
|
9
17
|
|
|
10
18
|
class ImportedNamespaces(object):
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import abc
|
|
2
2
|
import keyword
|
|
3
|
-
from typing import
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
from typing import (
|
|
4
|
+
Any,
|
|
5
|
+
Dict,
|
|
6
|
+
Generic,
|
|
7
|
+
Iterable,
|
|
8
|
+
Iterator,
|
|
9
|
+
List,
|
|
10
|
+
Optional,
|
|
11
|
+
Protocol,
|
|
12
|
+
Sequence,
|
|
13
|
+
Tuple,
|
|
14
|
+
TypeVar,
|
|
15
|
+
)
|
|
6
16
|
|
|
7
17
|
from comtypes.tools import typedesc
|
|
8
18
|
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import sys
|
|
3
|
-
from
|
|
4
|
-
from typing import Dict, List, Optional, Tuple
|
|
5
|
-
from ctypes import alignment, byref, c_void_p, sizeof, windll
|
|
3
|
+
from ctypes import alignment, c_void_p, sizeof, windll
|
|
4
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
6
5
|
|
|
7
|
-
from comtypes import
|
|
8
|
-
from comtypes.tools import typedesc
|
|
6
|
+
from comtypes import BSTR, COMError, automation, typeinfo
|
|
9
7
|
from comtypes.client._code_cache import _get_module_filename
|
|
10
|
-
|
|
8
|
+
from comtypes.tools import typedesc
|
|
11
9
|
|
|
12
10
|
# Is the process 64-bit?
|
|
13
11
|
is_64bits = sys.maxsize > 2**32
|
|
@@ -237,7 +235,7 @@ class Parser(object):
|
|
|
237
235
|
elif fd.callconv == typeinfo.CC_STDCALL:
|
|
238
236
|
attributes = "__stdcall__"
|
|
239
237
|
else:
|
|
240
|
-
raise ValueError("calling convention
|
|
238
|
+
raise ValueError(f"calling convention {fd.callconv:d}")
|
|
241
239
|
|
|
242
240
|
func = typedesc.Function(func_name, returns, attributes, extern=1)
|
|
243
241
|
if func_doc is not None:
|
|
@@ -741,28 +739,29 @@ def get_tlib_filename(tlib: typeinfo.ITypeLib) -> Optional[str]:
|
|
|
741
739
|
# seems if the typelib is not registered, there's no way to
|
|
742
740
|
# determine the filename.
|
|
743
741
|
la = tlib.GetLibAttr()
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
742
|
+
try:
|
|
743
|
+
full_filename = typeinfo.QueryPathOfRegTypeLib(
|
|
744
|
+
str(la.guid), la.wMajorVerNum, la.wMinorVerNum
|
|
745
|
+
)
|
|
746
|
+
except OSError:
|
|
747
|
+
return None
|
|
748
|
+
|
|
749
|
+
if not os.path.isabs(full_filename):
|
|
750
|
+
# workaround Windows 7 bug in QueryPathOfRegTypeLib returning relative path
|
|
751
|
+
try:
|
|
752
|
+
dll = windll.LoadLibrary(full_filename)
|
|
753
|
+
full_filename = _get_module_filename(dll._handle)
|
|
754
|
+
del dll
|
|
755
|
+
except OSError:
|
|
756
|
+
return None
|
|
757
|
+
return full_filename
|
|
759
758
|
|
|
760
759
|
|
|
761
760
|
def _py2exe_hint():
|
|
762
761
|
# If the tlbparser is frozen, we need to include these
|
|
762
|
+
import comtypes.automation
|
|
763
763
|
import comtypes.persist
|
|
764
764
|
import comtypes.typeinfo
|
|
765
|
-
import comtypes.automation
|
|
766
765
|
|
|
767
766
|
|
|
768
767
|
# -eof-
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
# in typedesc_base
|
|
3
3
|
|
|
4
4
|
import ctypes
|
|
5
|
-
from typing import Any, List, Optional, Sequence, Tuple
|
|
5
|
+
from typing import Any, List, Optional, Sequence, Tuple
|
|
6
|
+
from typing import Union as _UnionT
|
|
6
7
|
|
|
7
8
|
from comtypes import typeinfo
|
|
8
|
-
from comtypes.typeinfo import ITypeLib, TLIBATTR
|
|
9
9
|
from comtypes.tools.typedesc_base import *
|
|
10
|
+
from comtypes.typeinfo import TLIBATTR, ITypeLib
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class TypeLib(object):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# typedesc.py - classes representing C type descriptions
|
|
2
|
-
from typing import Any, SupportsInt
|
|
3
|
-
from typing import
|
|
2
|
+
from typing import Any, List, Optional, SupportsInt, Tuple
|
|
3
|
+
from typing import Union as _UnionT
|
|
4
4
|
|
|
5
5
|
import comtypes
|
|
6
6
|
|