python-libei 0.8.0__py3-none-any.whl → 0.8.2__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.0"
34
+ __version__ = "0.8.2"
35
35
 
36
36
  __all__ = ["__version__"]
libei/_capi/libei.py CHANGED
@@ -219,7 +219,13 @@ region_get_mapping_id = lib.function( # libei 1.1+
219
219
  "ei_region_get_mapping_id", (c_void_p,), c_char_p
220
220
  )
221
221
  # x and y are in/out parameters, overwritten only when the point is inside.
222
- region_convert_point = lib.function( # libei 1.1+
222
+ # No version marker: this one is in libei 1.0.0's own public header and
223
+ # implemented there, so every libei at or above the declared floor exports
224
+ # it. It carried `# libei 1.1+` alongside its genuine 1.1 neighbours
225
+ # `ei_region_get_mapping_id` and `ei_device_region_at`, and the weekly
226
+ # floor job caught it -- building 1.0.0 from source found the symbol
227
+ # present where the marker promised it would be absent.
228
+ region_convert_point = lib.function(
223
229
  "ei_region_convert_point",
224
230
  (c_void_p, POINTER(c_double), POINTER(c_double)),
225
231
  c_bool,
libei/ei.py CHANGED
@@ -372,8 +372,7 @@ class Region(CObject):
372
372
 
373
373
  Returns the point with the region's offset subtracted, or ``None``
374
374
  if it falls outside the region -- which is also how you test
375
- membership without a second :meth:`contains` call. Requires
376
- libei 1.1.
375
+ membership without a second :meth:`contains` call.
377
376
  """
378
377
  # x/y are in-out parameters: libei overwrites them only when the
379
378
  # point is inside, so the return value has to gate reading them.
@@ -1127,7 +1126,10 @@ class Context(CObject):
1127
1126
  pointer = _capi.libei.get_event(self)
1128
1127
  if not pointer:
1129
1128
  break
1130
- event = Event.wrap(pointer)
1129
+ # adopt(), not wrap(): ei_get_event() transfers ownership of
1130
+ # the returned reference to the caller, and the unref in
1131
+ # release() below is the one that balances it.
1132
+ event = Event.adopt(pointer)
1131
1133
  assert event is not None
1132
1134
  # try/finally, not a bare call after yield: breaking out of a
1133
1135
  # `for event in ctx.events:` loop (or an exception propagating
libei/eis.py CHANGED
@@ -944,7 +944,18 @@ class Event(CObject):
944
944
 
945
945
  @property
946
946
  def emulating_sequence(self) -> int:
947
- """Sequence number of the start_emulating transaction."""
947
+ """Sequence number of the start_emulating transaction.
948
+
949
+ Reads 0 on libei older than 1.6, whatever the client sent. libeis
950
+ queued the event without ever copying the sequence into it, so the
951
+ getter returned a zeroed struct field; upstream added the missing
952
+ assignment in libei 1.6.0. Every version from this package's 1.0.0
953
+ floor up exports the symbol, so there is nothing to raise and no
954
+ way to tell an old library apart from a client that genuinely sent
955
+ 0 -- treat a 0 here as "unknown" unless you know both ends are on
956
+ 1.6. :attr:`libei.ei.Event.emulating_sequence`, the receiver side
957
+ of the same transaction, is unaffected: libei has always stored it.
958
+ """
948
959
  self._require("emulating_sequence", EventType.DEVICE_START_EMULATING)
949
960
  return _capi.libeis.event_emulating_get_sequence(self)
950
961
 
@@ -1150,7 +1161,10 @@ class Eis(CObject):
1150
1161
  pointer = _capi.libeis.get_event(self)
1151
1162
  if not pointer:
1152
1163
  break
1153
- event = Event.wrap(pointer)
1164
+ # adopt(), not wrap(): eis_get_event() transfers ownership of
1165
+ # the returned reference to the caller, and the unref in
1166
+ # release() below is the one that balances it.
1167
+ event = Event.adopt(pointer)
1154
1168
  assert event is not None
1155
1169
  # See ei.Context.events: try/finally so release() still runs
1156
1170
  # if the caller breaks out of the loop (GeneratorExit at the
@@ -1168,9 +1182,11 @@ class Eis(CObject):
1168
1182
  def set_flag(self, flag: Flag) -> None:
1169
1183
  """Change this context's protocol behavior. Requires libei 1.6.
1170
1184
 
1171
- Must be called before the backend is set up, so in practice
1172
- before :meth:`create_for_fd` / :meth:`create_for_socket` -- which
1173
- also means this is only reachable on a context built by hand.
1185
+ Must be called before the backend is set up, so the supported
1186
+ way to use it is the ``flags`` parameter of
1187
+ :meth:`create_for_fd` / :meth:`create_for_socket`, which apply
1188
+ each flag at exactly that point; calling it directly only works
1189
+ on a context built by hand, before its backend is set up.
1174
1190
  Takes one flag, never a bitmask; call it again for another.
1175
1191
  """
1176
1192
  result = _capi.libeis.set_flag(self, flag)
libei/portal.py CHANGED
@@ -207,6 +207,23 @@ class PortalProtocolError(PortalError):
207
207
  default message names the expected shape), a phrase for a value fault
208
208
  (naming the field). ``payload`` is whatever best shows the fault -- the
209
209
  whole signal tuple for a shape fault, the options dict for a value one.
210
+
211
+ :func:`_request` raises it the same way for a ``Request``'s
212
+ ``Response`` reply that does not match its own ``(u response, a{sv}
213
+ results)`` shape, and :meth:`InputCaptureSession.zones` for a result
214
+ value that is not the type the spec gives it -- always with a
215
+ ``detail`` phrase, since the default shape message above is specific
216
+ to the session signals. ``step`` is then the method name, matching the
217
+ sibling errors raised from the same call.
218
+
219
+ :func:`_call_for_fd` -- both portals' ``ConnectToEIS``, whose reply is
220
+ an *index* into a separate out fd list -- raises it for
221
+ the three ways that pair can disagree: no fd list attached at all
222
+ (the out list is nullable), an index outside the list, and the dup
223
+ ``g_unix_fd_list_get()`` does failing on fd exhaustion. ``payload`` is
224
+ the index in each case. Those used to reach the caller as an
225
+ ``AttributeError``, a silent ``-1`` fd, and a raw ``GLib.Error``
226
+ respectively -- none of them catchable as a ``PortalError``.
210
227
  """
211
228
 
212
229
  def __init__(self, step: str, payload: object, detail: str | None = None) -> None:
@@ -457,6 +474,18 @@ def _request(
457
474
  for 60 seconds means the answer arrives inside 60 seconds, not inside
458
475
  however many 60-second waits the sequence happens to be built from.
459
476
 
477
+ A ``Response`` whose payload does not match the spec's ``(u response,
478
+ a{sv} results)`` shape raises :class:`PortalProtocolError` rather than
479
+ being unpacked on faith -- the same hardening `_wait_for_signal`
480
+ applies to the signals it waits on, and for the same two reasons: a
481
+ wrong-arity payload used to raise inside the GLib callback, where PyGI
482
+ swallows it, degrading the step to a full-timeout
483
+ :class:`PortalTimeoutError`; a non-dict ``results`` instead slipped
484
+ through to the caller, whose ``.get()`` crashed with a raw
485
+ ``AttributeError`` past ``except PortalError``. The guarantee callers
486
+ rely on is therefore structural: what this returns is always an
487
+ ``int`` code and a ``dict`` of results.
488
+
460
489
  ``trailing_args``, appended after ``options`` in the call's parameter
461
490
  tuple, exists for ``InputCapture.SetPointerBarriers`` -- the one
462
491
  Request-returning method in either portal whose ``options`` is not its
@@ -474,12 +503,28 @@ def _request(
474
503
 
475
504
  loop = GLib.MainLoop()
476
505
  result: dict[str, Any] = {}
506
+ malformed: dict[str, Any] = {}
477
507
  subscriptions: list[Any] = []
478
508
  # Set inside the timeout callback rather than inferred from an empty
479
509
  # `result` afterwards: a Response carrying no results is legitimate
480
510
  # (SelectDevices answers with an empty dict), so "did the loop end
481
511
  # because it timed out" has to be recorded, not deduced.
482
512
  timed_out = False
513
+ # Distinct from `timed_out`: whether `on_timeout` ran at all, either
514
+ # path -- the flag the cleanup below keys "already removed?" on. See
515
+ # the matching pair in `_wait_for_signal`.
516
+ timeout_fired = False
517
+
518
+ def _settled() -> bool:
519
+ """Whether some terminal outcome has already been recorded.
520
+
521
+ Same role as in `_wait_for_signal`: GLib dispatches every source
522
+ ready in one main-context iteration regardless of an earlier
523
+ ``loop.quit()``, so a Response and the deadline can both fire in
524
+ the same poll -- the first recorded outcome wins, and a delivered
525
+ reply is never dropped for a timeout (or vice versa).
526
+ """
527
+ return bool(result) or bool(malformed) or timed_out
483
528
 
484
529
  def on_response(
485
530
  _conn: Any,
@@ -491,14 +536,42 @@ def _request(
491
536
  *_a: Any,
492
537
  ) -> None:
493
538
  """Record the first reply and quit the loop; later replies are ignored."""
494
- if result: # both subscriptions may fire; the first reply wins
539
+ if _settled(): # both subscriptions may fire; the first reply wins
495
540
  return
496
- result["code"], result["results"] = params.unpack()
541
+ args = params.unpack()
542
+ # Checked here, raised only after the loop: this runs inside a
543
+ # GLib callback, where PyGI prints an exception to stderr and
544
+ # swallows it -- a bare raise on a malformed Response would leave
545
+ # the loop running until the full timeout, misreported as
546
+ # PortalTimeoutError; a non-dict `results` let through instead
547
+ # crashed the caller's `.get()` with a raw AttributeError past
548
+ # `except PortalError`. Same hardening `_wait_for_signal` applies
549
+ # to the signals it waits on.
550
+ if (
551
+ not isinstance(args, tuple)
552
+ or len(args) != 2
553
+ or isinstance(args[0], bool)
554
+ or not isinstance(args[0], int)
555
+ or not isinstance(args[1], dict)
556
+ ):
557
+ malformed["args"] = args
558
+ loop.quit()
559
+ return
560
+ result["code"], result["results"] = args
497
561
  loop.quit()
498
562
 
499
563
  def on_timeout() -> bool:
500
564
  """Stop the loop and record that it timed out rather than finished."""
501
- nonlocal timed_out
565
+ nonlocal timed_out, timeout_fired
566
+ # Set first, before the early return: GLib removes the source the
567
+ # moment this returns False (which both paths do), so the finally
568
+ # block keys "already removed" on this, not on `timed_out` -- see
569
+ # the same dance in `_wait_for_signal`.
570
+ timeout_fired = True
571
+ if _settled():
572
+ # A Response delivered in the same poll as the deadline has
573
+ # already recorded its outcome; do not overwrite it.
574
+ return False
502
575
  timed_out = True
503
576
  loop.quit()
504
577
  return False # one-shot; GLib removes the source when this is False
@@ -542,12 +615,14 @@ def _request(
542
615
  handle = _returned_handle(reply)
543
616
  if handle is not None and handle != expected_path:
544
617
  subscribe(handle)
545
- # `if not result` because a synchronous answer (a fast
618
+ # `if not _settled()` because a synchronous answer (a fast
546
619
  # non-interactive Response, or a test double) can arrive during the
547
620
  # call above, before run() is reached -- and quit() on a loop that
548
621
  # is not running yet does not stop the later run(), so running it
549
- # then would block with the reply already delivered.
550
- if not result:
622
+ # then would block with the reply already delivered. A malformed
623
+ # synchronous reply counts: it too has already quit a loop that
624
+ # was not running yet.
625
+ if not _settled():
551
626
  timeout_source = GLib.timeout_add(_msec_until(deadline), on_timeout)
552
627
  try:
553
628
  loop.run()
@@ -559,12 +634,27 @@ def _request(
559
634
  # fixed for _wait_for_signal below. Only remove it when the
560
635
  # *Response* woke the loop instead; leaving a live source in
561
636
  # that case holds a reference to this closure and fires it
562
- # into a dead loop on some later request.
563
- if not timed_out:
637
+ # into a dead loop on some later request. Keyed on
638
+ # `timeout_fired` (did on_timeout run), not `timed_out` (did
639
+ # the wait time out): a Response landing in the same poll as
640
+ # the deadline runs on_timeout down its `_settled` early
641
+ # return, which removes the source yet leaves `timed_out`
642
+ # False.
643
+ if not timeout_fired:
564
644
  GLib.source_remove(timeout_source)
565
645
  finally:
566
646
  for subscription in subscriptions:
567
647
  connection.signal_unsubscribe(subscription)
648
+ # Mirrors `_signal_outcome`: only one of these is ever set (every
649
+ # callback checks `_settled()` first), so the order here only decides
650
+ # between genuinely simultaneous dispatches.
651
+ if malformed:
652
+ raise PortalProtocolError(
653
+ method,
654
+ malformed["args"],
655
+ "the Request's Response signal is specified as "
656
+ "(uint response, results dict)",
657
+ )
568
658
  if timed_out:
569
659
  raise PortalTimeoutError(method, timeout)
570
660
  return result["code"], result["results"]
@@ -590,6 +680,27 @@ def _call_for_fd(
590
680
  wait on and nothing here beyond the call itself -- but it is a call to
591
681
  the same portal that just made the caller wait on a consent dialog, so
592
682
  it is bounded by the same ``timeout`` rather than by GIO's default.
683
+
684
+ The reply carries only an *index* into a separate out fd list, and both
685
+ halves have to be checked before the index is used, because
686
+ `g_unix_fd_list_get()` will not check them for us:
687
+
688
+ * The out fd list is **nullable** -- ``call_with_unix_fd_list_sync()``
689
+ is specified to hand back ``NULL`` for it, so a well-formed ``(h)``
690
+ reply with no fds attached arrives here as ``None``. Dereferencing
691
+ that raised ``AttributeError`` at the caller, outside every
692
+ ``except PortalError``.
693
+ * A bad index is a **programmer error**, not a runtime failure:
694
+ ``g_unix_fd_list_get()`` asserts ``index >= 0 && index < nfd``,
695
+ logs ``GLib-GIO-CRITICAL`` and **returns -1 without raising and
696
+ without setting a GError** (measured on GLib 2.90.1). So an
697
+ out-of-range index cannot be caught by an ``except GLib.Error``; the
698
+ -1 just flows out as the EIS fd. Gio-2.0.gir says as much and names
699
+ the two fixes: ``lookup()``, which is GLib 2.90+ only, or a bounds
700
+ check against ``get_length()`` -- the portable one, used below.
701
+
702
+ The one real ``GLib.Error`` from ``get()`` is the dup itself failing on
703
+ an fd the list does hold, i.e. EMFILE/ENFILE.
593
704
  """
594
705
  try:
595
706
  reply, fd_list = connection.call_with_unix_fd_list_sync(
@@ -609,7 +720,82 @@ def _call_for_fd(
609
720
  raise PortalTimeoutError(method, timeout) from exc
610
721
  raise PortalError(f"{method} failed on the D-Bus: {exc}") from exc
611
722
  (handle_index,) = reply.unpack()
612
- return fd_list.get(handle_index)
723
+ # Each of the three checks below turns something that used to escape a
724
+ # caller's `except PortalError` -- an AttributeError, a silent -1, a raw
725
+ # GLib.Error -- into the same typed protocol error _request() raises for a
726
+ # malformed Response. See this function's docstring for the GLib contract
727
+ # they are reading.
728
+ if fd_list is None:
729
+ raise PortalProtocolError(
730
+ method,
731
+ handle_index,
732
+ "it returned an fd index but attached no fd list to the reply",
733
+ )
734
+ length = fd_list.get_length()
735
+ if handle_index < 0 or handle_index >= length:
736
+ raise PortalProtocolError(
737
+ method,
738
+ handle_index,
739
+ "the fd index it returned is out of range for the reply's fd list "
740
+ f"(index {handle_index}, {length} fd(s) attached)",
741
+ )
742
+ try:
743
+ fd = fd_list.get(handle_index)
744
+ except _glib_error(GLib) as exc:
745
+ # The index is in range, so this is not a lookup failure: the only
746
+ # thing left for g_unix_fd_list_get() to fail at is the dup() it does
747
+ # to hand back an owned fd.
748
+ raise PortalProtocolError(
749
+ method,
750
+ handle_index,
751
+ "duplicating the fd it returned failed -- this process is out of "
752
+ f"file descriptors ({exc})",
753
+ ) from exc
754
+ if fd < 0:
755
+ # Unreachable via the bounds check above, which is the only documented
756
+ # way to get the -1 sentinel; kept so a future GLib that returns it for
757
+ # some other reason surfaces as a typed error rather than as a negative
758
+ # fd handed to ei.Sender.create_for_fd(), which does not check for one.
759
+ raise PortalProtocolError(
760
+ method,
761
+ handle_index,
762
+ f"its fd list returned no usable fd for index {handle_index} (got {fd})",
763
+ )
764
+ return fd
765
+
766
+
767
+ def _portal_version(reply: Any, interface: str) -> int:
768
+ """The ``version`` property out of a `Properties.Get` reply, as an int.
769
+
770
+ `_call_sync` is given no ``reply_type``, here as everywhere else in this
771
+ module, so GDBus validates nothing about the shape of what comes back --
772
+ which is why every other reply-consuming site checks the unpacked value
773
+ before trusting it. These two did not: a reply that unpacked to anything
774
+ but a one-element tuple raised `ValueError`, and a ``version`` that was
775
+ not a number raised `TypeError`, both bare built-ins escaping the
776
+ `except PortalError` that `docs/troubleshooting.md` promises covers the
777
+ negotiation.
778
+ """
779
+ unpacked = reply.unpack()
780
+ try:
781
+ (version,) = unpacked
782
+ except (ValueError, TypeError) as exc:
783
+ raise PortalProtocolError(
784
+ "Get",
785
+ unpacked,
786
+ f"{interface}'s version property is specified as a single "
787
+ f"value, and this reply is not that shape",
788
+ ) from exc
789
+ # bool before int, because bool *is* an int: a True would otherwise read
790
+ # as version 1 and be refused as "too old", blaming the portal's version
791
+ # for a reply that was nonsense.
792
+ if isinstance(version, bool) or not isinstance(version, int):
793
+ raise PortalProtocolError(
794
+ "Get",
795
+ unpacked,
796
+ f"{interface} reported a non-numeric version {version!r}",
797
+ )
798
+ return version
613
799
 
614
800
 
615
801
  def _remote_desktop_version(
@@ -628,8 +814,7 @@ def _remote_desktop_version(
628
814
  None,
629
815
  int(timeout * 1000),
630
816
  )
631
- (version,) = reply.unpack()
632
- return int(version)
817
+ return _portal_version(reply, _REMOTE_DESKTOP)
633
818
 
634
819
 
635
820
  class RemoteDesktopSession:
@@ -1011,8 +1196,7 @@ def _input_capture_version(
1011
1196
  None,
1012
1197
  int(timeout * 1000),
1013
1198
  )
1014
- (version,) = reply.unpack()
1015
- return int(version)
1199
+ return _portal_version(reply, _INPUT_CAPTURE)
1016
1200
 
1017
1201
 
1018
1202
  def _create_input_capture_session_v1(
@@ -1100,6 +1284,23 @@ def _classify_signal_payload(
1100
1284
  return "take"
1101
1285
 
1102
1286
 
1287
+ def _spec_int(value: Any) -> int:
1288
+ """``int(value)`` for a spec ``u``/``i``, refusing a silent truncation.
1289
+
1290
+ A portal integer field arrives as a Python ``int``. A malformed portal
1291
+ that put a ``d`` (double) there would still reach ``int()``, and
1292
+ ``int(0.9) == 0`` / ``int(1.9) == 1`` truncates it *silently* -- a zone
1293
+ coordinate or a refused barrier id quietly becomes a different,
1294
+ valid-looking value rather than an error. Reject any ``float``
1295
+ (``inf``/``nan`` included) with the ``ValueError`` the surrounding
1296
+ guards already turn into a :class:`PortalProtocolError`, so an off-spec
1297
+ fractional value is refused on the same footing as a non-numeric one.
1298
+ """
1299
+ if isinstance(value, float):
1300
+ raise ValueError("a fractional value where the spec gives an integer")
1301
+ return int(value)
1302
+
1303
+
1103
1304
  def _deactivation_id(options: dict[str, Any], signal: str) -> int:
1104
1305
  """The ``activation_id`` from Deactivated's options, as the spec's ``u``.
1105
1306
 
@@ -1107,13 +1308,12 @@ def _deactivation_id(options: dict[str, Any], signal: str) -> int:
1107
1308
  dict -- but not the types of the values in it. ``activation_id`` is a
1108
1309
  ``u``, and a non-conforming portal that put something else there would
1109
1310
  crash the caller with ``ValueError``/``TypeError``/``OverflowError``
1110
- (the last from ``int(float('inf'))``) past the shape check. Converting
1111
- it here turns that into the same typed :class:`PortalProtocolError` the
1112
- shape check raises, so a caller that guards against malformed signals
1113
- catches one error, not two.
1311
+ past the shape check. Converting it here turns that into the same typed
1312
+ :class:`PortalProtocolError` the shape check raises, so a caller that
1313
+ guards against malformed signals catches one error, not two.
1114
1314
  """
1115
1315
  try:
1116
- return int(options.get("activation_id", 0))
1316
+ return _spec_int(options.get("activation_id", 0))
1117
1317
  except (ValueError, TypeError, OverflowError) as exc:
1118
1318
  raise PortalProtocolError(
1119
1319
  signal, options, "activation_id is not an integer"
@@ -1134,7 +1334,7 @@ def _activation_from_options(options: dict[str, Any], signal: str) -> Activation
1134
1334
  fourth hand-rolled check nobody remembers to write.
1135
1335
  """
1136
1336
  try:
1137
- activation_id = int(options.get("activation_id", 0))
1337
+ activation_id = _spec_int(options.get("activation_id", 0))
1138
1338
  cursor = options.get("cursor_position")
1139
1339
  if cursor is None:
1140
1340
  cursor_position = None
@@ -1142,7 +1342,7 @@ def _activation_from_options(options: dict[str, Any], signal: str) -> Activation
1142
1342
  cx, cy = cursor # (dd): exactly two, or this unpacking raises
1143
1343
  cursor_position = (float(cx), float(cy))
1144
1344
  barrier = options.get("barrier_id")
1145
- barrier_id = None if barrier is None else int(barrier)
1345
+ barrier_id = None if barrier is None else _spec_int(barrier)
1146
1346
  except (ValueError, TypeError, OverflowError) as exc:
1147
1347
  raise PortalProtocolError(
1148
1348
  signal, options, "an option value is not the type the spec gives it"
@@ -1291,35 +1491,44 @@ def _wait_for_signal(
1291
1491
  loop.quit()
1292
1492
  return False
1293
1493
 
1294
- subscription = connection.signal_subscribe(
1295
- busname,
1296
- interface,
1297
- signal,
1298
- _OBJECT_PATH,
1299
- None,
1300
- Gio.DBusSignalFlags.NONE,
1301
- on_signal,
1302
- None,
1303
- )
1304
- closed_subscription = connection.signal_subscribe(
1305
- busname,
1306
- _SESSION_INTERFACE,
1307
- "Closed",
1308
- session_handle,
1309
- None,
1310
- Gio.DBusSignalFlags.NONE,
1311
- on_closed,
1312
- None,
1313
- )
1314
- logger.debug(
1315
- "waiting up to %s for %s.%s on %s for session %s",
1316
- "forever" if timeout is None else f"{timeout:g}s",
1317
- interface,
1318
- signal,
1319
- _OBJECT_PATH,
1320
- session_handle,
1321
- )
1494
+ # Collected as they are made, and unsubscribed from the list, for
1495
+ # `_request`'s reason: taking them into two locals before the try meant
1496
+ # a failure in the second subscribe left the first one registered for
1497
+ # the life of the connection, with nothing holding a handle to it.
1498
+ subscriptions: list[Any] = []
1322
1499
  try:
1500
+ subscriptions.append(
1501
+ connection.signal_subscribe(
1502
+ busname,
1503
+ interface,
1504
+ signal,
1505
+ _OBJECT_PATH,
1506
+ None,
1507
+ Gio.DBusSignalFlags.NONE,
1508
+ on_signal,
1509
+ None,
1510
+ )
1511
+ )
1512
+ subscriptions.append(
1513
+ connection.signal_subscribe(
1514
+ busname,
1515
+ _SESSION_INTERFACE,
1516
+ "Closed",
1517
+ session_handle,
1518
+ None,
1519
+ Gio.DBusSignalFlags.NONE,
1520
+ on_closed,
1521
+ None,
1522
+ )
1523
+ )
1524
+ logger.debug(
1525
+ "waiting up to %s for %s.%s on %s for session %s",
1526
+ "forever" if timeout is None else f"{timeout:g}s",
1527
+ interface,
1528
+ signal,
1529
+ _OBJECT_PATH,
1530
+ session_handle,
1531
+ )
1323
1532
  if not result and not session_closed and not malformed:
1324
1533
  timeout_source = None
1325
1534
  if timeout is not None:
@@ -1344,8 +1553,8 @@ def _wait_for_signal(
1344
1553
  if timeout_source is not None and not timeout_fired:
1345
1554
  GLib.source_remove(timeout_source)
1346
1555
  finally:
1347
- connection.signal_unsubscribe(subscription)
1348
- connection.signal_unsubscribe(closed_subscription)
1556
+ for subscription in subscriptions:
1557
+ connection.signal_unsubscribe(subscription)
1349
1558
  return _signal_outcome(
1350
1559
  signal, timeout, result, malformed, timed_out, session_closed
1351
1560
  )
@@ -1608,9 +1817,26 @@ class InputCaptureSession:
1608
1817
  )
1609
1818
  if code != 0:
1610
1819
  raise PortalDeniedError("GetZones")
1611
- zone_set = results.get("zone_set", 0)
1612
- zones = [tuple(z) for z in results.get("zones", [])]
1613
- return int(zone_set), zones
1820
+ # `results` is a dict by `_request`'s own guarantee; the *values*
1821
+ # are still the portal's to malform. The spec types them --
1822
+ # `zone_set` is a `u`, `zones` an `a(uuii)` -- so convert them
1823
+ # under one guard, the same way `_activation_from_options` covers
1824
+ # the Activated signal's values: a non-conforming value becomes
1825
+ # the typed PortalProtocolError rather than a raw
1826
+ # TypeError/ValueError past `except PortalError` in the caller.
1827
+ try:
1828
+ zone_set = _spec_int(results.get("zone_set", 0))
1829
+ zones = [
1830
+ (_spec_int(w), _spec_int(h), _spec_int(x), _spec_int(y))
1831
+ for w, h, x, y in results.get("zones", [])
1832
+ ]
1833
+ except (ValueError, TypeError, OverflowError) as exc:
1834
+ raise PortalProtocolError(
1835
+ "GetZones",
1836
+ results,
1837
+ "a result value is not the type the spec gives it",
1838
+ ) from exc
1839
+ return zone_set, zones
1614
1840
 
1615
1841
  def set_pointer_barriers(
1616
1842
  self,
@@ -1659,7 +1885,19 @@ class InputCaptureSession:
1659
1885
  )
1660
1886
  if code != 0:
1661
1887
  raise PortalDeniedError("SetPointerBarriers")
1662
- failed = list(results.get("failed_barriers", []))
1888
+ # `results` is a dict by `_request`'s own guarantee; the *value* at
1889
+ # `failed_barriers` (an `au` per the spec) is not. A non-iterable
1890
+ # there would crash the caller with a raw TypeError past
1891
+ # `except PortalError` -- the same value-level hole `zones()` guards
1892
+ # -- so a malformed one becomes the typed PortalProtocolError.
1893
+ try:
1894
+ failed = [_spec_int(b) for b in results.get("failed_barriers", [])]
1895
+ except (ValueError, TypeError, OverflowError) as exc:
1896
+ raise PortalProtocolError(
1897
+ "SetPointerBarriers",
1898
+ results,
1899
+ "a result value is not the type the spec gives it",
1900
+ ) from exc
1663
1901
  # A partially-refused set is the quiet failure here: the call
1664
1902
  # succeeds, some barriers stand, and an edge the caller believes is
1665
1903
  # armed simply never triggers. Callers see only the returned list,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-libei
3
- Version: 0.8.0
3
+ Version: 0.8.2
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.0`), published on [PyPI](https://pypi.org/project/python-libei/)
178
+ Beta (`0.8.2`), 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
@@ -228,17 +228,27 @@ Exactly what was run, when, and against which versions:
228
228
 
229
229
  | Needs | For |
230
230
  | --- | --- |
231
- | 1.1 | `Region.mapping_id`, `Region.convert_point()`, `Device.region_at()` |
231
+ | 1.1 | `Region.mapping_id`, `Device.region_at()` |
232
232
  | 1.4 | ping/pong round trips (`Context.new_ping()`), `Context.disconnect()`, touch cancellation (`Touch.cancel()`) |
233
233
  | 1.5 | `eis.Client.pid` |
234
234
  | 1.6 | `Device.text_utf8()` / `text_keysym()` and TEXT events, `Seat.request_device()`, `Eis.set_flag()` |
235
235
 
236
236
  Nothing is resolved until it is called, so a build without one of these
237
237
  costs you only that call — it raises `LibraryNotFoundError` naming the
238
- missing symbol, while the rest of the package keeps working. The one
239
- exception is `Event.touch_up_event`, which degrades instead of raising:
240
- on libei older than 1.4 it reports `is_cancel=False`, since a library
241
- with no notion of cancellation genuinely never sends one.
238
+ missing symbol, while the rest of the package keeps working. Two
239
+ accessors degrade instead of raising, because every supported version
240
+ exports the symbol and only the answer changed — so there is nothing to
241
+ resolve and nothing to report:
242
+
243
+ - `Event.touch_up_event` reports `is_cancel=False` on libei older than
244
+ 1.4, since a library with no notion of cancellation genuinely never
245
+ sends one.
246
+ - `eis.Event.emulating_sequence` reads 0 on libei older than 1.6
247
+ whatever the client sent: libeis queued the start_emulating event
248
+ without ever copying the sequence into it, until 1.6.0 added the
249
+ missing assignment. A 0 on an older build is indistinguishable from a
250
+ client that really sent 0. The client-side
251
+ `ei.Event.emulating_sequence` is unaffected.
242
252
 
243
253
  These versions were established by building libei 1.2.1 and diffing its
244
254
  exported symbols against every binding here, not by reading `@since`
@@ -0,0 +1,17 @@
1
+ libei/__init__.py,sha256=0WzSpuWo8E0SVd1Q-4ukFcaDjOjxEhmklsAm3rC4YFQ,1858
2
+ libei/_cobject.py,sha256=XjbUNJpZ87jAyPWh6dmRslk6cMy831oMRFhWmfjLDFo,13344
3
+ libei/ei.py,sha256=3oaZ4dxo-ytBHtES3_1_LUca2ZbR8r3SwA50Rj0hGxo,49541
4
+ libei/eis.py,sha256=kcFi6vfw9F9uBt6Bz-blGD-0M6mLEMTYDCgC_SKK7vU,46843
5
+ libei/oeffis.py,sha256=gJHR90s9VhQrgkjWUMDx-lxZ8qKxkttnqbx_xo-7oxs,10035
6
+ libei/portal.py,sha256=lULdezDuLj65iKY70f2GNywedwN1pgoiA3sdOfuFyyc,93747
7
+ libei/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ libei/_capi/__init__.py,sha256=raISSWSV9hAcE92DcLCz-vUb1IPcsmxRZaS-iAoQJBE,211
9
+ libei/_capi/libei.py,sha256=AQgVZ2ZsHH8rywwcmq1EJ-IauuNHbBMhwauMelX83yE,11754
10
+ libei/_capi/libeis.py,sha256=C_Uh7DwNncFC8A4wuMhviAj5C_TUmKHtLJYq0Qhhz1E,13142
11
+ libei/_capi/liboeffis.py,sha256=V8jdmJm3qOQUzzNiCAXt4Jr2JY11Y4-w6NIfIxbxGI4,1218
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,,
@@ -1,17 +0,0 @@
1
- libei/__init__.py,sha256=8k-acXmeIea963zVksZW5Ymby8ZYL_aO6B4o7g4_Y9w,1858
2
- libei/_cobject.py,sha256=XjbUNJpZ87jAyPWh6dmRslk6cMy831oMRFhWmfjLDFo,13344
3
- libei/ei.py,sha256=W4akKc_BNVfL0FroSXLGD1Z_L3OmYjZT5QDHNnEtMP8,49367
4
- libei/eis.py,sha256=X_umAaAAbAMC9d2RdnMReeJZI61WsnKz3cySY5YrGr0,45841
5
- libei/oeffis.py,sha256=gJHR90s9VhQrgkjWUMDx-lxZ8qKxkttnqbx_xo-7oxs,10035
6
- libei/portal.py,sha256=FdtVdUUKrq2GOcDBtunLCISw7RYO4Mwyk3ci26OH330,81621
7
- libei/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- libei/_capi/__init__.py,sha256=raISSWSV9hAcE92DcLCz-vUb1IPcsmxRZaS-iAoQJBE,211
9
- libei/_capi/libei.py,sha256=qsccHa_komCxtvPYi6AobszhFbEG2qA8QYJJVr8SaGM,11356
10
- libei/_capi/libeis.py,sha256=C_Uh7DwNncFC8A4wuMhviAj5C_TUmKHtLJYq0Qhhz1E,13142
11
- libei/_capi/liboeffis.py,sha256=V8jdmJm3qOQUzzNiCAXt4Jr2JY11Y4-w6NIfIxbxGI4,1218
12
- libei/_capi/loader.py,sha256=xW67uk35ckgeFaheDGrHC05ZM5w_cxBGvX5lG_GUSu8,6625
13
- python_libei-0.8.0.dist-info/licenses/LICENSE,sha256=l6xbMU6Y-JZDzmBciBj-J5t6h6jNg_Bcyp4bHxDepqU,1074
14
- python_libei-0.8.0.dist-info/METADATA,sha256=SNey10DqR4IKZ_T_XCKmafkR0ioMfxHbdbaSl9IWG-c,22882
15
- python_libei-0.8.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
16
- python_libei-0.8.0.dist-info/top_level.txt,sha256=_DQXzGjDsUBENI_cNkiOxPB4xi8coCbQS1lq18FMudQ,6
17
- python_libei-0.8.0.dist-info/RECORD,,