dbus-fast 3.1.2__cp310-cp310-macosx_11_0_arm64.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.
Files changed (51) hide show
  1. dbus_fast/__init__.py +82 -0
  2. dbus_fast/__version__.py +10 -0
  3. dbus_fast/_private/__init__.py +1 -0
  4. dbus_fast/_private/_cython_compat.py +14 -0
  5. dbus_fast/_private/address.cpython-310-darwin.so +0 -0
  6. dbus_fast/_private/address.pxd +15 -0
  7. dbus_fast/_private/address.py +119 -0
  8. dbus_fast/_private/constants.py +20 -0
  9. dbus_fast/_private/marshaller.cpython-310-darwin.so +0 -0
  10. dbus_fast/_private/marshaller.pxd +110 -0
  11. dbus_fast/_private/marshaller.py +231 -0
  12. dbus_fast/_private/unmarshaller.cpython-310-darwin.so +0 -0
  13. dbus_fast/_private/unmarshaller.pxd +261 -0
  14. dbus_fast/_private/unmarshaller.py +904 -0
  15. dbus_fast/_private/util.py +177 -0
  16. dbus_fast/aio/__init__.py +5 -0
  17. dbus_fast/aio/message_bus.py +578 -0
  18. dbus_fast/aio/message_reader.cpython-310-darwin.so +0 -0
  19. dbus_fast/aio/message_reader.pxd +13 -0
  20. dbus_fast/aio/message_reader.py +51 -0
  21. dbus_fast/aio/proxy_object.py +208 -0
  22. dbus_fast/auth.py +125 -0
  23. dbus_fast/constants.py +152 -0
  24. dbus_fast/errors.py +81 -0
  25. dbus_fast/glib/__init__.py +3 -0
  26. dbus_fast/glib/message_bus.py +513 -0
  27. dbus_fast/glib/proxy_object.py +318 -0
  28. dbus_fast/introspection.py +686 -0
  29. dbus_fast/message.cpython-310-darwin.so +0 -0
  30. dbus_fast/message.pxd +76 -0
  31. dbus_fast/message.py +389 -0
  32. dbus_fast/message_bus.cpython-310-darwin.so +0 -0
  33. dbus_fast/message_bus.pxd +75 -0
  34. dbus_fast/message_bus.py +1332 -0
  35. dbus_fast/proxy_object.py +357 -0
  36. dbus_fast/py.typed +0 -0
  37. dbus_fast/send_reply.py +61 -0
  38. dbus_fast/service.cpython-310-darwin.so +0 -0
  39. dbus_fast/service.pxd +50 -0
  40. dbus_fast/service.py +727 -0
  41. dbus_fast/signature.cpython-310-darwin.so +0 -0
  42. dbus_fast/signature.pxd +31 -0
  43. dbus_fast/signature.py +484 -0
  44. dbus_fast/unpack.cpython-310-darwin.so +0 -0
  45. dbus_fast/unpack.pxd +13 -0
  46. dbus_fast/unpack.py +28 -0
  47. dbus_fast/validators.py +199 -0
  48. dbus_fast-3.1.2.dist-info/METADATA +262 -0
  49. dbus_fast-3.1.2.dist-info/RECORD +51 -0
  50. dbus_fast-3.1.2.dist-info/WHEEL +6 -0
  51. dbus_fast-3.1.2.dist-info/licenses/LICENSE +22 -0
