python-libei 0.8.2__py3-none-any.whl → 0.8.3__py3-none-any.whl

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.
libei/__init__.py CHANGED
@@ -31,6 +31,6 @@ the full breakdown, including which features need which libei version.
31
31
  Beta: the API is not frozen.
32
32
  """
33
33
 
34
- __version__ = "0.8.2"
34
+ __version__ = "0.8.3"
35
35
 
36
36
  __all__ = ["__version__"]
libei/ei.py CHANGED
@@ -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; a file
1152
- object is duplicated first, so the caller's own object stays valid.
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. A raw int is assumed to already be one the caller is
1156
- # handing off (matching what eis.Eis.add_client()/oeffis.eis_fd
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.2
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.2`), published on [PyPI](https://pypi.org/project/python-libei/)
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 |
@@ -1,6 +1,6 @@
1
- libei/__init__.py,sha256=0WzSpuWo8E0SVd1Q-4ukFcaDjOjxEhmklsAm3rC4YFQ,1858
1
+ libei/__init__.py,sha256=312stxiJuabMPVgrF7OplROJZhuajmIAPnRyQoXL5hA,1858
2
2
  libei/_cobject.py,sha256=XjbUNJpZ87jAyPWh6dmRslk6cMy831oMRFhWmfjLDFo,13344
3
- libei/ei.py,sha256=3oaZ4dxo-ytBHtES3_1_LUca2ZbR8r3SwA50Rj0hGxo,49541
3
+ libei/ei.py,sha256=UA7dYyyelVoeNnjVocf_22YOxPTSFoiUyQqlkwk8g-M,52010
4
4
  libei/eis.py,sha256=kcFi6vfw9F9uBt6Bz-blGD-0M6mLEMTYDCgC_SKK7vU,46843
5
5
  libei/oeffis.py,sha256=gJHR90s9VhQrgkjWUMDx-lxZ8qKxkttnqbx_xo-7oxs,10035
6
6
  libei/portal.py,sha256=lULdezDuLj65iKY70f2GNywedwN1pgoiA3sdOfuFyyc,93747
@@ -10,8 +10,8 @@ libei/_capi/libei.py,sha256=AQgVZ2ZsHH8rywwcmq1EJ-IauuNHbBMhwauMelX83yE,11754
10
10
  libei/_capi/libeis.py,sha256=C_Uh7DwNncFC8A4wuMhviAj5C_TUmKHtLJYq0Qhhz1E,13142
11
11
  libei/_capi/liboeffis.py,sha256=V8jdmJm3qOQUzzNiCAXt4Jr2JY11Y4-w6NIfIxbxGI4,1218
12
12
  libei/_capi/loader.py,sha256=xW67uk35ckgeFaheDGrHC05ZM5w_cxBGvX5lG_GUSu8,6625
13
- python_libei-0.8.2.dist-info/licenses/LICENSE,sha256=l6xbMU6Y-JZDzmBciBj-J5t6h6jNg_Bcyp4bHxDepqU,1074
14
- python_libei-0.8.2.dist-info/METADATA,sha256=t0MI2_zYDuX-87YMTAIPkN_YEUhDW3ZPhnbT30V9RYQ,23364
15
- python_libei-0.8.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
16
- python_libei-0.8.2.dist-info/top_level.txt,sha256=_DQXzGjDsUBENI_cNkiOxPB4xi8coCbQS1lq18FMudQ,6
17
- python_libei-0.8.2.dist-info/RECORD,,
13
+ python_libei-0.8.3.dist-info/licenses/LICENSE,sha256=l6xbMU6Y-JZDzmBciBj-J5t6h6jNg_Bcyp4bHxDepqU,1074
14
+ python_libei-0.8.3.dist-info/METADATA,sha256=JghxAh-bPNxubjncnnWf10uhvJ3a2B66IblD3Aij9rg,25256
15
+ python_libei-0.8.3.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
16
+ python_libei-0.8.3.dist-info/top_level.txt,sha256=_DQXzGjDsUBENI_cNkiOxPB4xi8coCbQS1lq18FMudQ,6
17
+ python_libei-0.8.3.dist-info/RECORD,,