dbus-fast 4.2.0__tar.gz → 4.2.2__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.
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/PKG-INFO +1 -1
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/pyproject.toml +1 -1
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/setup.py +1 -1
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/__version__.py +1 -1
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/introspection.py +47 -1
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/signature.py +6 -1
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/LICENSE +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/README.md +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/build_ext.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/__init__.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/_private/__init__.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/_private/_cython_compat.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/_private/address.pxd +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/_private/address.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/_private/constants.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/_private/marshaller.pxd +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/_private/marshaller.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/_private/unmarshaller.pxd +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/_private/unmarshaller.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/_private/util.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/aio/__init__.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/aio/message_bus.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/aio/message_reader.pxd +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/aio/message_reader.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/aio/proxy_object.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/annotations.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/auth.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/constants.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/errors.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/glib/__init__.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/glib/message_bus.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/glib/proxy_object.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/message.pxd +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/message.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/message_bus.pxd +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/message_bus.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/proxy_object.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/py.typed +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/send_reply.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/service.pxd +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/service.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/signature.pxd +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/unpack.pxd +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/unpack.py +0 -0
- {dbus_fast-4.2.0 → dbus_fast-4.2.2}/src/dbus_fast/validators.py +0 -0
|
@@ -12,7 +12,7 @@ package_data = \
|
|
|
12
12
|
|
|
13
13
|
setup_kwargs = {
|
|
14
14
|
'name': 'dbus-fast',
|
|
15
|
-
'version': '4.2.
|
|
15
|
+
'version': '4.2.2',
|
|
16
16
|
'description': 'A faster version of dbus-next',
|
|
17
17
|
'long_description': '# dbus-fast\n\n<p align="center">\n <a href="https://github.com/bluetooth-devices/dbus-fast/actions?query=workflow%3ACI">\n <img src="https://img.shields.io/github/workflow/status/bluetooth-devices/dbus-fast/CI/main?label=CI&logo=github&style=flat-square" alt="CI Status" >\n </a>\n <a href="https://dbus-fast.readthedocs.io">\n <img src="https://img.shields.io/readthedocs/dbus-fast.svg?logo=read-the-docs&logoColor=fff&style=flat-square" alt="Documentation Status">\n </a>\n <a href="https://codecov.io/gh/bluetooth-devices/dbus-fast">\n <img src="https://img.shields.io/codecov/c/github/bluetooth-devices/dbus-fast.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">\n </a>\n</p>\n<p align="center">\n <a href="https://python-poetry.org/">\n <img src="https://img.shields.io/badge/packaging-poetry-299bd7?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJJSURBVHgBfZLPa1NBEMe/s7tNXoxW1KJQKaUHkXhQvHgW6UHQQ09CBS/6V3hKc/AP8CqCrUcpmop3Cx48eDB4yEECjVQrlZb80CRN8t6OM/teagVxYZi38+Yz853dJbzoMV3MM8cJUcLMSUKIE8AzQ2PieZzFxEJOHMOgMQQ+dUgSAckNXhapU/NMhDSWLs1B24A8sO1xrN4NECkcAC9ASkiIJc6k5TRiUDPhnyMMdhKc+Zx19l6SgyeW76BEONY9exVQMzKExGKwwPsCzza7KGSSWRWEQhyEaDXp6ZHEr416ygbiKYOd7TEWvvcQIeusHYMJGhTwF9y7sGnSwaWyFAiyoxzqW0PM/RjghPxF2pWReAowTEXnDh0xgcLs8l2YQmOrj3N7ByiqEoH0cARs4u78WgAVkoEDIDoOi3AkcLOHU60RIg5wC4ZuTC7FaHKQm8Hq1fQuSOBvX/sodmNJSB5geaF5CPIkUeecdMxieoRO5jz9bheL6/tXjrwCyX/UYBUcjCaWHljx1xiX6z9xEjkYAzbGVnB8pvLmyXm9ep+W8CmsSHQQY77Zx1zboxAV0w7ybMhQmfqdmmw3nEp1I0Z+FGO6M8LZdoyZnuzzBdjISicKRnpxzI9fPb+0oYXsNdyi+d3h9bm9MWYHFtPeIZfLwzmFDKy1ai3p+PDls1Llz4yyFpferxjnyjJDSEy9CaCx5m2cJPerq6Xm34eTrZt3PqxYO1XOwDYZrFlH1fWnpU38Y9HRze3lj0vOujZcXKuuXm3jP+s3KbZVra7y2EAAAAAASUVORK5CYII=" alt="Poetry">\n </a>\n <a href="https://github.com/astral-sh/ruff">\n <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff">\n </a>\n <a href="https://github.com/pre-commit/pre-commit">\n <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">\n </a>\n <a href="https://codspeed.io/Bluetooth-Devices/dbus-fast"><img src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" alt="CodSpeed Badge"/></a>\n</p>\n<p align="center">\n <a href="https://pypi.org/project/dbus-fast/">\n <img src="https://img.shields.io/pypi/v/dbus-fast.svg?logo=python&logoColor=fff&style=flat-square" alt="PyPI Version">\n </a>\n <img src="https://img.shields.io/pypi/pyversions/dbus-fast.svg?style=flat-square&logo=python&logoColor=fff" alt="Supported Python versions">\n <img src="https://img.shields.io/pypi/l/dbus-fast.svg?style=flat-square" alt="License">\n</p>\n\nA faster version of dbus-next originally from the [great DBus next library](https://github.com/altdesktop/python-dbus-next) ❤️\n\n## Installation\n\nInstall this via pip (or your favourite package manager):\n\n`pip install dbus-fast`\n\n[Documentation](https://dbus-fast.readthedocs.io/en/latest/)\n\ndbus-fast is a Python library for DBus that aims to be a performant fully featured high level library primarily geared towards integration of applications into Linux desktop and mobile environments.\n\nDesktop application developers can use this library for integrating their applications into desktop environments by implementing common DBus standard interfaces or creating custom plugin interfaces.\n\nDesktop users can use this library to create their own scripts and utilities to interact with those interfaces for customization of their desktop environment.\n\ndbus-fast plans to improve over other DBus libraries for Python in the following ways:\n\n- Zero dependencies and pure Python 3\n- An optional cython extension is available to speed up (un)marshalling\n- Focus on performance\n- Support for multiple IO backends including asyncio and the GLib main loop.\n- Nonblocking IO suitable for GUI development.\n- Target the latest language features of Python for beautiful services and clients.\n- Complete implementation of the DBus type system without ever guessing types.\n- Integration tests for all features of the library.\n- Completely documented public API.\n\n## Installing\n\nThis library is available on PyPi as [dbus-fast](https://pypi.org/project/dbus-fast/).\n\n```\npip3 install dbus-fast\n```\n\n## The Client Interface\n\nTo use a service on the bus, the library constructs a proxy object you can use to call methods, get and set properties, and listen to signals.\n\nFor more information, see the [overview for the high-level client](https://dbus-fast.readthedocs.io/en/latest/high-level-client/index.html).\n\nThis example connects to a media player and controls it with the [MPRIS](https://specifications.freedesktop.org/mpris-spec/latest/) DBus interface.\n\n```python\nfrom dbus_fast.aio import MessageBus\n\nimport asyncio\n\n\nasync def main():\n bus = await MessageBus().connect()\n # the introspection xml would normally be included in your project, but\n # this is convenient for development\n introspection = await bus.introspect(\'org.mpris.MediaPlayer2.vlc\', \'/org/mpris/MediaPlayer2\')\n\n obj = bus.get_proxy_object(\'org.mpris.MediaPlayer2.vlc\', \'/org/mpris/MediaPlayer2\', introspection)\n player = obj.get_interface(\'org.mpris.MediaPlayer2.Player\')\n properties = obj.get_interface(\'org.freedesktop.DBus.Properties\')\n\n # call methods on the interface (this causes the media player to play)\n await player.call_play()\n\n volume = await player.get_volume()\n print(f\'current volume: {volume}, setting to 0.5\')\n\n await player.set_volume(0.5)\n\n # listen to signals\n def on_properties_changed(interface_name, changed_properties, invalidated_properties):\n for changed, variant in changed_properties.items():\n print(f\'property changed: {changed} - {variant.value}\')\n\n properties.on_properties_changed(on_properties_changed)\n\n await asyncio.Event().wait()\n\nasyncio.run(main())\n```\n\n## The Service Interface\n\nTo define a service on the bus, use the `ServiceInterface` class and decorate class methods to specify DBus methods, properties, and signals with their type signatures.\n\nFor more information, see the [overview for the high-level service](https://dbus-fast.readthedocs.io/en/latest/high-level-service/index.html).\n\n```python\nfrom dbus_fast.annotations import DBusStr, DBusDict\nfrom dbus_fast.service import ServiceInterface, dbus_method, dbus_property, dbus_signal\nfrom dbus_fast import Variant\nfrom dbus_fast.aio import MessageBus\n\nimport asyncio\n\nclass ExampleInterface(ServiceInterface):\n def __init__(self, name):\n super().__init__(name)\n self._string_prop = \'kevin\'\n\n @dbus_method()\n def Echo(self, what: DBusStr) -> DBusStr:\n return what\n\n @dbus_method()\n def GetVariantDict(self) -> DBusDict:\n return {\n \'foo\': Variant(\'s\', \'bar\'),\n \'bat\': Variant(\'x\', -55),\n \'a_list\': Variant(\'as\', [\'hello\', \'world\'])\n }\n\n @dbus_property()\n def string_prop(self) -> DBusStr:\n return self._string_prop\n\n @string_prop.setter\n def string_prop_setter(self, val: DBusStr):\n self._string_prop = val\n\n @dbus_signal()\n def signal_simple(self) -> DBusStr:\n return \'hello\'\n\nasync def main():\n bus = await MessageBus().connect()\n interface = ExampleInterface(\'test.interface\')\n bus.export(\'/test/path\', interface)\n # now that we are ready to handle requests, we can request name from D-Bus\n await bus.request_name(\'test.name\')\n # wait indefinitely\n await asyncio.Event().wait()\n\nasyncio.run(main())\n```\n\n## The Low-Level Interface\n\nThe low-level interface works with DBus messages directly.\n\nFor more information, see the [overview for the low-level interface](https://dbus-fast.readthedocs.io/en/latest/low-level-interface/index.html).\n\n```python\nfrom dbus_fast.message import Message, MessageType\nfrom dbus_fast.aio import MessageBus\n\nimport asyncio\nimport json\n\n\nasync def main():\n bus = await MessageBus().connect()\n\n reply = await bus.call(\n Message(destination=\'org.freedesktop.DBus\',\n path=\'/org/freedesktop/DBus\',\n interface=\'org.freedesktop.DBus\',\n member=\'ListNames\'))\n\n if reply.message_type == MessageType.ERROR:\n raise Exception(reply.body[0])\n\n print(json.dumps(reply.body[0], indent=2))\n\n\nasyncio.run(main())\n```\n\n## Projects that use dbus-fast\n\n- [Bluetooth Adapters](https://github.com/bluetooth-devices/bluetooth-adapters)\n\n## Contributing\n\nContributions are welcome. Development happens on [Github](https://github.com/Bluetooth-Devices/dbus-fast).\n\nBefore you commit, run `pre-commit run --all-files` to run the linter, code formatter, and the test suite.\n\n## Copyright\n\nYou can use this code under an MIT license (see LICENSE).\n\n- © 2019, Tony Crisci\n- © 2022, Bluetooth Devices authors\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n<!-- prettier-ignore-start -->\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- markdownlint-disable -->\n<!-- markdownlint-enable -->\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n<!-- prettier-ignore-end -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n## Credits\n\nThis package was created with\n[Cookiecutter](https://github.com/audreyr/cookiecutter) and the\n[browniebroke/cookiecutter-pypackage](https://github.com/browniebroke/cookiecutter-pypackage)\nproject template.\n',
|
|
18
18
|
'author': 'Bluetooth Devices Authors',
|
|
@@ -3,7 +3,7 @@ __description__ = (
|
|
|
3
3
|
"A performant zero-dependency DBus library for Python with asyncio support"
|
|
4
4
|
)
|
|
5
5
|
__url__ = "https://github.com/bluetooth-devices/dbus-fast"
|
|
6
|
-
__version__ = "4.2.
|
|
6
|
+
__version__ = "4.2.2"
|
|
7
7
|
__author__ = "Bluetooth Devices authors, Tony Crisci"
|
|
8
8
|
__author_email__ = "bluetooth@koston.org"
|
|
9
9
|
__license__ = "MIT"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import xml.etree.ElementTree as ET
|
|
2
|
+
import xml.parsers.expat as _expat
|
|
2
3
|
|
|
3
4
|
from .constants import ArgDirection, PropertyAccess
|
|
4
5
|
from .errors import InvalidIntrospectionError
|
|
@@ -8,6 +9,51 @@ from .validators import assert_interface_name_valid, assert_member_name_valid
|
|
|
8
9
|
# https://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
|
|
9
10
|
|
|
10
11
|
|
|
12
|
+
def _reject_internal_subset(
|
|
13
|
+
_name: str,
|
|
14
|
+
_sysid: str | None,
|
|
15
|
+
_pubid: str | None,
|
|
16
|
+
has_internal_subset: bool,
|
|
17
|
+
) -> None:
|
|
18
|
+
# The standard D-Bus introspection DOCTYPE is PUBLIC-only with no
|
|
19
|
+
# internal subset. Any `[ ... ]` block in the DOCTYPE is therefore
|
|
20
|
+
# either the billion-laughs / quadratic-blowup ENTITY vector, an
|
|
21
|
+
# ATTLIST default-value amplification, or an XXE attempt from a
|
|
22
|
+
# hostile peer — reject the whole subset as a single boundary.
|
|
23
|
+
if has_internal_subset:
|
|
24
|
+
raise InvalidIntrospectionError(
|
|
25
|
+
"internal DTD subsets are not allowed in introspection XML"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _parse_introspection_xml(data: str) -> ET.Element:
|
|
30
|
+
"""Parse introspection XML with the DTD-based amplification vectors closed."""
|
|
31
|
+
# namespace_separator="}" mirrors ElementTree's expat config so a
|
|
32
|
+
# namespaced root (`<node xmlns="urn:x">`) still surfaces with a
|
|
33
|
+
# non-"node" tag and gets rejected by the root-element check below
|
|
34
|
+
# rather than slipping through this stricter parser.
|
|
35
|
+
parser = _expat.ParserCreate(namespace_separator="}")
|
|
36
|
+
builder = ET.TreeBuilder()
|
|
37
|
+
parser.StartElementHandler = builder.start
|
|
38
|
+
parser.EndElementHandler = builder.end
|
|
39
|
+
parser.CharacterDataHandler = builder.data
|
|
40
|
+
parser.StartDoctypeDeclHandler = _reject_internal_subset
|
|
41
|
+
# Defense-in-depth: refuse to expand parameter entities, which is the
|
|
42
|
+
# path expat would otherwise take to fetch external DTDs.
|
|
43
|
+
parser.SetParamEntityParsing(_expat.XML_PARAM_ENTITY_PARSING_NEVER)
|
|
44
|
+
try:
|
|
45
|
+
parser.Parse(data.encode("utf-8") if isinstance(data, str) else data, True)
|
|
46
|
+
except _expat.ExpatError as e:
|
|
47
|
+
# Preserve the code / position metadata ElementTree attaches to
|
|
48
|
+
# ParseError so callers that inspect them (e.position, e.code) keep
|
|
49
|
+
# working as they did with ET.fromstring.
|
|
50
|
+
err = ET.ParseError(e)
|
|
51
|
+
err.code = e.code
|
|
52
|
+
err.position = (e.lineno, e.offset)
|
|
53
|
+
raise err from e
|
|
54
|
+
return builder.close()
|
|
55
|
+
|
|
56
|
+
|
|
11
57
|
def _fetch_annotations(element: ET.Element) -> dict[str, str]:
|
|
12
58
|
annotations: dict[str, str] = {}
|
|
13
59
|
|
|
@@ -532,7 +578,7 @@ class Node:
|
|
|
532
578
|
:raises:
|
|
533
579
|
- :class:`InvalidIntrospectionError <dbus_fast.InvalidIntrospectionError>` - If the string is not valid introspection data.
|
|
534
580
|
"""
|
|
535
|
-
element =
|
|
581
|
+
element = _parse_introspection_xml(data)
|
|
536
582
|
if element.tag != "node":
|
|
537
583
|
raise InvalidIntrospectionError(
|
|
538
584
|
'introspection data must have a "node" for the root element'
|
|
@@ -473,7 +473,12 @@ class Variant: # noqa: PLW1641
|
|
|
473
473
|
return f"<dbus_fast.signature.Variant ('{self.type.signature}', {self.value})>"
|
|
474
474
|
|
|
475
475
|
|
|
476
|
-
|
|
476
|
+
# Bound the cache so a peer streaming messages with unique attacker-chosen
|
|
477
|
+
# signatures (signatures up to 255 bytes, body-side signatures pass through
|
|
478
|
+
# get_signature_tree in the unmarshaller) cannot grow this dict without
|
|
479
|
+
# limit and OOM the process. 4096 entries covers every signature emitted
|
|
480
|
+
# by real-world D-Bus services many times over.
|
|
481
|
+
get_signature_tree = lru_cache(maxsize=4096)(SignatureTree)
|
|
477
482
|
"""Get a signature tree for the given signature.
|
|
478
483
|
|
|
479
484
|
:param signature: The signature to get a tree for.
|
|
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
|
|
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
|