Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/sdbus/dbus_common_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@
T = TypeVar('T')


class DbusSomethingCommon:
class DbusMemberCommon:
interface_name: str
serving_enabled: bool


class DbusSomethingAsync(DbusSomethingCommon):
class DbusMemberAsync(DbusMemberCommon):
...


class DbusSomethingSync(DbusSomethingCommon):
class DbusMemberSync(DbusMemberCommon):
...


Expand All @@ -83,7 +83,7 @@ def __new__(cls: Type[SelfMeta], name: str,
...

for attr_name, attr in namespace.items():
if not isinstance(attr, DbusSomethingCommon):
if not isinstance(attr, DbusMemberCommon):
continue

# TODO: Fix async metaclass copying all methods
Expand Down Expand Up @@ -112,7 +112,7 @@ def __new__(cls: Type[SelfMeta], name: str,
)


class DbusMethodCommon(DbusSomethingCommon):
class DbusMethodCommon(DbusMemberCommon):

def __init__(
self,
Expand Down Expand Up @@ -231,7 +231,7 @@ def _rebuild_args(
return new_args_list


class DbusPropertyCommon(DbusSomethingCommon):
class DbusPropertyCommon(DbusMemberCommon):
def __init__(self,
property_name: Optional[str],
property_signature: str,
Expand Down Expand Up @@ -262,7 +262,7 @@ def __init__(self,
self.flags = flags


class DbusSignalCommon(DbusSomethingCommon):
class DbusSignalCommon(DbusMemberCommon):
def __init__(self,
signal_name: Optional[str],
signal_signature: str,
Expand Down Expand Up @@ -291,11 +291,11 @@ def __init__(self,
self.__annotations__ = original_method.__annotations__


class DbusBindedAsync:
class DbusBoundAsync:
...


class DbusBindedSync:
class DbusBoundSync:
...


Expand Down
52 changes: 26 additions & 26 deletions src/sdbus/dbus_proxy_async_interface_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@
DbusClassMeta,
DbusInterfaceMetaCommon,
DbusLocalObjectMeta,
DbusMemberAsync,
DbusMemberCommon,
DbusMemberSync,
DbusMethodOverride,
DbusPropertyOverride,
DbusRemoteObjectMeta,
DbusSomethingAsync,
DbusSomethingCommon,
DbusSomethingSync,
)
from .dbus_common_funcs import get_default_bus
from .dbus_proxy_async_method import DbusMethodAsync, DbusMethodAsyncLocalBind
from .dbus_proxy_async_method import DbusLocalMethodAsync, DbusMethodAsync
from .dbus_proxy_async_property import (
DbusLocalPropertyAsync,
DbusPropertyAsync,
DbusPropertyAsyncLocalBind,
)
from .dbus_proxy_async_signal import DbusSignalAsync, DbusSignalAsyncLocalBind
from .dbus_proxy_async_signal import DbusLocalSignalAsync, DbusSignalAsync
from .sd_bus_internals import SdBusInterface

if TYPE_CHECKING:
Expand All @@ -61,7 +61,7 @@
Union,
)

from .dbus_common_elements import DbusBindedAsync
from .dbus_common_elements import DbusBoundAsync
from .sd_bus_internals import SdBus, SdBusSlot

T = TypeVar('T')
Expand All @@ -81,7 +81,7 @@ class DbusInterfaceMetaAsync(DbusInterfaceMetaCommon):
def _process_dbus_method_override(
override_attr_name: str,
override: DbusMethodOverride[T],
mro_dbus_elements: Dict[str, DbusSomethingAsync],
mro_dbus_elements: Dict[str, DbusMemberAsync],
) -> DbusMethodAsync:
try:
original_method = mro_dbus_elements[override_attr_name]
Expand All @@ -105,7 +105,7 @@ def _process_dbus_method_override(
def _process_dbus_property_override(
override_attr_name: str,
override: DbusPropertyOverride[T],
mro_dbus_elements: Dict[str, DbusSomethingAsync],
mro_dbus_elements: Dict[str, DbusMemberAsync],
) -> DbusPropertyAsync[Any]:
try:
original_property = mro_dbus_elements[override_attr_name]
Expand Down Expand Up @@ -137,11 +137,11 @@ def _check_collisions(
cls,
new_class_name: str,
namespace: Dict[str, Any],
mro_dbus_elements: Dict[str, DbusSomethingAsync],
mro_dbus_elements: Dict[str, DbusMemberAsync],
) -> None:

possible_collisions = namespace.keys() & mro_dbus_elements.keys()
new_overrides: Dict[str, DbusSomethingAsync] = {}
new_overrides: Dict[str, DbusMemberAsync] = {}

for attr_name, attr in namespace.items():
if isinstance(attr, DbusMethodOverride):
Expand Down Expand Up @@ -173,12 +173,12 @@ def _check_collisions(
def _extract_dbus_elements(
dbus_class: type,
dbus_meta: DbusClassMeta,
) -> Dict[str, DbusSomethingAsync]:
dbus_elements_map: Dict[str, DbusSomethingAsync] = {}
) -> Dict[str, DbusMemberAsync]:
dbus_elements_map: Dict[str, DbusMemberAsync] = {}

for attr_name in dbus_meta.python_attr_to_dbus_member.keys():
dbus_element = dbus_class.__dict__.get(attr_name)
if not isinstance(dbus_element, DbusSomethingAsync):
if not isinstance(dbus_element, DbusMemberAsync):
raise TypeError(
f"Expected async D-Bus element, got {dbus_element!r} "
f"in class {dbus_class!r}"
Expand All @@ -193,8 +193,8 @@ def _map_mro_dbus_elements(
cls,
new_class_name: str,
base_classes: Iterable[type],
) -> Dict[str, DbusSomethingAsync]:
all_python_dbus_map: Dict[str, DbusSomethingAsync] = {}
) -> Dict[str, DbusMemberAsync]:
all_python_dbus_map: Dict[str, DbusMemberAsync] = {}
possible_collisions: Set[str] = set()

for c in base_classes:
Expand Down Expand Up @@ -227,10 +227,10 @@ def _map_dbus_elements(
meta: DbusClassMeta,
interface_name: str,
) -> None:
if not isinstance(attr, DbusSomethingCommon):
if not isinstance(attr, DbusMemberCommon):
return

if isinstance(attr, DbusSomethingSync):
if isinstance(attr, DbusMemberSync):
raise TypeError(
"Can't mix blocking methods in "
f"async interface: {attr_name!r}"
Expand Down Expand Up @@ -344,20 +344,20 @@ def export_to_dbus(
local_object_meta.attached_bus = bus
local_object_meta.serving_object_path = object_path
# TODO: can be optimized with a single loop
interface_map: Dict[str, List[DbusBindedAsync]] = {}
interface_map: Dict[str, List[DbusBoundAsync]] = {}

for key, value in getmembers(self):
assert not isinstance(value, DbusSomethingAsync)
assert not isinstance(value, DbusMemberAsync)

if isinstance(value, DbusMethodAsyncLocalBind):
if isinstance(value, DbusLocalMethodAsync):
interface_name = value.dbus_method.interface_name
if not value.dbus_method.serving_enabled:
continue
elif isinstance(value, DbusPropertyAsyncLocalBind):
elif isinstance(value, DbusLocalPropertyAsync):
interface_name = value.dbus_property.interface_name
if not value.dbus_property.serving_enabled:
continue
elif isinstance(value, DbusSignalAsyncLocalBind):
elif isinstance(value, DbusLocalSignalAsync):
interface_name = value.dbus_signal.interface_name
if not value.dbus_signal.serving_enabled:
continue
Expand All @@ -375,7 +375,7 @@ def export_to_dbus(
for interface_name, member_list in interface_map.items():
new_interface = SdBusInterface()
for dbus_something in member_list:
if isinstance(dbus_something, DbusMethodAsyncLocalBind):
if isinstance(dbus_something, DbusLocalMethodAsync):
new_interface.add_method(
dbus_something.dbus_method.method_name,
dbus_something.dbus_method.input_signature,
Expand All @@ -385,7 +385,7 @@ def export_to_dbus(
dbus_something.dbus_method.flags,
dbus_something._dbus_reply_call,
)
elif isinstance(dbus_something, DbusPropertyAsyncLocalBind):
elif isinstance(dbus_something, DbusLocalPropertyAsync):
getter = dbus_something._dbus_reply_get
dbus_property = dbus_something.dbus_property

Expand All @@ -405,7 +405,7 @@ def export_to_dbus(
setter,
dbus_property.flags,
)
elif isinstance(dbus_something, DbusSignalAsyncLocalBind):
elif isinstance(dbus_something, DbusLocalSignalAsync):
new_interface.add_signal(
dbus_something.dbus_signal.signal_name,
dbus_something.dbus_signal.signal_signature,
Expand Down
16 changes: 8 additions & 8 deletions src/sdbus/dbus_proxy_async_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
from weakref import ref as weak_ref

from .dbus_common_elements import (
DbusBindedAsync,
DbusBoundAsync,
DbusMemberAsync,
DbusMethodCommon,
DbusMethodOverride,
DbusRemoteObjectMeta,
DbusSomethingAsync,
)
from .dbus_exceptions import DbusFailedError
from .sd_bus_internals import DbusNoReplyFlag
Expand All @@ -52,7 +52,7 @@ def get_current_message() -> SdBusMessage:
return CURRENT_MESSAGE.get()


class DbusMethodAsync(DbusMethodCommon, DbusSomethingAsync):
class DbusMethodAsync(DbusMethodCommon, DbusMemberAsync):

@overload
def __get__(
Expand All @@ -78,20 +78,20 @@ def __get__(
if obj is not None:
dbus_meta = obj._dbus
if isinstance(dbus_meta, DbusRemoteObjectMeta):
return DbusMethodAsyncProxyBind(self, dbus_meta)
return DbusProxyMethodAsync(self, dbus_meta)
else:
return DbusMethodAsyncLocalBind(self, obj)
return DbusLocalMethodAsync(self, obj)
else:
return self


class DbusMethodAsyncBaseBind(DbusBindedAsync):
class DbusBoundMethodAsyncBase(DbusBoundAsync):

def __call__(self, *args: Any, **kwargs: Any) -> Any:
raise NotImplementedError


class DbusMethodAsyncProxyBind(DbusMethodAsyncBaseBind):
class DbusProxyMethodAsync(DbusBoundMethodAsyncBase):
def __init__(
self,
dbus_method: DbusMethodAsync,
Expand Down Expand Up @@ -145,7 +145,7 @@ def __call__(self, *args: Any, **kwargs: Any) -> Any:
return self._dbus_async_call(new_call_message)


class DbusMethodAsyncLocalBind(DbusMethodAsyncBaseBind):
class DbusLocalMethodAsync(DbusBoundMethodAsyncBase):
def __init__(
self,
dbus_method: DbusMethodAsync,
Expand Down
20 changes: 10 additions & 10 deletions src/sdbus/dbus_proxy_async_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
from weakref import ref as weak_ref

from .dbus_common_elements import (
DbusBindedAsync,
DbusBoundAsync,
DbusMemberAsync,
DbusPropertyCommon,
DbusPropertyOverride,
DbusRemoteObjectMeta,
DbusSomethingAsync,
)

if TYPE_CHECKING:
Expand All @@ -42,7 +42,7 @@
T = TypeVar('T')


class DbusPropertyAsync(DbusSomethingAsync, DbusPropertyCommon, Generic[T]):
class DbusPropertyAsync(DbusMemberAsync, DbusPropertyCommon, Generic[T]):
def __init__(
self,
property_name: Optional[str],
Expand Down Expand Up @@ -84,20 +84,20 @@ def __get__(
self,
obj: DbusInterfaceBaseAsync,
obj_class: Type[DbusInterfaceBaseAsync],
) -> DbusPropertyAsyncBaseBind[T]:
) -> DbusBoundPropertyAsyncBase[T]:
...

def __get__(
self,
obj: Optional[DbusInterfaceBaseAsync],
obj_class: Optional[Type[DbusInterfaceBaseAsync]] = None,
) -> Union[DbusPropertyAsyncBaseBind[T], DbusPropertyAsync[T]]:
) -> Union[DbusBoundPropertyAsyncBase[T], DbusPropertyAsync[T]]:
if obj is not None:
dbus_meta = obj._dbus
if isinstance(dbus_meta, DbusRemoteObjectMeta):
return DbusPropertyAsyncProxyBind(self, dbus_meta)
return DbusProxyPropertyAsync(self, dbus_meta)
else:
return DbusPropertyAsyncLocalBind(self, obj)
return DbusLocalPropertyAsync(self, obj)
else:
return self

Expand Down Expand Up @@ -126,7 +126,7 @@ def setter_private(
self.property_setter_is_public = False


class DbusPropertyAsyncBaseBind(DbusBindedAsync, Awaitable[T]):
class DbusBoundPropertyAsyncBase(DbusBoundAsync, Awaitable[T]):
def __await__(self) -> Generator[Any, None, T]:
return self.get_async().__await__()

Expand All @@ -137,7 +137,7 @@ async def set_async(self, complete_object: T) -> None:
raise NotImplementedError


class DbusPropertyAsyncProxyBind(DbusPropertyAsyncBaseBind[T]):
class DbusProxyPropertyAsync(DbusBoundPropertyAsyncBase[T]):
def __init__(
self,
dbus_property: DbusPropertyAsync[T],
Expand Down Expand Up @@ -179,7 +179,7 @@ async def set_async(self, complete_object: T) -> None:
await bus.call_async(new_set_message)


class DbusPropertyAsyncLocalBind(DbusPropertyAsyncBaseBind[T]):
class DbusLocalPropertyAsync(DbusBoundPropertyAsyncBase[T]):
def __init__(
self,
dbus_property: DbusPropertyAsync[T],
Expand Down
Loading