@@ -0,0 +1,177 @@
1
+ from __future__ import annotations
2
+
3
+ import ast
4
+ import inspect
5
+ from collections.abc import Callable
6
+ from typing import Any
7
+
8
+ from ..signature import SignatureTree, SignatureType, Variant, get_signature_tree
9
+
10
+
11
+ def signature_contains_type(
12
+ signature: str | SignatureTree, body: list[Any], token: str
13
+ ) -> bool:
14
+ """For a given signature and body, check to see if it contains any members
15
+ with the given token"""
16
+ if type(signature) is str:
17
+ signature = get_signature_tree(signature)
18
+
19
+ queue = list(signature.types) # type: ignore[union-attr]
20
+ contains_variants = False
21
+
22
+ while True:
23
+ if not queue:
24
+ break
25
+ st = queue.pop()
26
+ if st.token == token:
27
+ return True
28
+ if st.token == "v":
29
+ contains_variants = True
30
+ queue.extend(st.children)
31
+
32
+ if not contains_variants:
33
+ return False
34
+
35
+ for member in body:
36
+ queue.append(member)
37
+
38
+ while True:
39
+ if not queue:
40
+ return False
41
+ member = queue.pop()
42
+ if type(member) is Variant and signature_contains_type(
43
+ member.signature, [member.value], token
44
+ ):
45
+ return True
46
+ if type(member) is list:
47
+ queue.extend(member)
48
+ elif type(member) is dict:
49
+ queue.extend(member.values())
50
+
51
+
52
+ def replace_fds_with_idx(
53
+ signature: str | SignatureTree, body: list[Any]
54
+ ) -> tuple[list[Any], list[int]]:
55
+ """Take the high level body format and convert it into the low level body
56
+ format. Type 'h' refers directly to the fd in the body. Replace that with
57
+ an index and return the corresponding list of unix fds that can be set on
58
+ the Message"""
59
+ if type(signature) is str:
60
+ signature = get_signature_tree(signature)
61
+
62
+ if not signature_contains_type(signature, body, "h"):
63
+ return body, []
64
+
65
+ unix_fds: list[Any] = []
66
+
67
+ def _replace(fd: Any) -> int:
68
+ try:
69
+ return unix_fds.index(fd)
70
+ except ValueError:
71
+ unix_fds.append(fd)
72
+ return len(unix_fds) - 1
73
+
74
+ _replace_fds(body, signature.types, _replace) # type: ignore[union-attr]
75
+
76
+ return body, unix_fds
77
+
78
+
79
+ def replace_idx_with_fds(
80
+ signature: str | SignatureTree, body: list[Any], unix_fds: list[Any]
81
+ ) -> list[Any]:
82
+ """Take the low level body format and return the high level body format.
83
+ Type 'h' refers to an index in the unix_fds array. Replace those with the
84
+ actual file descriptor or `None` if one does not exist."""
85
+ if type(signature) is str:
86
+ signature = get_signature_tree(signature)
87
+
88
+ if not signature_contains_type(signature, body, "h"):
89
+ return body
90
+
91
+ def _replace(idx: int) -> Any:
92
+ try:
93
+ return unix_fds[idx]
94
+ except IndexError:
95
+ return None
96
+
97
+ _replace_fds(body, signature.types, _replace) # type: ignore[union-attr]
98
+
99
+ return body
100
+
101
+
102
+ def parse_annotation(annotation: str) -> str:
103
+ """
104
+ Because of PEP 563, if `from __future__ import annotations` is used in code
105
+ or on Python version >=3.10 where this is the default, return annotations
106
+ from the `inspect` module will return annotations as "forward definitions".
107
+ In this case, we must eval the result which we do only when given a string
108
+ constant.
109
+ """
110
+
111
+ def raise_value_error() -> None:
112
+ raise ValueError(
113
+ f"service annotations must be a string constant (got {annotation})"
114
+ )
115
+
116
+ if not annotation or annotation is inspect.Signature.empty:
117
+ return ""
118
+ if type(annotation) is not str:
119
+ raise_value_error()
120
+ try:
121
+ body = ast.parse(annotation).body
122
+ if len(body) == 1 and type(body[0].value) is ast.Constant: # type: ignore[attr-defined]
123
+ if type(body[0].value.value) is not str: # type: ignore[attr-defined]
124
+ raise_value_error()
125
+ return body[0].value.value # type: ignore[attr-defined]
126
+ except SyntaxError:
127
+ pass
128
+
129
+ return annotation
130
+
131
+
132
+ def _replace_fds(
133
+ body_obj: dict[Any, Any] | list[Any],
134
+ children: list[SignatureType],
135
+ replace_fn: Callable[[Any], Any],
136
+ ) -> None:
137
+ """Replace any type 'h' with the value returned by replace_fn() given the
138
+ value of the fd field. This is used by the high level interfaces which
139
+ allow type 'h' to be the fd directly instead of an index in an external
140
+ array such as in the spec."""
141
+ for index, st in enumerate(children):
142
+ if not any(sig in st.signature for sig in "hv"):
143
+ continue
144
+ if st.signature == "h":
145
+ body_obj[index] = replace_fn(body_obj[index])
146
+ elif st.token == "a":
147
+ if st.children[0].token == "{":
148
+ _replace_fds(body_obj[index], st.children, replace_fn)
149
+ else:
150
+ for i, child in enumerate(body_obj[index]):
151
+ if st.signature == "ah":
152
+ body_obj[index][i] = replace_fn(child)
153
+ else:
154
+ _replace_fds([child], st.children, replace_fn)
155
+ elif st.token in "(":
156
+ _replace_fds(body_obj[index], st.children, replace_fn)
157
+ elif st.token in "{":
158
+ for key, value in list(body_obj.items()): # type: ignore[union-attr]
159
+ body_obj.pop(key)
160
+ if st.children[0].signature == "h":
161
+ key = replace_fn(key)
162
+ if st.children[1].signature == "h":
163
+ value = replace_fn(value)
164
+ else:
165
+ _replace_fds([value], [st.children[1]], replace_fn)
166
+ body_obj[key] = value
167
+
168
+ elif st.signature == "v":
169
+ if body_obj[index].signature == "h":
170
+ body_obj[index].value = replace_fn(body_obj[index].value)
171
+ else:
172
+ _replace_fds(
173
+ [body_obj[index].value], [body_obj[index].type], replace_fn
174
+ )
175
+
176
+ elif st.children:
177
+ _replace_fds(body_obj[index], st.children, replace_fn)
@@ -0,0 +1,5 @@
1
+ from __future__ import annotations
2
+
3
+ from .message_bus import MessageBus as MessageBus
4
+ from .proxy_object import ProxyInterface as ProxyInterface
5
+ from .proxy_object import ProxyObject as ProxyObject