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
24 changes: 13 additions & 11 deletions dbus_next/message_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,25 +399,27 @@ def _interface_signal_notify(self, interface, interface_name, member, signature,
def _introspect_export_path(self, path):
assert_object_path_valid(path)

node = None
if path in self._path_exports:
node = intr.Node.default(path)
[
for interface in self._path_exports[path]:
node.interfaces.append(interface.introspect())
for interface in self._path_exports[path]
]
else:
node = intr.Node(path)

path_split = [path for path in path.split('/') if path]
children = set()

for export_path in self._path_exports.keys():
export_path_split = [path for path in export_path.split('/') if path]
if len(export_path_split) <= len(path_split):
for export_path in self._path_exports:
try:
child_path = export_path.split(path, maxsplit=1)[1]
except IndexError:
continue
if all(path == export_path_split[i] for i, path in enumerate(path_split)):
child = intr.Node(export_path_split[len(path_split)])
node.nodes.append(child)

child_path = child_path.lstrip('/')
child_name = child_path.split('/', maxsplit=1)[0]

children.add(child_name)

node.nodes = [intr.Node(name) for name in children if name]

return node

Expand Down
17 changes: 17 additions & 0 deletions test/service/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,20 @@ async def test_export_alias():
member='some_method'))
assert result.message_type is MessageType.METHOD_RETURN, result.body[0]
assert interface._method_called


@pytest.mark.asyncio
async def test_export_introspection():
interface = ExampleInterface('test.interface')
interface2 = ExampleInterface('test.interface2')

export_path = '/test/path'
export_path2 = '/test/path/child'

bus = await MessageBus().connect()
bus.export(export_path, interface)
bus.export(export_path2, interface2)

root = bus._introspect_export_path('/')
assert len(root.nodes) == 1