No project description provided
Project description
dbus-objects
DBus objects implementation on top of the Python type system.
Integrations:
import random
from typing import List
import dbus_objects.object
import dbus_objects.integration.jeepney
class ExampleObject(dbus_objects.object.DBusObject):
def __init__(self):
super().__init__(default_interface_root='io.github.ffy00.dbus_objects.example')
self._bets = []
@dbus_objects.object.dbus_method()
def ping(self) -> str:
return 'Pong!'
@dbus_objects.object.dbus_method()
def print(self, msg: str) -> None:
print(msg)
@dbus_objects.object.dbus_method()
def sum(self, a: int, b: int) -> int:
return a + b
@dbus_objects.object.dbus_method()
def save_bet(self, number: int) -> None:
self._bets.append(number)
@dbus_objects.object.dbus_method()
def get_bets(self) -> List[int]:
return self._bets
@dbus_objects.object.dbus_method()
def lotery(self) -> int:
winner = random.choice(self._bets)
self._bets = []
return winner
server = dbus_objects.integration.jeepney.BlockingDBusServer(
bus='SESSION',
name='io.github.ffy00.dbus-objects'
)
server.register_object('/io/github/ffy00/dbus_objects/example', ExampleObject())
server.listen()
This example will generate the following server topology:
paths
├── /
│ ├── org.freedesktop.DBus.Introspectable
│ │ └── Introspect
│ └── org.freedesktop.DBus.Peer
│ └── Ping
├── /io
│ ├── org.freedesktop.DBus.Introspectable
│ │ └── Introspect
│ └── org.freedesktop.DBus.Peer
│ └── Ping
├── /io/github
│ ├── org.freedesktop.DBus.Introspectable
│ │ └── Introspect
│ └── org.freedesktop.DBus.Peer
│ └── Ping
├── /io/github/ffy00
│ ├── org.freedesktop.DBus.Introspectable
│ │ └── Introspect
│ └── org.freedesktop.DBus.Peer
│ └── Ping
├── /io/github/ffy00/dbus_objects
│ ├── org.freedesktop.DBus.Introspectable
│ │ └── Introspect
│ └── org.freedesktop.DBus.Peer
│ └── Ping
└── /io/github/ffy00/dbus_objects/example
├── io.github.ffy00.dbus_objects.example.ExampleObject
│ ├── GetBets
│ ├── Lotery
│ ├── Ping
│ ├── Print
│ ├── SaveBet
│ └── Sum
├── org.freedesktop.DBus.Introspectable
│ └── Introspect
├── org.freedesktop.DBus.Peer
│ └── Ping
└── org.freedesktop.DBus.Properties
├── Get
├── GetAll
└── Set
And, for eg., the following DBus introspection XML for /io/github/ffy00/dbus_objects/example
:
<!DOCTYPE node PUBLIC
"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" >
<node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
<interface name="io.github.ffy00.dbus_objects.example.ExampleObject">
<method name="GetBets">
<arg direction="out" type="ai" />
</method>
<method name="Lotery">
<arg direction="out" type="i" />
</method>
<method name="Ping">
<arg direction="out" type="s" />
</method>
<method name="Print">
<arg direction="in" type="s" name="msg" />
</method>
<method name="SaveBet">
<arg direction="in" type="i" name="number" />
</method>
<method name="Sum">
<arg direction="in" type="i" name="a" />
<arg direction="in" type="i" name="b" />
<arg direction="out" type="i" />
</method>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="GetAll">
<arg direction="in" type="s" name="interface_name" />
<arg direction="out" type="a{sv}" />
</method>
</interface>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg direction="out" type="s" name="xml" />
</method>
</interface>
<interface name="org.freedesktop.DBus.Peer">
<method name="Ping" />
</interface>
</node>
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dbus-objects-0.0.1b1.tar.gz
(13.1 kB
view details)
Built Distribution
File details
Details for the file dbus-objects-0.0.1b1.tar.gz
.
File metadata
- Download URL: dbus-objects-0.0.1b1.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11763b2b2066a25ab7a1d48d6f43f37696ee0580afbe22cac98684584fa7590a |
|
MD5 | de0921486beb10c749e93cbebad49e3c |
|
BLAKE2b-256 | eed6820496d7e1db5fbabb0a1d829f414caa3f12d65d11c695dd0d1122ac650f |
Provenance
File details
Details for the file dbus_objects-0.0.1b1-py3-none-any.whl
.
File metadata
- Download URL: dbus_objects-0.0.1b1-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61e8e66a55ab234677edea6c94b36f0000a01e3e6793b480bcf03dec3ffe562b |
|
MD5 | 76cd991215883a81db87d8c74cd6ff49 |
|
BLAKE2b-256 | e0ef5dbb4cd14414883f10f6077acdedb5e3019f7d7bab88ffff2049cfcfd62d |