comtypes 1.4.9__zip → 1.4.11__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.11}/CHANGES.txt +41 -0
- {comtypes-1.4.9/comtypes.egg-info → comtypes-1.4.11}/PKG-INFO +4 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/GUID.py +34 -13
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/__init__.py +25 -16
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_comobject.py +92 -39
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_memberspec.py +112 -78
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_meta.py +2 -1
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_post_coinit/_cominterface_meta_patcher.py +3 -6
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_post_coinit/bstr.py +12 -5
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_post_coinit/instancemethod.py +1 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_post_coinit/misc.py +59 -24
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_post_coinit/unknwn.py +30 -25
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_safearray.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_vtbl.py +52 -55
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/automation.py +19 -14
- comtypes-1.4.11/comtypes/client/__init__.py +42 -0
- comtypes-1.4.11/comtypes/client/_activeobj.py +46 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/client/_code_cache.py +15 -24
- comtypes-1.4.11/comtypes/client/_create.py +147 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/client/_events.py +140 -57
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/client/_generate.py +3 -5
- comtypes-1.4.11/comtypes/client/_managing.py +114 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/client/dynamic.py +2 -3
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/client/lazybind.py +10 -11
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/connectionpoints.py +38 -3
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/errorinfo.py +72 -21
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/git.py +4 -3
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/hints.pyi +15 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/hresult.py +16 -6
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/logutil.py +15 -3
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/messageloop.py +15 -13
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/persist.py +3 -5
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/safearray.py +8 -6
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/server/__init__.py +22 -4
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/server/automation.py +1 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/server/connectionpoints.py +71 -70
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/server/inprocserver.py +14 -8
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/server/localserver.py +28 -16
- comtypes-1.4.11/comtypes/server/register.py +478 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/shelllink.py +13 -7
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/stream.py +7 -4
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/TestComServer.py +6 -7
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/TestDispServer.py +4 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/__init__.py +1 -1
- comtypes-1.4.11/comtypes/test/find_memleak.py +72 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/runtests.py +1 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/setup.py +2 -1
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_BSTR.py +7 -17
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_GUID.py +7 -7
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_QueryService.py +1 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_agilent.py +4 -3
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_basic.py +18 -9
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_clear_cache.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_client.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_client_dynamic.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_client_regenerate_modules.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_collections.py +7 -4
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_comobject.py +22 -9
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_comserver.py +56 -3
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_dict.py +2 -1
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_dispifc_records.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_dispifc_safearrays.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_dyndispatch.py +5 -2
- comtypes-1.4.11/comtypes/test/test_errorinfo.py +115 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_findgendir.py +1 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_getactiveobj.py +4 -4
- comtypes-1.4.11/comtypes/test/test_hresult.py +48 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_ie.py +19 -6
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_ienum.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_imfattributes.py +13 -3
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_inout_args.py +10 -3
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_midl_safearray_create.py +6 -4
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_monikers.py +23 -9
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_msscript.py +2 -1
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_npsupport.py +4 -4
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_outparam.py +22 -6
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_persist.py +2 -4
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_recordinfo.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_safearray.py +2 -1
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_sapi.py +4 -1
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_server_register.py +114 -125
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_shelllink.py +2 -3
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_storage.py +12 -6
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_stream.py +16 -5
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_subinterface.py +4 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_typeannotator.py +1 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_typeinfo.py +36 -7
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_urlhistory.py +7 -4
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_variant.py +5 -3
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_w_getopt.py +4 -4
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_word.py +1 -1
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/codegenerator.py +167 -435
- comtypes-1.4.11/comtypes/tools/codegenerator/comments.py +79 -0
- comtypes-1.4.11/comtypes/tools/codegenerator/heads.py +192 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/helpers.py +3 -6
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/namespaces.py +13 -5
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/typeannotator.py +13 -3
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/tlbparser.py +25 -25
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/typedesc.py +3 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/typedesc_base.py +2 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/typeinfo.py +163 -51
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/viewobject.py +2 -4
- {comtypes-1.4.9 → comtypes-1.4.11/comtypes.egg-info}/PKG-INFO +4 -2
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes.egg-info/SOURCES.txt +7 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/pyproject.toml +10 -23
- 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.11}/LICENSE.txt +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/MANIFEST.in +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/README.md +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_npsupport.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_post_coinit/__init__.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/_tlib_version_checker.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/clear_cache.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/client/_constants.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/patcher.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/server/w_getopt.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/TestComServer.idl +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/TestComServer.tlb +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/TestDispServer.idl +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/TestDispServer.tlb +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/mylib.idl +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/mylib.tlb +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/mytypelib.idl +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_DISPPARAMS.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_avmc.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_casesensitivity.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_createwrappers.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_dispinterface.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_excel.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_jscript.js +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_pump_events.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_server.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_showevents.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_win32com_interop.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/test_wmi.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/test/urlhist.tlb +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/__init__.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/__init__.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/modulenamer.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/tools/codegenerator/packing.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes/util.py +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes.egg-info/dependency_links.txt +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes.egg-info/entry_points.txt +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/comtypes.egg-info/top_level.txt +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/setup.cfg +0 -0
- {comtypes-1.4.9 → comtypes-1.4.11}/setup.py +0 -0
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
from
|
|
4
|
-
from
|
|
5
|
-
from
|
|
1
|
+
import functools
|
|
2
|
+
import logging
|
|
3
|
+
from _ctypes import COMError
|
|
4
|
+
from ctypes import c_void_p, pointer
|
|
5
|
+
from ctypes.wintypes import DWORD
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Callable, Dict, Iterator, List, Tuple, Type
|
|
7
|
+
from typing import Union as _UnionT
|
|
8
|
+
|
|
9
|
+
from comtypes import GUID, COMObject, IUnknown
|
|
6
10
|
from comtypes.automation import IDispatch
|
|
11
|
+
from comtypes.connectionpoints import IConnectionPoint
|
|
12
|
+
from comtypes.hresult import *
|
|
13
|
+
from comtypes.typeinfo import ITypeInfo, LoadRegTypeLib
|
|
7
14
|
|
|
8
|
-
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from ctypes import _Pointer
|
|
17
|
+
from typing import ClassVar
|
|
18
|
+
|
|
19
|
+
from comtypes import hints # type: ignore
|
|
9
20
|
|
|
10
21
|
logger = logging.getLogger(__name__)
|
|
11
22
|
|
|
@@ -17,9 +28,11 @@ class ConnectionPointImpl(COMObject):
|
|
|
17
28
|
|
|
18
29
|
_com_interfaces_ = [IConnectionPoint]
|
|
19
30
|
|
|
20
|
-
def __init__(
|
|
31
|
+
def __init__(
|
|
32
|
+
self, sink_interface: Type[IUnknown], sink_typeinfo: ITypeInfo
|
|
33
|
+
) -> None:
|
|
21
34
|
super(ConnectionPointImpl, self).__init__()
|
|
22
|
-
self._connections = {}
|
|
35
|
+
self._connections: Dict[int, IUnknown] = {}
|
|
23
36
|
self._cookie = 0
|
|
24
37
|
self._sink_interface = sink_interface
|
|
25
38
|
self._typeinfo = sink_typeinfo
|
|
@@ -27,7 +40,9 @@ class ConnectionPointImpl(COMObject):
|
|
|
27
40
|
# per MSDN, all interface methods *must* be implemented, E_NOTIMPL
|
|
28
41
|
# is no allowed return value
|
|
29
42
|
|
|
30
|
-
def IConnectionPoint_Advise(
|
|
43
|
+
def IConnectionPoint_Advise(
|
|
44
|
+
self, this: Any, pUnk: IUnknown, pdwCookie: "_Pointer[DWORD]"
|
|
45
|
+
) -> "hints.Hresult":
|
|
31
46
|
if not pUnk or not pdwCookie:
|
|
32
47
|
return E_POINTER
|
|
33
48
|
logger.debug("Advise")
|
|
@@ -39,7 +54,7 @@ class ConnectionPointImpl(COMObject):
|
|
|
39
54
|
self._connections[self._cookie] = ptr
|
|
40
55
|
return S_OK
|
|
41
56
|
|
|
42
|
-
def IConnectionPoint_Unadvise(self, this, dwCookie):
|
|
57
|
+
def IConnectionPoint_Unadvise(self, this: Any, dwCookie: int) -> "hints.Hresult":
|
|
43
58
|
logger.debug("Unadvise %s", dwCookie)
|
|
44
59
|
try:
|
|
45
60
|
del self._connections[dwCookie]
|
|
@@ -47,13 +62,17 @@ class ConnectionPointImpl(COMObject):
|
|
|
47
62
|
return CONNECT_E_NOCONNECTION
|
|
48
63
|
return S_OK
|
|
49
64
|
|
|
50
|
-
def IConnectionPoint_GetConnectionPointContainer(
|
|
65
|
+
def IConnectionPoint_GetConnectionPointContainer(
|
|
66
|
+
self, this: Any, ppCPC: c_void_p
|
|
67
|
+
) -> "hints.Hresult":
|
|
51
68
|
return E_NOTIMPL
|
|
52
69
|
|
|
53
|
-
def IConnectionPoint_GetConnectionInterface(
|
|
70
|
+
def IConnectionPoint_GetConnectionInterface(
|
|
71
|
+
self, this: Any, pIID: "_Pointer[GUID]"
|
|
72
|
+
) -> "hints.Hresult":
|
|
54
73
|
return E_NOTIMPL
|
|
55
74
|
|
|
56
|
-
def _call_sinks(self, name, *args, **kw):
|
|
75
|
+
def _call_sinks(self, name: str, *args: Any, **kw: Any) -> List[Any]:
|
|
57
76
|
results = []
|
|
58
77
|
logger.debug("_call_sinks(%s, %s, *%s, **%s)", self, name, args, kw)
|
|
59
78
|
# Is it an IDispatch derived interface? Then, events have to be delivered
|
|
@@ -62,61 +81,33 @@ class ConnectionPointImpl(COMObject):
|
|
|
62
81
|
# for better performance, we could cache the dispids.
|
|
63
82
|
dispid = self._typeinfo.GetIDsOfNames(name)[0]
|
|
64
83
|
for key, p in self._connections.items():
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
except COMError as details:
|
|
68
|
-
if details.hresult == -2147023174:
|
|
69
|
-
logger.warning(
|
|
70
|
-
"_call_sinks(%s, %s, *%s, **%s) failed; removing connection",
|
|
71
|
-
self,
|
|
72
|
-
name,
|
|
73
|
-
args,
|
|
74
|
-
kw,
|
|
75
|
-
exc_info=True,
|
|
76
|
-
)
|
|
77
|
-
try:
|
|
78
|
-
del self._connections[key]
|
|
79
|
-
except KeyError:
|
|
80
|
-
pass # connection already gone
|
|
81
|
-
else:
|
|
82
|
-
logger.warning(
|
|
83
|
-
"_call_sinks(%s, %s, *%s, **%s)",
|
|
84
|
-
self,
|
|
85
|
-
name,
|
|
86
|
-
args,
|
|
87
|
-
kw,
|
|
88
|
-
exc_info=True,
|
|
89
|
-
)
|
|
90
|
-
else:
|
|
91
|
-
results.append(result)
|
|
84
|
+
mth = functools.partial(p.Invoke, dispid) # type: ignore
|
|
85
|
+
results.extend(self._call_sink(name, key, mth, *args, **kw))
|
|
92
86
|
else:
|
|
93
|
-
for p in self._connections.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
except COMError as details:
|
|
97
|
-
if details.hresult == -2147023174:
|
|
98
|
-
logger.warning(
|
|
99
|
-
"_call_sinks(%s, %s, *%s, **%s) failed; removing connection",
|
|
100
|
-
self,
|
|
101
|
-
name,
|
|
102
|
-
args,
|
|
103
|
-
kw,
|
|
104
|
-
exc_info=True,
|
|
105
|
-
)
|
|
106
|
-
del self._connections[key]
|
|
107
|
-
else:
|
|
108
|
-
logger.warning(
|
|
109
|
-
"_call_sinks(%s, %s, *%s, **%s)",
|
|
110
|
-
self,
|
|
111
|
-
name,
|
|
112
|
-
args,
|
|
113
|
-
kw,
|
|
114
|
-
exc_info=True,
|
|
115
|
-
)
|
|
116
|
-
else:
|
|
117
|
-
results.append(result)
|
|
87
|
+
for key, p in self._connections.items():
|
|
88
|
+
mth = getattr(p, name)
|
|
89
|
+
results.extend(self._call_sink(name, key, mth, *args, **kw))
|
|
118
90
|
return results
|
|
119
91
|
|
|
92
|
+
def _call_sink(
|
|
93
|
+
self, name: str, key: int, mth: Callable[..., Any], *args: Any, **kw: Any
|
|
94
|
+
) -> Iterator[Any]:
|
|
95
|
+
try:
|
|
96
|
+
result = mth(*args, **kw)
|
|
97
|
+
except COMError as details:
|
|
98
|
+
if details.hresult == RPC_S_SERVER_UNAVAILABLE:
|
|
99
|
+
warn_msg = "_call_sinks(%s, %s, *%s, **%s) failed; removing connection"
|
|
100
|
+
logger.warning(warn_msg, self, name, args, kw, exc_info=True)
|
|
101
|
+
try:
|
|
102
|
+
del self._connections[key]
|
|
103
|
+
except KeyError:
|
|
104
|
+
pass # connection already gone
|
|
105
|
+
else:
|
|
106
|
+
warn_msg = "_call_sinks(%s, %s, *%s, **%s)"
|
|
107
|
+
logger.warning(warn_msg, self, name, args, kw, exc_info=True)
|
|
108
|
+
else:
|
|
109
|
+
yield result
|
|
110
|
+
|
|
120
111
|
|
|
121
112
|
class ConnectableObjectMixin(object):
|
|
122
113
|
"""Mixin which implements IConnectionPointContainer.
|
|
@@ -126,22 +117,30 @@ class ConnectableObjectMixin(object):
|
|
|
126
117
|
integer index into the _outgoing_interfaces_ list.
|
|
127
118
|
"""
|
|
128
119
|
|
|
129
|
-
|
|
120
|
+
if TYPE_CHECKING:
|
|
121
|
+
_outgoing_interfaces_: ClassVar[List[Type[IDispatch]]]
|
|
122
|
+
_reg_typelib_: ClassVar[Tuple[str, int, int]]
|
|
123
|
+
|
|
124
|
+
def __init__(self) -> None:
|
|
130
125
|
super(ConnectableObjectMixin, self).__init__()
|
|
131
|
-
self.__connections = {}
|
|
126
|
+
self.__connections: Dict[Type[IDispatch], ConnectionPointImpl] = {}
|
|
132
127
|
|
|
133
128
|
tlib = LoadRegTypeLib(*self._reg_typelib_)
|
|
134
129
|
for itf in self._outgoing_interfaces_:
|
|
135
130
|
typeinfo = tlib.GetTypeInfoOfGuid(itf._iid_)
|
|
136
131
|
self.__connections[itf] = ConnectionPointImpl(itf, typeinfo)
|
|
137
132
|
|
|
138
|
-
def IConnectionPointContainer_EnumConnectionPoints(
|
|
133
|
+
def IConnectionPointContainer_EnumConnectionPoints(
|
|
134
|
+
self, this: Any, ppEnum: c_void_p
|
|
135
|
+
) -> "hints.Hresult":
|
|
139
136
|
# according to MSDN, E_NOTIMPL is specificially disallowed
|
|
140
137
|
# because, without typeinfo, there's no way for the caller to
|
|
141
138
|
# find out.
|
|
142
139
|
return E_NOTIMPL
|
|
143
140
|
|
|
144
|
-
def IConnectionPointContainer_FindConnectionPoint(
|
|
141
|
+
def IConnectionPointContainer_FindConnectionPoint(
|
|
142
|
+
self, this: Any, refiid: "_Pointer[GUID]", ppcp: c_void_p
|
|
143
|
+
) -> "hints.Hresult":
|
|
145
144
|
iid = refiid[0]
|
|
146
145
|
logger.debug("FindConnectionPoint %s", iid)
|
|
147
146
|
if not ppcp:
|
|
@@ -161,7 +160,9 @@ class ConnectableObjectMixin(object):
|
|
|
161
160
|
logger.debug("No connectionpoint found")
|
|
162
161
|
return CONNECT_E_NOCONNECTION
|
|
163
162
|
|
|
164
|
-
def Fire_Event(
|
|
163
|
+
def Fire_Event(
|
|
164
|
+
self, itf: _UnionT[int, Type[IDispatch]], name: str, *args: Any, **kw: Any
|
|
165
|
+
) -> Any:
|
|
165
166
|
# Fire event 'name' with arguments *args and **kw.
|
|
166
167
|
# Accepts either an interface index or an interface as first argument.
|
|
167
168
|
# Returns a list of results.
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import ctypes
|
|
2
1
|
import logging
|
|
3
2
|
import sys
|
|
4
3
|
import winreg
|
|
5
|
-
from
|
|
4
|
+
from ctypes import c_void_p, pointer
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Literal, Optional, Type
|
|
6
6
|
|
|
7
7
|
from comtypes import GUID, COMObject, IUnknown, hresult
|
|
8
|
+
from comtypes._comobject import InprocServer as _InprocRefCounter
|
|
8
9
|
from comtypes.server import IClassFactory
|
|
9
10
|
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from ctypes import _Pointer
|
|
13
|
+
|
|
10
14
|
logger = logging.getLogger(__name__)
|
|
11
15
|
_debug = logger.debug
|
|
12
16
|
_critical = logger.critical
|
|
@@ -24,9 +28,9 @@ class ClassFactory(COMObject):
|
|
|
24
28
|
def IClassFactory_CreateInstance(
|
|
25
29
|
self,
|
|
26
30
|
this: Any,
|
|
27
|
-
punkOuter: Optional[Type["
|
|
28
|
-
riid: "
|
|
29
|
-
ppv:
|
|
31
|
+
punkOuter: Optional[Type["_Pointer[IUnknown]"]],
|
|
32
|
+
riid: "_Pointer[GUID]",
|
|
33
|
+
ppv: c_void_p,
|
|
30
34
|
) -> int:
|
|
31
35
|
_debug("ClassFactory.CreateInstance(%s)", riid[0])
|
|
32
36
|
result = self._cls().IUnknown_QueryInterface(None, riid, ppv)
|
|
@@ -34,6 +38,7 @@ class ClassFactory(COMObject):
|
|
|
34
38
|
return result
|
|
35
39
|
|
|
36
40
|
def IClassFactory_LockServer(self, this: Any, fLock: bool) -> Literal[0]:
|
|
41
|
+
assert COMObject.__server__ is not None, "The inprocserver is not running yet"
|
|
37
42
|
if fLock:
|
|
38
43
|
COMObject.__server__.Lock()
|
|
39
44
|
else:
|
|
@@ -55,7 +60,7 @@ def inproc_find_class(clsid: GUID) -> Type[COMObject]:
|
|
|
55
60
|
except:
|
|
56
61
|
_debug("NO path to insert")
|
|
57
62
|
else:
|
|
58
|
-
if not
|
|
63
|
+
if pathdir not in sys.path:
|
|
59
64
|
sys.path.insert(0, str(pathdir))
|
|
60
65
|
_debug("insert path %r", pathdir)
|
|
61
66
|
else:
|
|
@@ -135,7 +140,7 @@ def DllGetClassObject(rclsid: int, riid: int, ppv: int) -> int:
|
|
|
135
140
|
return hresult.CLASS_E_CLASSNOTAVAILABLE
|
|
136
141
|
|
|
137
142
|
result = ClassFactory(cls).IUnknown_QueryInterface(
|
|
138
|
-
None,
|
|
143
|
+
None, pointer(iid), c_void_p(ppv)
|
|
139
144
|
)
|
|
140
145
|
_debug("DllGetClassObject() -> %s", result)
|
|
141
146
|
return result
|
|
@@ -146,7 +151,8 @@ def DllGetClassObject(rclsid: int, riid: int, ppv: int) -> int:
|
|
|
146
151
|
|
|
147
152
|
def DllCanUnloadNow() -> Literal[1]: # S_FALSE
|
|
148
153
|
COMObject.__run_inprocserver__()
|
|
149
|
-
|
|
154
|
+
assert isinstance(COMObject.__server__, _InprocRefCounter)
|
|
155
|
+
result = COMObject.__server__.DllCanUnloadNow() # noqa
|
|
150
156
|
# To avoid a memory leak when PyInitialize()/PyUninitialize() are
|
|
151
157
|
# called several times, we refuse to unload the dll.
|
|
152
158
|
return hresult.S_FALSE
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import queue
|
|
3
|
-
import
|
|
4
|
-
from ctypes import
|
|
3
|
+
from ctypes import HRESULT, POINTER, OleDLL, byref, c_ulong, c_void_p
|
|
4
|
+
from ctypes.wintypes import DWORD, LPDWORD
|
|
5
5
|
from typing import TYPE_CHECKING, Any, Literal, Optional, Sequence, Type
|
|
6
6
|
|
|
7
7
|
import comtypes
|
|
8
|
-
from comtypes import hresult
|
|
8
|
+
from comtypes import GUID, COMObject, IUnknown, hresult
|
|
9
9
|
from comtypes.server import IClassFactory
|
|
10
10
|
|
|
11
11
|
if TYPE_CHECKING:
|
|
@@ -21,19 +21,30 @@ REGCLS_MULTI_SEPARATE = 2 # multiple use, but separate control over each
|
|
|
21
21
|
REGCLS_SUSPENDED = 4 # register it as suspended, will be activated
|
|
22
22
|
REGCLS_SURROGATE = 8 # must be used when a surrogate process
|
|
23
23
|
|
|
24
|
+
_ole32 = OleDLL("ole32")
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
REFCLSID = POINTER(GUID)
|
|
27
|
+
_CoRegisterClassObject = _ole32.CoRegisterClassObject
|
|
28
|
+
_CoRegisterClassObject.argtypes = [REFCLSID, c_void_p, DWORD, DWORD, LPDWORD]
|
|
29
|
+
_CoRegisterClassObject.restype = HRESULT
|
|
30
|
+
|
|
31
|
+
_CoRevokeClassObject = _ole32.CoRevokeClassObject
|
|
32
|
+
_CoRevokeClassObject.argtypes = [DWORD]
|
|
33
|
+
_CoRevokeClassObject.restype = HRESULT
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def run(classes: Sequence[Type[COMObject]]) -> None:
|
|
26
37
|
classobjects = [ClassFactory(cls) for cls in classes]
|
|
27
|
-
|
|
38
|
+
COMObject.__run_localserver__(classobjects)
|
|
28
39
|
|
|
29
40
|
|
|
30
|
-
class ClassFactory(
|
|
41
|
+
class ClassFactory(COMObject):
|
|
31
42
|
_com_interfaces_ = [IClassFactory]
|
|
32
43
|
_locks: int = 0
|
|
33
44
|
_queue: Optional[queue.Queue] = None
|
|
34
45
|
regcls: int = REGCLS_MULTIPLEUSE
|
|
35
46
|
|
|
36
|
-
def __init__(self, cls: Type[
|
|
47
|
+
def __init__(self, cls: Type[COMObject], *args, **kw) -> None:
|
|
37
48
|
super(ClassFactory, self).__init__()
|
|
38
49
|
self._cls = cls
|
|
39
50
|
self._register_class()
|
|
@@ -49,11 +60,11 @@ class ClassFactory(comtypes.COMObject):
|
|
|
49
60
|
def _register_class(self) -> None:
|
|
50
61
|
regcls = getattr(self._cls, "_regcls_", self.regcls)
|
|
51
62
|
cookie = c_ulong()
|
|
52
|
-
ptr = self._com_pointers_[
|
|
53
|
-
clsctx = self._cls._reg_clsctx_
|
|
63
|
+
ptr = self._com_pointers_[IUnknown._iid_]
|
|
64
|
+
clsctx = self._cls._reg_clsctx_ # type: ignore
|
|
54
65
|
clsctx &= ~comtypes.CLSCTX_INPROC # reset the inproc flags
|
|
55
|
-
|
|
56
|
-
byref(
|
|
66
|
+
_CoRegisterClassObject(
|
|
67
|
+
byref(GUID(self._cls._reg_clsid_)),
|
|
57
68
|
ptr,
|
|
58
69
|
clsctx,
|
|
59
70
|
regcls,
|
|
@@ -62,13 +73,13 @@ class ClassFactory(comtypes.COMObject):
|
|
|
62
73
|
self.cookie = cookie
|
|
63
74
|
|
|
64
75
|
def _revoke_class(self) -> None:
|
|
65
|
-
|
|
76
|
+
_CoRevokeClassObject(self.cookie)
|
|
66
77
|
|
|
67
78
|
def CreateInstance(
|
|
68
79
|
self,
|
|
69
80
|
this: Any,
|
|
70
|
-
punkOuter: Optional[Type["_Pointer[
|
|
71
|
-
riid: "_Pointer[
|
|
81
|
+
punkOuter: Optional[Type["_Pointer[IUnknown]"]],
|
|
82
|
+
riid: "_Pointer[GUID]",
|
|
72
83
|
ppv: c_void_p,
|
|
73
84
|
) -> int:
|
|
74
85
|
_debug("ClassFactory.CreateInstance(%s)", riid[0])
|
|
@@ -78,8 +89,9 @@ class ClassFactory(comtypes.COMObject):
|
|
|
78
89
|
return result
|
|
79
90
|
|
|
80
91
|
def LockServer(self, this: Any, fLock: bool) -> Literal[0]:
|
|
92
|
+
assert COMObject.__server__ is not None, "The localserver is not running yet"
|
|
81
93
|
if fLock:
|
|
82
|
-
|
|
94
|
+
COMObject.__server__.Lock()
|
|
83
95
|
else:
|
|
84
|
-
|
|
96
|
+
COMObject.__server__.Unlock()
|
|
85
97
|
return hresult.S_OK
|