winrt-runtime 3.1.0__tar.gz → 3.2.0__tar.gz

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 (28) hide show
  1. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/PKG-INFO +1 -1
  2. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/_winrt.cpp +9 -3
  3. winrt_runtime-3.2.0/_winrt_buffer.cpp +59 -0
  4. winrt_runtime-3.2.0/pywinrt-version.txt +1 -0
  5. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/runtime.cpp +43 -0
  6. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/setup.py +3 -1
  7. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/src/winrt/_winrt.pyi +2 -2
  8. winrt_runtime-3.2.0/src/winrt/runtime/_internals.py +247 -0
  9. winrt_runtime-3.2.0/src/winrt/runtime/py.typed +0 -0
  10. winrt_runtime-3.2.0/src/winrt/system/__init__.py +113 -0
  11. winrt_runtime-3.2.0/src/winrt/system/hresult.py +48 -0
  12. winrt_runtime-3.2.0/src/winrt/system/py.typed +0 -0
  13. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/src/winrt_runtime.egg-info/PKG-INFO +1 -1
  14. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/src/winrt_runtime.egg-info/SOURCES.txt +5 -0
  15. winrt_runtime-3.1.0/pywinrt-version.txt +0 -1
  16. winrt_runtime-3.1.0/src/winrt/system/__init__.py +0 -285
  17. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/README.md +0 -0
  18. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/_winrt_array.cpp +0 -0
  19. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/_winrt_box.cpp +0 -0
  20. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/pyproject.toml +0 -0
  21. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/requirements.txt +0 -0
  22. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/setup.cfg +0 -0
  23. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/src/winrt/py.typed +0 -0
  24. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/src/winrt/runtime/__init__.py +0 -0
  25. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/src/winrt/runtime/interop.py +0 -0
  26. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/src/winrt_runtime.egg-info/dependency_links.txt +0 -0
  27. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/src/winrt_runtime.egg-info/requires.txt +0 -0
  28. {winrt_runtime-3.1.0 → winrt_runtime-3.2.0}/src/winrt_runtime.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: winrt-runtime
3
- Version: 3.1.0
3
+ Version: 3.2.0
4
4
  Summary: Python projection of Windows Runtime (WinRT) APIs
5
5
  License-Expression: MIT
6
6
  Project-URL: Documentation, https://pywinrt.readthedocs.io
@@ -398,6 +398,8 @@ namespace py::cpp::_winrt
398
398
  .get_object_type = py::get_object_type,
399
399
  .array_new = py::cpp::_winrt::Array_New,
400
400
  .array_assign = &py::cpp::_winrt::Array_Assign,
401
+ .await_async = py::await_async,
402
+ .convert_to_ibuffer = py::convert_to_ibuffer,
401
403
  };
402
404
 
403
405
  static PyObject* init_apartment(PyObject* /*unused*/, PyObject* type_obj) noexcept
@@ -558,6 +560,7 @@ namespace py::cpp::_winrt
558
560
  Py_VISIT(state->array_type);
559
561
  Py_VISIT(state->mapping_iter_type);
560
562
  Py_VISIT(state->to_uuid_func);
563
+ Py_VISIT(state->wrap_async_func);
561
564
 
562
565
  for (const auto& [key, value] : state->type_cache)
563
566
  {
@@ -576,6 +579,7 @@ namespace py::cpp::_winrt
576
579
  Py_CLEAR(state->array_type);
577
580
  Py_CLEAR(state->mapping_iter_type);
578
581
  Py_CLEAR(state->to_uuid_func);
582
+ Py_CLEAR(state->wrap_async_func);
579
583
 
580
584
  auto type_cache = std::move(state->type_cache);
581
585
 
@@ -596,6 +600,7 @@ namespace py::cpp::_winrt
596
600
  Py_XDECREF(state->array_type);
597
601
  Py_XDECREF(state->mapping_iter_type);
598
602
  Py_XDECREF(state->to_uuid_func);
603
+ Py_XDECREF(state->wrap_async_func);
599
604
 
600
605
  for (auto& [key, value] : state->type_cache)
601
606
  {
@@ -653,15 +658,15 @@ namespace py::cpp::_winrt
653
658
  METH_VARARGS,
654
659
  PyDoc_STR(
655
660
  "interop function to invoke IInitializeWithWindow::Initialize on an object")},
656
- {"_add_dll_directory",
661
+ {"add_dll_directory",
657
662
  add_dll_directory,
658
663
  METH_O,
659
664
  PyDoc_STR("Adds a directory to the DLL search path.")},
660
- {"_remove_dll_directory",
665
+ {"remove_dll_directory",
661
666
  remove_dll_directory,
662
667
  METH_O,
663
668
  PyDoc_STR(
664
- "Removes a directory that was added to the process DLL search path by using _add_dll_directory.")},
669
+ "Removes a directory that was added to the process DLL search path by using add_dll_directory.")},
665
670
  {"box_boolean", box_boolean, METH_O, PyDoc_STR("Box a Boolean value")},
666
671
  {"box_char16", box_char16, METH_O, PyDoc_STR("Box a Char16 value")},
667
672
  {"box_string", box_string, METH_O, PyDoc_STR("Box a string value")},
@@ -803,6 +808,7 @@ namespace py::cpp::_winrt
803
808
  state->array_type = array_type.detach();
804
809
  state->mapping_iter_type = mapping_iter_type.detach();
805
810
  state->to_uuid_func = to_uuid_func.detach();
811
+ state->wrap_async_func = nullptr; // lazy-initialized
806
812
 
807
813
  return module.detach();
808
814
  }
