diff --git a/build.py b/build.py index 85e7098a..4d9c77c1 100644 --- a/build.py +++ b/build.py @@ -23,6 +23,7 @@ def build(setup_kwargs): dict( ext_modules=cythonize( [ + "src/dbus_fast/_unpack.py", "src/dbus_fast/_private/marshaller.py", "src/dbus_fast/_private/unmarshaller.py", ] diff --git a/src/dbus_fast/__init__.py b/src/dbus_fast/__init__.py index 73fa53a0..8ebade4f 100644 --- a/src/dbus_fast/__init__.py +++ b/src/dbus_fast/__init__.py @@ -27,6 +27,7 @@ ) from .message import Message from .signature import SignatureTree, SignatureType, Variant +from .unpack import unpack_variants from .validators import ( assert_bus_name_valid, assert_interface_name_valid, @@ -37,3 +38,47 @@ is_member_name_valid, is_object_path_valid, ) + +__all__ = [ + "aio", + "glib", + "introspection", + "message_bus", + "proxy_object", + "service", + "ArgDirection", + "BusType", + "ErrorType", + "MessageFlag", + "MessageType", + "NameFlag", + "PropertyAccess", + "ReleaseNameReply", + "RequestNameReply", + "AuthError", + "DBusError", + "InterfaceNotFoundError", + "InvalidAddressError", + "InvalidBusNameError", + "InvalidInterfaceNameError", + "InvalidIntrospectionError", + "InvalidMemberNameError", + "InvalidMessageError", + "InvalidObjectPathError", + "InvalidSignatureError", + "SignalDisabledError", + "SignatureBodyMismatchError", + "Message", + "SignatureTree", + "SignatureType", + "Variant", + "assert_bus_name_valid", + "assert_interface_name_valid", + "assert_member_name_valid", + "assert_object_path_valid", + "is_bus_name_valid", + "is_interface_name_valid", + "is_member_name_valid", + "is_object_path_valid", + "unpack_variants", +] diff --git a/src/dbus_fast/aio/proxy_object.py b/src/dbus_fast/aio/proxy_object.py index 6bef63cd..5a260b09 100644 --- a/src/dbus_fast/aio/proxy_object.py +++ b/src/dbus_fast/aio/proxy_object.py @@ -9,7 +9,7 @@ from ..message_bus import BaseMessageBus from ..proxy_object import BaseProxyInterface, BaseProxyObject from ..signature import Variant -from ..signature import unpack_variants as unpack +from ..unpack import unpack_variants as unpack if TYPE_CHECKING: from .message_bus import MessageBus as AioMessageBus diff --git a/src/dbus_fast/glib/proxy_object.py b/src/dbus_fast/glib/proxy_object.py index a5a020a2..ba9f4722 100644 --- a/src/dbus_fast/glib/proxy_object.py +++ b/src/dbus_fast/glib/proxy_object.py @@ -8,7 +8,7 @@ from ..message_bus import BaseMessageBus from ..proxy_object import BaseProxyInterface, BaseProxyObject from ..signature import Variant -from ..signature import unpack_variants as unpack +from ..unpack import unpack_variants as unpack # glib is optional try: diff --git a/src/dbus_fast/proxy_object.py b/src/dbus_fast/proxy_object.py index f0130d24..71a052db 100644 --- a/src/dbus_fast/proxy_object.py +++ b/src/dbus_fast/proxy_object.py @@ -13,7 +13,7 @@ from .constants import ErrorType, MessageType from .errors import DBusError, InterfaceNotFoundError from .message import Message -from .signature import unpack_variants as unpack +from .unpack import unpack_variants as unpack from .validators import assert_bus_name_valid, assert_object_path_valid diff --git a/src/dbus_fast/signature.py b/src/dbus_fast/signature.py index fd264f81..a9081b6f 100644 --- a/src/dbus_fast/signature.py +++ b/src/dbus_fast/signature.py @@ -5,17 +5,6 @@ from .validators import is_object_path_valid -def unpack_variants(data: Any): - """Unpack variants and remove signature info.""" - if isinstance(data, Variant): - return unpack_variants(data.value) - if isinstance(data, dict): - return {k: unpack_variants(v) for k, v in data.items()} - if isinstance(data, list): - return [unpack_variants(item) for item in data] - return data - - class SignatureType: """A class that represents a single complete type within a signature. diff --git a/src/dbus_fast/unpack.pxd b/src/dbus_fast/unpack.pxd new file mode 100644 index 00000000..3f996c32 --- /dev/null +++ b/src/dbus_fast/unpack.pxd @@ -0,0 +1,6 @@ +"""cdefs for unpack.py""" + +import cython + + +cpdef unpack_variants(object data) diff --git a/src/dbus_fast/unpack.py b/src/dbus_fast/unpack.py new file mode 100644 index 00000000..ac2a1401 --- /dev/null +++ b/src/dbus_fast/unpack.py @@ -0,0 +1,14 @@ +from typing import Any + +from .signature import Variant + + +def unpack_variants(data: Any) -> Any: + """Unpack variants and remove signature info.""" + if isinstance(data, Variant): + return unpack_variants(data.value) + if isinstance(data, dict): + return {k: unpack_variants(v) for k, v in data.items()} + if isinstance(data, list): + return [unpack_variants(item) for item in data] + return data diff --git a/tests/test_unpack_variants.py b/tests/test_unpack_variants.py index 0c832990..61f46d66 100644 --- a/tests/test_unpack_variants.py +++ b/tests/test_unpack_variants.py @@ -1,7 +1,8 @@ """Test unpack variants.""" import pytest -from dbus_fast.signature import Variant, unpack_variants +from dbus_fast.signature import Variant +from dbus_fast.unpack import unpack_variants @pytest.mark.asyncio