python-libei 0.8.2__tar.gz → 0.8.3__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.
- {python_libei-0.8.2/src/python_libei.egg-info → python_libei-0.8.3}/PKG-INFO +35 -2
- {python_libei-0.8.2 → python_libei-0.8.3}/README.md +34 -1
- {python_libei-0.8.2 → python_libei-0.8.3}/pyproject.toml +1 -1
- {python_libei-0.8.2 → python_libei-0.8.3}/src/libei/__init__.py +1 -1
- {python_libei-0.8.2 → python_libei-0.8.3}/src/libei/ei.py +50 -4
- {python_libei-0.8.2 → python_libei-0.8.3/src/python_libei.egg-info}/PKG-INFO +35 -2
- python_libei-0.8.3/tests/test_integration_lifetime.py +94 -0
- python_libei-0.8.2/tests/test_integration_lifetime.py +0 -49
- {python_libei-0.8.2 → python_libei-0.8.3}/LICENSE +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/setup.cfg +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/libei/_capi/__init__.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/libei/_capi/libei.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/libei/_capi/libeis.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/libei/_capi/liboeffis.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/libei/_capi/loader.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/libei/_cobject.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/libei/eis.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/libei/oeffis.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/libei/portal.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/libei/py.typed +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/python_libei.egg-info/SOURCES.txt +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/python_libei.egg-info/dependency_links.txt +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/python_libei.egg-info/requires.txt +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/src/python_libei.egg-info/top_level.txt +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_abi.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_cobject.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_documentation_shape.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_documented_examples.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_ei_objects.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_eis_objects.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_event_accessors.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_inputcapture.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_integration_extras.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_integration_frame.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_integration_socketpair.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_loader.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_oeffis.py +0 -0
- {python_libei-0.8.2 → python_libei-0.8.3}/tests/test_portal.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-libei
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.3
|
|
4
4
|
Summary: Inject, receive and capture input on Wayland from Python: ctypes bindings for libei, libeis and liboeffis, plus the RemoteDesktop and InputCapture portals
|
|
5
5
|
Author: Dennis K. Paulsen
|
|
6
6
|
License-Expression: MIT
|
|
@@ -175,7 +175,7 @@ and why, is in
|
|
|
175
175
|
|
|
176
176
|
## Status
|
|
177
177
|
|
|
178
|
-
Beta (`0.8.
|
|
178
|
+
Beta (`0.8.3`), published on [PyPI](https://pypi.org/project/python-libei/)
|
|
179
179
|
since `0.1.0`, and **the API is not frozen** — expect renames before 1.0.
|
|
180
180
|
|
|
181
181
|
The injection path is exercised end to end against the real libraries by the
|
|
@@ -190,6 +190,39 @@ asserted.
|
|
|
190
190
|
Exactly what was run, when, and against which versions:
|
|
191
191
|
[docs/developers/verification.md](docs/developers/verification.md).
|
|
192
192
|
|
|
193
|
+
### What the API raises
|
|
194
|
+
|
|
195
|
+
Three independent exception families, by the layer that raises them, so a
|
|
196
|
+
caller can catch at the granularity they need — plus one that sits before
|
|
197
|
+
all of them:
|
|
198
|
+
|
|
199
|
+
- **`LibraryNotFoundError`** (a `RuntimeError`, exported by `libei.ei`,
|
|
200
|
+
`libei.eis` and `libei.oeffis` alike) — the native library could not be
|
|
201
|
+
loaded. Importing never raises it; the first call that needs the library
|
|
202
|
+
does, and every later call after that. `is_available()` asks the same
|
|
203
|
+
question without raising.
|
|
204
|
+
- **`libei.ei.Error`** (and `libei.eis.Error`) — the native library reported
|
|
205
|
+
a failure through its own return codes. One base class per module;
|
|
206
|
+
subclasses are added as distinct failure modes earn them rather than up
|
|
207
|
+
front.
|
|
208
|
+
- **`libei.oeffis.DisconnectedError`**, with `SessionClosedError` under it —
|
|
209
|
+
the EIS connection is gone. `dispatch()` raises the subclass when the
|
|
210
|
+
portal closed the session and the base class when the connection dropped
|
|
211
|
+
or the fd could not be obtained; `eis_fd` raises the base class whenever
|
|
212
|
+
no connection is up yet, so it is `dispatch()` that tells the two apart.
|
|
213
|
+
- **`libei.portal.PortalError`**, with `PortalVersionError`,
|
|
214
|
+
`PortalTimeoutError`, `PortalDeniedError`, `PortalProtocolError` and
|
|
215
|
+
`PortalSessionClosedError` under it — each a *different* thing the portal
|
|
216
|
+
round trip can do, kept separate on purpose: a timeout (no answer), a
|
|
217
|
+
denial (answered no), a protocol surprise (answered malformed) and a
|
|
218
|
+
version mismatch are not interchangeable, and collapsing them would make a
|
|
219
|
+
caller guess. These are the ones worth catching individually.
|
|
220
|
+
|
|
221
|
+
Argument mistakes that are the caller's and not the desktop's —
|
|
222
|
+
no capabilities, the wrong value kind — raise the stock `ValueError` /
|
|
223
|
+
`TypeError`, never a library exception. The hierarchy is stable in shape; as
|
|
224
|
+
with the rest of the API, names may still change before 1.0.
|
|
225
|
+
|
|
193
226
|
## Alternatives
|
|
194
227
|
|
|
195
228
|
| Instead of this | Why you might |
|
|
@@ -135,7 +135,7 @@ and why, is in
|
|
|
135
135
|
|
|
136
136
|
## Status
|
|
137
137
|
|
|
138
|
-
Beta (`0.8.
|
|
138
|
+
Beta (`0.8.3`), published on [PyPI](https://pypi.org/project/python-libei/)
|
|
139
139
|
since `0.1.0`, and **the API is not frozen** — expect renames before 1.0.
|
|
140
140
|
|
|
141
141
|
The injection path is exercised end to end against the real libraries by the
|
|
@@ -150,6 +150,39 @@ asserted.
|
|
|
150
150
|
Exactly what was run, when, and against which versions:
|
|
151
151
|
[docs/developers/verification.md](docs/developers/verification.md).
|
|
152
152
|
|
|
153
|
+
### What the API raises
|
|
154
|
+
|
|
155
|
+
Three independent exception families, by the layer that raises them, so a
|
|
156
|
+
caller can catch at the granularity they need — plus one that sits before
|
|
157
|
+
all of them:
|
|
158
|
+
|
|
159
|
+
- **`LibraryNotFoundError`** (a `RuntimeError`, exported by `libei.ei`,
|
|
160
|
+
`libei.eis` and `libei.oeffis` alike) — the native library could not be
|
|
161
|
+
loaded. Importing never raises it; the first call that needs the library
|
|
162
|
+
does, and every later call after that. `is_available()` asks the same
|
|
163
|
+
question without raising.
|
|
164
|
+
- **`libei.ei.Error`** (and `libei.eis.Error`) — the native library reported
|
|
165
|
+
a failure through its own return codes. One base class per module;
|
|
166
|
+
subclasses are added as distinct failure modes earn them rather than up
|
|
167
|
+
front.
|
|
168
|
+
- **`libei.oeffis.DisconnectedError`**, with `SessionClosedError` under it —
|
|
169
|
+
the EIS connection is gone. `dispatch()` raises the subclass when the
|
|
170
|
+
portal closed the session and the base class when the connection dropped
|
|
171
|
+
or the fd could not be obtained; `eis_fd` raises the base class whenever
|
|
172
|
+
no connection is up yet, so it is `dispatch()` that tells the two apart.
|
|
173
|
+
- **`libei.portal.PortalError`**, with `PortalVersionError`,
|
|
174
|
+
`PortalTimeoutError`, `PortalDeniedError`, `PortalProtocolError` and
|
|
175
|
+
`PortalSessionClosedError` under it — each a *different* thing the portal
|
|
176
|
+
round trip can do, kept separate on purpose: a timeout (no answer), a
|
|
177
|
+
denial (answered no), a protocol surprise (answered malformed) and a
|
|
178
|
+
version mismatch are not interchangeable, and collapsing them would make a
|
|
179
|
+
caller guess. These are the ones worth catching individually.
|
|
180
|
+
|
|
181
|
+
Argument mistakes that are the caller's and not the desktop's —
|
|
182
|
+
no capabilities, the wrong value kind — raise the stock `ValueError` /
|
|
183
|
+
`TypeError`, never a library exception. The hierarchy is stable in shape; as
|
|
184
|
+
with the rest of the API, names may still change before 1.0.
|
|
185
|
+
|
|
153
186
|
## Alternatives
|
|
154
187
|
|
|
155
188
|
| Instead of this | Why you might |
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "python-libei"
|
|
7
|
-
version = "0.8.
|
|
7
|
+
version = "0.8.3"
|
|
8
8
|
description = "Inject, receive and capture input on Wayland from Python: ctypes bindings for libei, libeis and liboeffis, plus the RemoteDesktop and InputCapture portals"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -1081,6 +1081,10 @@ class Context(CObject):
|
|
|
1081
1081
|
"""
|
|
1082
1082
|
super().__init__(pointer, _adopt=_adopt)
|
|
1083
1083
|
self._name: str | None = None
|
|
1084
|
+
# Whether set_fd()/set_socket() has run -- attempted, not
|
|
1085
|
+
# succeeded; see _refuse_a_second_backend() for why those are the
|
|
1086
|
+
# same thing here.
|
|
1087
|
+
self._backend_configured = False
|
|
1084
1088
|
_capi.libei.log_set_handler(self, _log_handler)
|
|
1085
1089
|
_capi.libei.log_set_priority(self, _LogPriority.DEBUG)
|
|
1086
1090
|
|
|
@@ -1145,20 +1149,53 @@ class Context(CObject):
|
|
|
1145
1149
|
"""The context's current time, in microseconds."""
|
|
1146
1150
|
return _capi.libei.now(self)
|
|
1147
1151
|
|
|
1152
|
+
def _refuse_a_second_backend(self) -> None:
|
|
1153
|
+
"""Raise for a transport setup on a context that already had one.
|
|
1154
|
+
|
|
1155
|
+
Letting the call through instead is not an error return: both
|
|
1156
|
+
``ei_setup_backend_fd()`` and ``ei_setup_backend_socket()`` open
|
|
1157
|
+
on ``assert(!ei->backend)``, which aborts the whole process
|
|
1158
|
+
(measured: SIGABRT on 1.6.0). And each installs its backend
|
|
1159
|
+
object *before* anything that can fail, so a context whose setup
|
|
1160
|
+
failed is just as spent as one whose setup succeeded -- which is
|
|
1161
|
+
why the flag this reads records the attempt, not the outcome.
|
|
1162
|
+
"""
|
|
1163
|
+
if self._backend_configured:
|
|
1164
|
+
raise RuntimeError(
|
|
1165
|
+
f"this {type(self).__name__} already has a transport, and a "
|
|
1166
|
+
"failed setup attempt also counts -- libei's setup functions "
|
|
1167
|
+
"abort the process on a second call rather than returning an "
|
|
1168
|
+
"error; create a new context instead"
|
|
1169
|
+
)
|
|
1170
|
+
|
|
1148
1171
|
def set_fd(self: _ContextT, fd: IO[bytes] | int) -> _ContextT:
|
|
1149
1172
|
"""Use an already-connected socket as the transport.
|
|
1150
1173
|
|
|
1151
|
-
libei takes ownership of a raw int fd and closes it itself
|
|
1152
|
-
|
|
1174
|
+
libei takes ownership of a raw int fd and closes it itself --
|
|
1175
|
+
whether setup succeeds or fails; a file object is duplicated
|
|
1176
|
+
first, so the caller's own object stays valid.
|
|
1177
|
+
|
|
1178
|
+
Once per context, counting :meth:`set_socket` and counting failed
|
|
1179
|
+
attempts: a second call raises ``RuntimeError`` here rather than
|
|
1180
|
+
reaching C, where it is an assertion failure that aborts the
|
|
1181
|
+
process. The refused fd is untouched and stays the caller's.
|
|
1153
1182
|
"""
|
|
1183
|
+
self._refuse_a_second_backend()
|
|
1154
1184
|
# ei_setup_backend_fd() takes ownership of the fd and will close it
|
|
1155
|
-
# itself
|
|
1156
|
-
#
|
|
1185
|
+
# itself -- on its failure path too: the fd goes straight into a
|
|
1186
|
+
# source whose destroy closes it, and failing drops that source
|
|
1187
|
+
# (libei-fd.c -> ei_set_socket() -> source_unref(), read on 1.6.0).
|
|
1188
|
+
# So no close here on error, which would double-close a possibly
|
|
1189
|
+
# reused number. A raw int is assumed to already be one the caller
|
|
1190
|
+
# is handing off (matching what eis.Eis.add_client()/oeffis.eis_fd
|
|
1157
1191
|
# return); a file object still thinks it owns its own fd and would
|
|
1158
1192
|
# close it again later -- possibly a *different*, since-reused fd
|
|
1159
1193
|
# number by then -- so duplicate it rather than handing over the
|
|
1160
1194
|
# original.
|
|
1161
1195
|
raw_fd = fd if isinstance(fd, int) else os.dup(fd.fileno())
|
|
1196
|
+
# Spent on the attempt: the C call installs its backend object
|
|
1197
|
+
# before anything that can fail.
|
|
1198
|
+
self._backend_configured = True
|
|
1162
1199
|
err = _capi.libei.setup_backend_fd(self, raw_fd)
|
|
1163
1200
|
if err < 0:
|
|
1164
1201
|
raise Error(os.strerror(-err), -err)
|
|
@@ -1169,8 +1206,17 @@ class Context(CObject):
|
|
|
1169
1206
|
|
|
1170
1207
|
``None`` uses ``$LIBEI_SOCKET``; a relative path is resolved
|
|
1171
1208
|
against ``$XDG_RUNTIME_DIR``.
|
|
1209
|
+
|
|
1210
|
+
Once per context, counting :meth:`set_fd` and counting failed
|
|
1211
|
+
attempts -- see :meth:`set_fd`.
|
|
1172
1212
|
"""
|
|
1173
1213
|
encoded = os.fspath(path).encode("utf-8") if path else None
|
|
1214
|
+
self._refuse_a_second_backend()
|
|
1215
|
+
# Spent on the attempt: the backend object is installed before any
|
|
1216
|
+
# of the failure returns (no $LIBEI_SOCKET, no $XDG_RUNTIME_DIR, a
|
|
1217
|
+
# failed connect), so even a context that never connected cannot
|
|
1218
|
+
# try again.
|
|
1219
|
+
self._backend_configured = True
|
|
1174
1220
|
err = _capi.libei.setup_backend_socket(self, encoded)
|
|
1175
1221
|
if err < 0:
|
|
1176
1222
|
raise Error(os.strerror(-err), -err)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-libei
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.3
|
|
4
4
|
Summary: Inject, receive and capture input on Wayland from Python: ctypes bindings for libei, libeis and liboeffis, plus the RemoteDesktop and InputCapture portals
|
|
5
5
|
Author: Dennis K. Paulsen
|
|
6
6
|
License-Expression: MIT
|
|
@@ -175,7 +175,7 @@ and why, is in
|
|
|
175
175
|
|
|
176
176
|
## Status
|
|
177
177
|
|
|
178
|
-
Beta (`0.8.
|
|
178
|
+
Beta (`0.8.3`), published on [PyPI](https://pypi.org/project/python-libei/)
|
|
179
179
|
since `0.1.0`, and **the API is not frozen** — expect renames before 1.0.
|
|
180
180
|
|
|
181
181
|
The injection path is exercised end to end against the real libraries by the
|
|
@@ -190,6 +190,39 @@ asserted.
|
|
|
190
190
|
Exactly what was run, when, and against which versions:
|
|
191
191
|
[docs/developers/verification.md](docs/developers/verification.md).
|
|
192
192
|
|
|
193
|
+
### What the API raises
|
|
194
|
+
|
|
195
|
+
Three independent exception families, by the layer that raises them, so a
|
|
196
|
+
caller can catch at the granularity they need — plus one that sits before
|
|
197
|
+
all of them:
|
|
198
|
+
|
|
199
|
+
- **`LibraryNotFoundError`** (a `RuntimeError`, exported by `libei.ei`,
|
|
200
|
+
`libei.eis` and `libei.oeffis` alike) — the native library could not be
|
|
201
|
+
loaded. Importing never raises it; the first call that needs the library
|
|
202
|
+
does, and every later call after that. `is_available()` asks the same
|
|
203
|
+
question without raising.
|
|
204
|
+
- **`libei.ei.Error`** (and `libei.eis.Error`) — the native library reported
|
|
205
|
+
a failure through its own return codes. One base class per module;
|
|
206
|
+
subclasses are added as distinct failure modes earn them rather than up
|
|
207
|
+
front.
|
|
208
|
+
- **`libei.oeffis.DisconnectedError`**, with `SessionClosedError` under it —
|
|
209
|
+
the EIS connection is gone. `dispatch()` raises the subclass when the
|
|
210
|
+
portal closed the session and the base class when the connection dropped
|
|
211
|
+
or the fd could not be obtained; `eis_fd` raises the base class whenever
|
|
212
|
+
no connection is up yet, so it is `dispatch()` that tells the two apart.
|
|
213
|
+
- **`libei.portal.PortalError`**, with `PortalVersionError`,
|
|
214
|
+
`PortalTimeoutError`, `PortalDeniedError`, `PortalProtocolError` and
|
|
215
|
+
`PortalSessionClosedError` under it — each a *different* thing the portal
|
|
216
|
+
round trip can do, kept separate on purpose: a timeout (no answer), a
|
|
217
|
+
denial (answered no), a protocol surprise (answered malformed) and a
|
|
218
|
+
version mismatch are not interchangeable, and collapsing them would make a
|
|
219
|
+
caller guess. These are the ones worth catching individually.
|
|
220
|
+
|
|
221
|
+
Argument mistakes that are the caller's and not the desktop's —
|
|
222
|
+
no capabilities, the wrong value kind — raise the stock `ValueError` /
|
|
223
|
+
`TypeError`, never a library exception. The hierarchy is stable in shape; as
|
|
224
|
+
with the rest of the API, names may still change before 1.0.
|
|
225
|
+
|
|
193
226
|
## Alternatives
|
|
194
227
|
|
|
195
228
|
| Instead of this | Why you might |
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""An event used after its loop iteration, through the real library.
|
|
2
|
+
|
|
3
|
+
Each event is released as the loop moves on, and the docs promise a
|
|
4
|
+
``RuntimeError`` afterwards. test_ei_objects.py checks ``_as_parameter_`` in
|
|
5
|
+
isolation, which is not the path a caller takes: a real call converts its
|
|
6
|
+
arguments inside ctypes, and ctypes re-raises whatever that conversion raised as
|
|
7
|
+
``ctypes.ArgumentError`` carrying only the text. So the promise is checked here,
|
|
8
|
+
with a real event and a real C call.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import select
|
|
15
|
+
import socket
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
import pytest
|
|
19
|
+
|
|
20
|
+
from conftest import requires_libei
|
|
21
|
+
from libei import ei, eis
|
|
22
|
+
from test_integration_extras import Pair
|
|
23
|
+
|
|
24
|
+
pytestmark = [pytest.mark.integration, requires_libei]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_a_released_event_raises_runtime_error_from_a_real_call() -> None:
|
|
28
|
+
pair = Pair((eis.DeviceCapability.POINTER,))
|
|
29
|
+
kept: list[eis.Event] = []
|
|
30
|
+
|
|
31
|
+
def on_server_event(event: eis.Event) -> None:
|
|
32
|
+
if event.event_type is eis.EventType.POINTER_MOTION:
|
|
33
|
+
kept.append(event)
|
|
34
|
+
|
|
35
|
+
def on_device(device: ei.Device) -> None:
|
|
36
|
+
device.start_emulating().pointer_motion(7, 3).frame().stop_emulating()
|
|
37
|
+
|
|
38
|
+
pair.run(lambda: bool(kept), on_server_event=on_server_event, on_device=on_device)
|
|
39
|
+
# The loop has moved on, so the event has been released.
|
|
40
|
+
if select.select([pair.server.fd], [], [], 0.2)[0]:
|
|
41
|
+
pair.server.dispatch()
|
|
42
|
+
list(pair.server.events)
|
|
43
|
+
|
|
44
|
+
def event_type(event: eis.Event) -> object:
|
|
45
|
+
return event.event_type
|
|
46
|
+
|
|
47
|
+
def pointer_event(event: eis.Event) -> object:
|
|
48
|
+
return event.pointer_event
|
|
49
|
+
|
|
50
|
+
for read in (event_type, pointer_event):
|
|
51
|
+
with pytest.raises(RuntimeError, match="already been released"):
|
|
52
|
+
read(kept[0])
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_a_second_transport_setup_is_refused_in_python_not_an_abort() -> None:
|
|
56
|
+
# ei_setup_backend_fd() and ei_setup_backend_socket() both open on
|
|
57
|
+
# assert(!ei->backend): a second setup reaching C does not fail, it
|
|
58
|
+
# SIGABRTs the interpreter. That makes this test its own bite check --
|
|
59
|
+
# without the Python-side refusal it cannot merely fail, it kills the
|
|
60
|
+
# whole run.
|
|
61
|
+
server = eis.Eis.create_for_fd()
|
|
62
|
+
client_fd = server.add_client()
|
|
63
|
+
sender = ei.Sender.create_for_fd(client_fd, name="setup-twice-probe")
|
|
64
|
+
first, second = socket.socketpair()
|
|
65
|
+
with first, second:
|
|
66
|
+
spare = os.dup(first.fileno())
|
|
67
|
+
try:
|
|
68
|
+
with pytest.raises(RuntimeError, match="already has a transport"):
|
|
69
|
+
sender.set_fd(spare)
|
|
70
|
+
finally:
|
|
71
|
+
# Refused before the pointer ever reached C, so the fd was not
|
|
72
|
+
# handed off and is still the caller's to close.
|
|
73
|
+
os.close(spare)
|
|
74
|
+
with pytest.raises(RuntimeError, match="already has a transport"):
|
|
75
|
+
sender.set_socket(None)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_a_failed_socket_setup_spends_the_context_too() -> None:
|
|
79
|
+
# The C setup installs its backend object before any of its failure
|
|
80
|
+
# returns, so a context whose setup failed hits the same abort on a
|
|
81
|
+
# retry: the refusal has to key on "was setup attempted", not "did it
|
|
82
|
+
# succeed". Built the way create_for_socket() builds it, because the
|
|
83
|
+
# public constructor raises away its context on exactly this failure.
|
|
84
|
+
context = ei.Sender(ei.Sender._new())
|
|
85
|
+
with pytest.raises(ei.Error):
|
|
86
|
+
context.set_socket(Path("/nonexistent-libei-test") / "no-such-socket")
|
|
87
|
+
first, second = socket.socketpair()
|
|
88
|
+
with first, second:
|
|
89
|
+
spare = os.dup(first.fileno())
|
|
90
|
+
try:
|
|
91
|
+
with pytest.raises(RuntimeError, match="already has a transport"):
|
|
92
|
+
context.set_fd(spare)
|
|
93
|
+
finally:
|
|
94
|
+
os.close(spare)
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"""An event used after its loop iteration, through the real library.
|
|
2
|
-
|
|
3
|
-
Each event is released as the loop moves on, and the docs promise a
|
|
4
|
-
``RuntimeError`` afterwards. test_ei_objects.py checks ``_as_parameter_`` in
|
|
5
|
-
isolation, which is not the path a caller takes: a real call converts its
|
|
6
|
-
arguments inside ctypes, and ctypes re-raises whatever that conversion raised as
|
|
7
|
-
``ctypes.ArgumentError`` carrying only the text. So the promise is checked here,
|
|
8
|
-
with a real event and a real C call.
|
|
9
|
-
"""
|
|
10
|
-
|
|
11
|
-
from __future__ import annotations
|
|
12
|
-
|
|
13
|
-
import select
|
|
14
|
-
|
|
15
|
-
import pytest
|
|
16
|
-
|
|
17
|
-
from conftest import requires_libei
|
|
18
|
-
from libei import ei, eis
|
|
19
|
-
from test_integration_extras import Pair
|
|
20
|
-
|
|
21
|
-
pytestmark = [pytest.mark.integration, requires_libei]
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def test_a_released_event_raises_runtime_error_from_a_real_call() -> None:
|
|
25
|
-
pair = Pair((eis.DeviceCapability.POINTER,))
|
|
26
|
-
kept: list[eis.Event] = []
|
|
27
|
-
|
|
28
|
-
def on_server_event(event: eis.Event) -> None:
|
|
29
|
-
if event.event_type is eis.EventType.POINTER_MOTION:
|
|
30
|
-
kept.append(event)
|
|
31
|
-
|
|
32
|
-
def on_device(device: ei.Device) -> None:
|
|
33
|
-
device.start_emulating().pointer_motion(7, 3).frame().stop_emulating()
|
|
34
|
-
|
|
35
|
-
pair.run(lambda: bool(kept), on_server_event=on_server_event, on_device=on_device)
|
|
36
|
-
# The loop has moved on, so the event has been released.
|
|
37
|
-
if select.select([pair.server.fd], [], [], 0.2)[0]:
|
|
38
|
-
pair.server.dispatch()
|
|
39
|
-
list(pair.server.events)
|
|
40
|
-
|
|
41
|
-
def event_type(event: eis.Event) -> object:
|
|
42
|
-
return event.event_type
|
|
43
|
-
|
|
44
|
-
def pointer_event(event: eis.Event) -> object:
|
|
45
|
-
return event.pointer_event
|
|
46
|
-
|
|
47
|
-
for read in (event_type, pointer_event):
|
|
48
|
-
with pytest.raises(RuntimeError, match="already been released"):
|
|
49
|
-
read(kept[0])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|