@@ -0,0 +1,59 @@
1
+ #define PYWINRT_RUNTIME_MODULE
2
+ #include <Python.h>
3
+ #include <Robuffer.h>
4
+ #include "pybase.h"
5
+ #include <winrt/base.h>
6
+
7
+ namespace py::cpp::_winrt
8
+ {
9
+ struct PyWinRTBuffer : winrt::implements<
10
+ PyWinRTBuffer,
11
+ winrt::Windows::Storage::Streams::IBuffer,
12
+ Windows::Storage::Streams::IBufferByteAccess>
13
+ {
14
+ private:
15
+ Py_buffer buffer;
16
+
17
+ public:
18
+ PyWinRTBuffer(PyObject* obj)
19
+ {
20
+ if (PyObject_GetBuffer(obj, &buffer, PyBUF_SIMPLE) == -1)
21
+ {
22
+ throw python_exception();
23
+ };
24
+ }
25
+
26
+ ~PyWinRTBuffer()
27
+ {
28
+ PyBuffer_Release(&buffer);
29
+ }
30
+
31
+ uint32_t Capacity() const
32
+ {
33
+ return static_cast<uint32_t>(buffer.len);
34
+ }
35
+
36
+ uint32_t Length() const
37
+ {
38
+ return static_cast<uint32_t>(buffer.len);
39
+ }
40
+
41
+ void Length(uint32_t /*unused*/)
42
+ {
43
+ // can't resize Python buffers.
44
+ throw winrt::hresult_not_implemented{};
45
+ }
46
+
47
+ HRESULT __stdcall Buffer(uint8_t** value)
48
+ {
49
+ *value = reinterpret_cast<uint8_t*>(buffer.buf);
50
+ return S_OK;
51
+ }
52
+ };
53
+
54
+ } // namespace py::cpp::_winrt
55
+
56
+ winrt::Windows::Storage::Streams::IBuffer py::convert_to_ibuffer(PyObject* obj)
57
+ {
58
+ return winrt::make<py::cpp::_winrt::PyWinRTBuffer>(obj);
59
+ }
@@ -0,0 +1 @@
1
+ 3.2.0
@@ -605,3 +605,46 @@ winrt::guid py::convert_to_guid(PyObject* obj)
605
605
  throw python_exception();
606
606
  }
607
607
  }
608
+
609
+ PyObject* py::await_async(PyObject* obj) noexcept
610
+ {
611
+ auto state = py::cpp::_winrt::get_module_state();
612
+ if (!state)
613
+ {
614
+ return nullptr;
615
+ }
616
+
617
+ // lazy import to avoid circular import issues
618
+ if (!state->wrap_async_func)
619
+ {
620
+ pyobj_handle winrt_system{PyImport_ImportModule("winrt.runtime._internals")};
621
+ if (!winrt_system)
622
+ {
623
+ return nullptr;
624
+ }
625
+
626
+ pyobj_handle wrap_async_func{
627
+ PyObject_GetAttrString(winrt_system.get(), "wrap_async")};
628
+ if (!wrap_async_func)
629
+ {
630
+ return nullptr;
631
+ }
632
+
633
+ state->wrap_async_func = wrap_async_func.detach();
634
+ }
635
+
636
+ pyobj_handle awaitable{PyObject_CallOneArg(state->wrap_async_func, obj)};
637
+ if (!awaitable)
638
+ {
639
+ return nullptr;
640
+ }
641
+
642
+ py::pyobj_handle await_str{PyUnicode_InternFromString("__await__")};
643
+ if (!await_str)
644
+ {
645
+ return nullptr;
646
+ }
647
+
648
+ // __await__() expects an iterable to be returned
649
+ return PyObject_CallMethodNoArgs(awaitable.get(), await_str.get());
650
+ }
@@ -11,6 +11,8 @@ class build_ext_ex(build_ext):
11
11
  ext.extra_compile_args = ["/std:c++20", "/permissive-"]
12
12
  elif self.compiler.compiler_type == "mingw32":
13
13
  ext.extra_compile_args = ["-std=c++20", "-D_WIN32_WINNT=_WIN32_WINNT_WIN10"]
14
+ # GCC 15 complains about some things that it didn't in the past
15
+ ext.extra_compile_args += ["-Wno-strict-aliasing", "-Wno-template-body"]
14
16
  ext.extra_link_args = ["-loleaut32"]
15
17
  else:
16
18
  raise ValueError(f"Unsupported compiler: {self.compiler.compiler_type}")
@@ -23,7 +25,7 @@ setup(
23
25
  ext_modules=[
24
26
  Extension(
25
27
  "winrt._winrt",
26
- sources=["_winrt.cpp", "_winrt_array.cpp", "_winrt_box.cpp", "runtime.cpp"],
28
+ sources=["_winrt.cpp", "_winrt_array.cpp", "_winrt_box.cpp", "_winrt_buffer.cpp", "runtime.cpp"],
27
29
  include_dirs=get_include_dirs(),
28
30
  libraries=["windowsapp"],
29
31
  )
@@ -30,8 +30,8 @@ STA: int
30
30
  def init_apartment(apartment_type: ApartmentType) -> None: ...
31
31
  def uninit_apartment() -> None: ...
32
32
  def initialize_with_window(obj: Object, hwnd: int) -> None: ...
33
- def _add_dll_directory(path: str) -> int: ...
34
- def _remove_dll_directory(cookie: int) -> None: ...
33
+ def add_dll_directory(path: str) -> int: ...
34
+ def remove_dll_directory(cookie: int) -> None: ...
35
35
  def box_boolean(value: bool) -> Object: ...
36
36
  def box_int8(value: int) -> Object: ...
37
37
  def box_uint8(value: int) -> Object: ...
@@ -0,0 +1,247 @@
1
+ import asyncio
2
+ import os
3
+ from collections.abc import (
4
+ Awaitable,
5
+ Callable,
6
+ Mapping,
7
+ MutableMapping,
8
+ MutableSequence,
9
+ Sequence,
10
+ )
11
+ from pathlib import Path
12
+ import sys
13
+ from typing import Any, TypeVar, Protocol, TYPE_CHECKING
14
+
15
+ from typing_extensions import Self
16
+
17
+ from winrt._winrt import add_dll_directory, remove_dll_directory
18
+ from winrt.system import Object
19
+
20
+ # Unfortunately, we can't import at runtime because of circular imports.
21
+ if TYPE_CHECKING:
22
+ from winrt.windows.foundation import HResult, AsyncStatus
23
+
24
+
25
+ class _DllCookie:
26
+ def __init__(self, cookie: int) -> None:
27
+ self.cookie = cookie
28
+
29
+ def close(self):
30
+ if self.cookie:
31
+ remove_dll_directory(self.cookie)
32
+ self.cookie = None
33
+
34
+ def __del__(self):
35
+ self.close()
36
+
37
+
38
+ def register_dll_search_path(module_path: str) -> _DllCookie:
39
+ """
40
+ Register a module's directory as a DLL search path.
41
+
42
+ Args:
43
+ module_path: The path to a module file (i.e. ``__file__``)
44
+
45
+ Returns:
46
+ An cookie object that will remove the search path when closed.
47
+ """
48
+ return _DllCookie(add_dll_directory(os.fspath(Path(module_path).parent.resolve())))
49
+
50
+
51
+ # NB: The types implemented in C cannot inherit from abc.ABC since Python 3.12
52
+ # so we have to implement the protocols like this instead.
53
+ # https://github.com/python/cpython/issues/103968#issuecomment-1589928055
54
+
55
+
56
+ def mixin_sequence(typ: type) -> None:
57
+ """
58
+ Adds missing Python mapping methods to types that implement IVectorView and
59
+ registers the type as a Sequence.
60
+ """
61
+ # mixin methods
62
+ if not hasattr(typ, "index"):
63
+ typ.index = Sequence.index # type: ignore
64
+
65
+ if not hasattr(typ, "count"):
66
+ typ.count = Sequence.count # type: ignore
67
+
68
+ if not hasattr(typ, "__contains__"):
69
+ typ.__contains__ = Sequence.__contains__ # type: ignore
70
+
71
+ if not hasattr(typ, "__iter__"):
72
+ typ.__iter__ = Sequence.__iter__ # type: ignore
73
+
74
+ if not hasattr(typ, "__reversed__"):
75
+ typ.__reversed__ = Sequence.__reversed__ # type: ignore
76
+
77
+ Sequence.register(typ)
78
+
79
+
80
+ def mixin_mutable_sequence(typ: type) -> None:
81
+ """
82
+ Adds missing Python mapping methods to types that implement IVector and
83
+ registers the type as a MutableSequence.
84
+ """
85
+ mixin_sequence(typ)
86
+
87
+ if not hasattr(typ, "insert") and hasattr(typ, "insert_at"):
88
+
89
+ def insert(self: Any, index: int, value: object) -> None:
90
+ """
91
+ Alias for ``insert_at`` for compatibility with Python Sequence protocol.
92
+ """
93
+ self.insert_at(index, value)
94
+
95
+ typ.insert = insert # type: ignore
96
+
97
+ # mixin methods
98
+ if not hasattr(typ, "append"):
99
+ typ.append = MutableSequence.append # type: ignore
100
+
101
+ if not hasattr(typ, "clear"):
102
+ typ.clear = MutableSequence.clear # type: ignore
103
+
104
+ if not hasattr(typ, "extend"):
105
+ typ.extend = MutableSequence.extend # type: ignore
106
+
107
+ if not hasattr(typ, "reverse"):
108
+ typ.reverse = MutableSequence.reverse # type: ignore
109
+
110
+ if not hasattr(typ, "pop"):
111
+ typ.pop = MutableSequence.pop # type: ignore
112
+
113
+ if not hasattr(typ, "remove"):
114
+ typ.remove = MutableSequence.remove # type: ignore
115
+
116
+ if not hasattr(typ, "__iadd__"):
117
+ typ.__iadd__ = MutableSequence.__iadd__ # type: ignore
118
+
119
+ MutableSequence.register(typ)
120
+
121
+
122
+ def mixin_mapping(typ: type) -> None:
123
+ """
124
+ Adds missing Python mapping methods to types that implement IMapView and
125
+ registers the type as a Mapping.
126
+ """
127
+ # mixin methods
128
+ if not hasattr(typ, "keys"):
129
+ typ.keys = Mapping.keys # type: ignore
130
+
131
+ if not hasattr(typ, "items"):
132
+ typ.items = Mapping.items # type: ignore
133
+
134
+ if not hasattr(typ, "values"):
135
+ typ.values = Mapping.values # type: ignore
136
+
137
+ if not hasattr(typ, "get"):
138
+ typ.get = Mapping.get # type: ignore
139
+
140
+ if not hasattr(typ, "__contains__"):
141
+ typ.__contains__ = Mapping.__contains__ # type: ignore
142
+
143
+ # HACK: Version check works around inheritance anomaly caused by hacky
144
+ # metaclass inheritance implementation in runtime.cpp. This works as long
145
+ # as we don't change the projection to implement rich comparison methods
146
+ # on mapping types.
147
+
148
+ if (
149
+ typ.__eq__ == object.__eq__
150
+ or typ.__eq__ == Object.__eq__
151
+ or sys.version_info < (3, 12)
152
+ ):
153
+ typ.__eq__ = Mapping.__eq__ # type: ignore
154
+
155
+ if (
156
+ typ.__ne__ == object.__ne__
157
+ or typ.__ne__ == Object.__ne__
158
+ or sys.version_info < (3, 12)
159
+ ):
160
+ typ.__ne__ = Mapping.__ne__ # type: ignore
161
+
162
+ Mapping.register(typ)
163
+
164
+
165
+ def mixin_mutable_mapping(typ: type) -> None:
166
+ """
167
+ Adds missing Python mapping methods to types that implement IMap and
168
+ registers the type as a MutableMapping.
169
+ """
170
+ mixin_mapping(typ)
171
+
172
+ # mixin methods
173
+ if not hasattr(typ, "clear"):
174
+ typ.clear = MutableMapping.clear # type: ignore
175
+
176
+ if not hasattr(typ, "pop"):
177
+ typ.pop = MutableMapping.pop # type: ignore
178
+ # private-name-mangled attribute :-(
179
+ typ._MutableMapping__marker = MutableMapping._MutableMapping__marker # type: ignore
180
+
181
+ if not hasattr(typ, "popitem"):
182
+ typ.popitem = MutableMapping.popitem # type: ignore
183
+
184
+ if not hasattr(typ, "setdefault"):
185
+ typ.setdefault = MutableMapping.setdefault # type: ignore
186
+
187
+ if not hasattr(typ, "update"):
188
+ typ.update = MutableMapping.update # type: ignore
189
+
190
+ MutableMapping.register(typ)
191
+
192
+
193
+ T = TypeVar("T")
194
+
195
+
196
+ # MyPy wants covariant T but Pylance wants invariant. Invariant seems correct.
197
+ class AsyncOp(Protocol[T]): # type: ignore [misc]
198
+ """
199
+ Protocol that matches both IAsyncAction and IAsyncOperation.
200
+ """
201
+
202
+ def cancel(self) -> None: ...
203
+ @property
204
+ def error_code(self) -> "HResult": ...
205
+ @property
206
+ def status(self) -> "AsyncStatus": ...
207
+ def get_results(self) -> T: ...
208
+ @property
209
+ def completed(self) -> Callable[[Self, "AsyncStatus"], None]: ...
210
+ @completed.setter
211
+ def completed(self, value: Callable[[Self, "AsyncStatus"], None]) -> None: ...
212
+
213
+
214
+ def wrap_async(op: AsyncOp[T]) -> Awaitable[T]:
215
+ """
216
+ Wraps a WinRT async operation in a Python Awaitable.
217
+
218
+ This is used by the runtime to implement ``__await__`` on async operations.
219
+
220
+ Args:
221
+ op: The WinRT async operation to wrap.
222
+
223
+ Returns:
224
+ An asyncio Awaitable that will be completed when the WinRT operation
225
+ completes.
226
+ """
227
+
228
+ async def wait() -> T:
229
+ loop = asyncio.get_running_loop()
230
+ event = asyncio.Event()
231
+
232
+ def on_complete(op: AsyncOp[T], status: "AsyncStatus") -> None:
233
+ loop.call_soon_threadsafe(event.set)
234
+
235
+ op.completed = on_complete
236
+
237
+ try:
238
+ await event.wait()
239
+ except asyncio.CancelledError:
240
+ op.cancel()
241
+ # REVISIT: what if it is cancelled again?
242
+ await event.wait()
243
+ raise
244
+
245
+ return op.get_results()
246
+
247
+ return wait()
File without changes
@@ -0,0 +1,113 @@
1
+ from typing import Annotated
2
+
3
+ from typing_extensions import Buffer, TypeAlias
4
+
5
+ from winrt._winrt import (
6
+ Array,
7
+ Object,
8
+ box_boolean,
9
+ box_char16,
10
+ box_date_time,
11
+ box_double,
12
+ box_guid,
13
+ box_int8,
14
+ box_int16,
15
+ box_int32,
16
+ box_int64,
17
+ box_single,
18
+ box_string,
19
+ box_time_span,
20
+ box_uint8,
21
+ box_uint16,
22
+ box_uint32,
23
+ box_uint64,
24
+ unbox_boolean,
25
+ unbox_char16,
26
+ unbox_date_time,
27
+ unbox_double,
28
+ unbox_guid,
29
+ unbox_int8,
30
+ unbox_int16,
31
+ unbox_int32,
32
+ unbox_int64,
33
+ unbox_single,
34
+ unbox_string,
35
+ unbox_time_span,
36
+ unbox_uint8,
37
+ unbox_uint16,
38
+ unbox_uint32,
39
+ unbox_uint64,
40
+ )
41
+ import winrt.runtime._internals
42
+
43
+
44
+ # type aliases with struct format string annotation
45
+ Int8 = Annotated[int, "b"]
46
+ UInt8 = Annotated[int, "B"]
47
+ Int16 = Annotated[int, "h"]
48
+ UInt16 = Annotated[int, "H"]
49
+ Int32 = Annotated[int, "i"]
50
+ UInt32 = Annotated[int, "I"]
51
+ Int64 = Annotated[int, "q"]
52
+ UInt64 = Annotated[int, "Q"]
53
+ Single = Annotated[float, "f"]
54
+ Double = Annotated[float, "d"]
55
+ Char16 = Annotated[str, "u"]
56
+
57
+ winrt.runtime._internals.mixin_mutable_sequence(Array)
58
+
59
+ # Type hints for Python buffer protocol - can use standard Python types in
60
+ # addition to the WinRT Array.
61
+ ReadableBuffer: TypeAlias = Buffer # WinRT PassArray
62
+ WriteableBuffer: TypeAlias = Buffer # WinRT FillArray
63
+
64
+
65
+ __all__ = [
66
+ "Int8",
67
+ "UInt8",
68
+ "Int16",
69
+ "UInt16",
70
+ "Int32",
71
+ "UInt32",
72
+ "Int64",
73
+ "UInt64",
74
+ "Single",
75
+ "Double",
76
+ "Char16",
77
+ "Object",
78
+ "Array",
79
+ "ReadableBuffer",
80
+ "WriteableBuffer",
81
+ "box_boolean",
82
+ "box_int8",
83
+ "box_uint8",
84
+ "box_int16",
85
+ "box_uint16",
86
+ "box_int32",
87
+ "box_uint32",
88
+ "box_int64",
89
+ "box_uint64",
90
+ "box_single",
91
+ "box_double",
92
+ "box_char16",
93
+ "box_string",
94
+ "box_guid",
95
+ "box_date_time",
96
+ "box_time_span",
97
+ "unbox_boolean",
98
+ "unbox_int8",
99
+ "unbox_uint8",
100
+ "unbox_int16",
101
+ "unbox_uint16",
102
+ "unbox_int32",
103
+ "unbox_uint32",
104
+ "unbox_int64",
105
+ "unbox_uint64",
106
+ "unbox_single",
107
+ "unbox_double",
108
+ "unbox_char16",
109
+ "unbox_string",
110
+ "unbox_guid",
111
+ "unbox_date_time",
112
+ "unbox_time_span",
113
+ ]
@@ -0,0 +1,48 @@
1
+ from ctypes import HRESULT as _HRESULT
2
+
3
+ """Common HRESULT error codes."""
4
+
5
+ # NB: have to use ctypes.HRESULT to convert unsigned values to signed int
6
+
7
+
8
+ # https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
9
+ _ERROR_FILE_NOT_FOUND = 2
10
+
11
+ # https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--1000-1299-
12
+ _ERROR_CANCELLED = 1223
13
+
14
+
15
+ # https://learn.microsoft.com/en-us/windows/win32/api/winerror/nf-winerror-hresult_facility
16
+ _FACILITY_WIN32 = 7
17
+
18
+
19
+ # https://learn.microsoft.com/en-us/windows/win32/api/winerror/nf-winerror-hresult_from_win32
20
+ def _HRESULT_FROM_WIN32(error_code: int) -> _HRESULT:
21
+ x = _HRESULT(error_code).value
22
+ return _HRESULT(
23
+ x if x <= 0 else ((x & 0x0000FFFF) | (_FACILITY_WIN32 << 16) | 0x80000000)
24
+ )
25
+
26
+
27
+ # common errors from CppWinRT
28
+ S_OK = 0
29
+ E_FAIL = _HRESULT(0x80004005).value
30
+ E_ACCESSDENIED = _HRESULT(0x80070005).value
31
+ E_NOTIMPL = _HRESULT(0x80004001).value
32
+ E_INVALIDARG = _HRESULT(0x80070057).value
33
+ E_BOUNDS = _HRESULT(0x8000000B).value
34
+ E_NOINTERFACE = _HRESULT(0x80004002).value
35
+ E_CHANGED_STATE = _HRESULT(0x8000000C).value
36
+ E_ILLEGAL_METHOD_CALL = _HRESULT(0x8000000E).value
37
+ E_ILLEGAL_STATE_CHANGE = _HRESULT(0x8000000D).value
38
+ E_ILLEGAL_DELEGATE_ASSIGNMENT = _HRESULT(0x80000018).value
39
+ E_OUTOFMEMORY = _HRESULT(0x8007000E).value
40
+ CLASS_E_CLASSNOTAVAILABLE = _HRESULT(0x80040111).value
41
+ CO_E_NOTINITIALIZED = _HRESULT(0x800401F0).value
42
+ REGDB_E_CLASSNOTREG = _HRESULT(0x80040154).value
43
+ RPC_E_WRONG_THREAD = _HRESULT(0x8001010E).value
44
+ WIN32_ERROR_FILE_NOT_FOUND = _HRESULT_FROM_WIN32(_ERROR_FILE_NOT_FOUND).value
45
+ WIN32_ERROR_CANCELLED = _HRESULT_FROM_WIN32(_ERROR_CANCELLED).value
46
+
47
+ # Errors defined by PyWinRT
48
+ PYWINRT_E_UNRAISABLE_PYTHON_EXCEPTION = _HRESULT(0xA0EE4005).value
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: winrt-runtime
3
- Version: 3.1.0
3
+ Version: 3.2.0
4
4
  Summary: Python projection of Windows Runtime (WinRT) APIs
5
5
  License-Expression: MIT
6
6
  Project-URL: Documentation, https://pywinrt.readthedocs.io
@@ -2,6 +2,7 @@ README.md
2
2
  _winrt.cpp
3
3
  _winrt_array.cpp
4
4
  _winrt_box.cpp
5
+ _winrt_buffer.cpp
5
6
  pyproject.toml
6
7
  pywinrt-version.txt
7
8
  requirements.txt
@@ -10,8 +11,12 @@ setup.py
10
11
  src/winrt/_winrt.pyi
11
12
  src/winrt/py.typed
12
13
  src/winrt/runtime/__init__.py
14
+ src/winrt/runtime/_internals.py
13
15
  src/winrt/runtime/interop.py
16
+ src/winrt/runtime/py.typed
14
17
  src/winrt/system/__init__.py
18
+ src/winrt/system/hresult.py
19
+ src/winrt/system/py.typed
15
20
  src/winrt_runtime.egg-info/PKG-INFO
16
21
  src/winrt_runtime.egg-info/SOURCES.txt
17
22
  src/winrt_runtime.egg-info/dependency_links.txt
@@ -1 +0,0 @@
1
- 3.1.0
@@ -1,285 +0,0 @@
1
- import os
2
- import sys
3
- from collections.abc import Mapping, MutableMapping, MutableSequence, Sequence
4
- from pathlib import Path
5
- from typing import Annotated
6
-
7
- from typing_extensions import Buffer, TypeAlias
8
-
9
- from .._winrt import (
10
- Array,
11
- Object,
12
- _add_dll_directory,
13
- _remove_dll_directory,
14
- box_boolean,
15
- box_char16,
16
- box_date_time,
17
- box_double,
18
- box_guid,
19
- box_int8,
20
- box_int16,
21
- box_int32,
22
- box_int64,
23
- box_single,
24
- box_string,
25
- box_time_span,
26
- box_uint8,
27
- box_uint16,
28
- box_uint32,
29
- box_uint64,
30
- unbox_boolean,
31
- unbox_char16,
32
- unbox_date_time,
33
- unbox_double,
34
- unbox_guid,
35
- unbox_int8,
36
- unbox_int16,
37
- unbox_int32,
38
- unbox_int64,
39
- unbox_single,
40
- unbox_string,
41
- unbox_time_span,
42
- unbox_uint8,
43
- unbox_uint16,
44
- unbox_uint32,
45
- unbox_uint64,
46
- )
47
-
48
-
49
- class _DllCookie:
50
- def __init__(self, cookie: int) -> None:
51
- self.cookie = cookie
52
-
53
- def close(self):
54
- if self.cookie:
55
- _remove_dll_directory(self.cookie)
56
- self.cookie = None
57
-
58
- def __del__(self):
59
- self.close()
60
-
61
-
62
- def _register_dll_search_path(module_path) -> _DllCookie:
63
- """
64
- Register a module's directory as a DLL search path.
65
-
66
- Args:
67
- module_path: The path to a module file (i.e. ``__file__``)
68
-
69
- Returns:
70
- An cookie object that will remove the search path when closed.
71
- """
72
- return _DllCookie(_add_dll_directory(os.fspath(Path(module_path).parent.resolve())))
73
-
74
-
75
- # NB: The types implemented in C cannot inherit from abc.ABC since Python 3.12
76
- # so we have to implement the protocols like this instead.
77
- # https://github.com/python/cpython/issues/103968#issuecomment-1589928055
78
-
79
-
80
- def _mixin_sequence(typ) -> None:
81
- """
82
- Adds missing Python mapping methods to types that implement IVectorView and
83
- registers the type as a Sequence.
84
- """
85
- # mixin methods
86
- if not hasattr(typ, "index"):
87
- typ.index = Sequence.index
88
-
89
- if not hasattr(typ, "count"):
90
- typ.count = Sequence.count
91
-
92
- if not hasattr(typ, "__contains__"):
93
- typ.__contains__ = Sequence.__contains__
94
-
95
- if not hasattr(typ, "__iter__"):
96
- typ.__iter__ = Sequence.__iter__
97
-
98
- if not hasattr(typ, "__reversed__"):
99
- typ.__reversed__ = Sequence.__reversed__
100
-
101
- Sequence.register(typ)
102
-
103
-
104
- def _mixin_mutable_sequence(typ) -> None:
105
- """
106
- Adds missing Python mapping methods to types that implement IVector and
107
- registers the type as a MutableSequence.
108
- """
109
- _mixin_sequence(typ)
110
-
111
- if not hasattr(typ, "insert") and hasattr(typ, "insert_at"):
112
-
113
- def insert(self, index: int, value: object) -> None:
114
- """
115
- Alias for ``insert_at`` for compatibility with Python Sequence protocol.
116
- """
117
- self.insert_at(index, value)
118
-
119
- typ.insert = insert
120
-
121
- # mixin methods
122
- if not hasattr(typ, "append"):
123
- typ.append = MutableSequence.append
124
-
125
- if not hasattr(typ, "clear"):
126
- typ.clear = MutableSequence.clear
127
-
128
- if not hasattr(typ, "extend"):
129
- typ.extend = MutableSequence.extend
130
-
131
- if not hasattr(typ, "reverse"):
132
- typ.reverse = MutableSequence.reverse
133
-
134
- if not hasattr(typ, "pop"):
135
- typ.pop = MutableSequence.pop
136
-
137
- if not hasattr(typ, "remove"):
138
- typ.remove = MutableSequence.remove
139
-
140
- if not hasattr(typ, "__iadd__"):
141
- typ.__iadd__ = MutableSequence.__iadd__
142
-
143
- MutableSequence.register(typ)
144
-
145
-
146
- def _mixin_mapping(typ) -> None:
147
- """
148
- Adds missing Python mapping methods to types that implement IMapView and
149
- registers the type as a Mapping.
150
- """
151
- # mixin methods
152
- if not hasattr(typ, "keys"):
153
- typ.keys = Mapping.keys
154
-
155
- if not hasattr(typ, "items"):
156
- typ.items = Mapping.items
157
-
158
- if not hasattr(typ, "values"):
159
- typ.values = Mapping.values
160
-
161
- if not hasattr(typ, "get"):
162
- typ.get = Mapping.get
163
-
164
- if not hasattr(typ, "__contains__"):
165
- typ.__contains__ = Mapping.__contains__
166
-
167
- # HACK: Version check works around inheritance anomaly caused by hacky
168
- # metaclass inheritance implementation in runtime.cpp. This works as long
169
- # as we don't change the projection to implement rich comparison methods
170
- # on mapping types.
171
-
172
- if (
173
- typ.__eq__ == object.__eq__
174
- or typ.__eq__ == Object.__eq__
175
- or sys.version_info < (3, 12)
176
- ):
177
- typ.__eq__ = Mapping.__eq__
178
-
179
- if (
180
- typ.__ne__ == object.__ne__
181
- or typ.__ne__ == Object.__ne__
182
- or sys.version_info < (3, 12)
183
- ):
184
- typ.__ne__ = Mapping.__ne__
185
-
186
- Mapping.register(typ)
187
-
188
-
189
- def _mixin_mutable_mapping(typ) -> None:
190
- """
191
- Adds missing Python mapping methods to types that implement IMap and
192
- registers the type as a MutableMapping.
193
- """
194
- _mixin_mapping(typ)
195
-
196
- # mixin methods
197
- if not hasattr(typ, "clear"):
198
- typ.clear = MutableMapping.clear
199
-
200
- if not hasattr(typ, "pop"):
201
- typ.pop = MutableMapping.pop
202
- # private-name-mangled attribute :-(
203
- typ._MutableMapping__marker = MutableMapping._MutableMapping__marker # type: ignore
204
-
205
- if not hasattr(typ, "popitem"):
206
- typ.popitem = MutableMapping.popitem
207
-
208
- if not hasattr(typ, "setdefault"):
209
- typ.setdefault = MutableMapping.setdefault
210
-
211
- if not hasattr(typ, "update"):
212
- typ.update = MutableMapping.update
213
-
214
- MutableMapping.register(typ)
215
-
216
-
217
- # type aliases with struct format string annotation
218
- Int8 = Annotated[int, "b"]
219
- UInt8 = Annotated[int, "B"]
220
- Int16 = Annotated[int, "h"]
221
- UInt16 = Annotated[int, "H"]
222
- Int32 = Annotated[int, "i"]
223
- UInt32 = Annotated[int, "I"]
224
- Int64 = Annotated[int, "q"]
225
- UInt64 = Annotated[int, "Q"]
226
- Single = Annotated[float, "f"]
227
- Double = Annotated[float, "d"]
228
- Char16 = Annotated[str, "u"]
229
-
230
- _mixin_mutable_sequence(Array)
231
-
232
- # Type hints for Python buffer protocol - can use standard Python types in
233
- # addition to the WinRT Array.
234
- ReadableBuffer: TypeAlias = Buffer # WinRT PassArray
235
- WriteableBuffer: TypeAlias = Buffer # WinRT FillArray
236
-
237
- __all__ = [
238
- "Int8",
239
- "UInt8",
240
- "Int16",
241
- "UInt16",
242
- "Int32",
243
- "UInt32",
244
- "Int64",
245
- "UInt64",
246
- "Single",
247
- "Double",
248
- "Char16",
249
- "Object",
250
- "Array",
251
- "ReadableBuffer",
252
- "WriteableBuffer",
253
- "box_boolean",
254
- "box_int8",
255
- "box_uint8",
256
- "box_int16",
257
- "box_uint16",
258
- "box_int32",
259
- "box_uint32",
260
- "box_int64",
261
- "box_uint64",
262
- "box_single",
263
- "box_double",
264
- "box_char16",
265
- "box_string",
266
- "box_guid",
267
- "box_date_time",
268
- "box_time_span",
269
- "unbox_boolean",
270
- "unbox_int8",
271
- "unbox_uint8",
272
- "unbox_int16",
273
- "unbox_uint16",
274
- "unbox_int32",
275
- "unbox_uint32",
276
- "unbox_int64",
277
- "unbox_uint64",
278
- "unbox_single",
279
- "unbox_double",
280
- "unbox_char16",
281
- "unbox_string",
282
- "unbox_guid",
283
- "unbox_date_time",
284
- "unbox_time_span",
285
- ]
File without changes
File without changes