Mini Shell

Direktori : /usr/lib/python3.6/site-packages/dasbus/server/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/dasbus/server/__pycache__/container.cpython-36.opt-1.pyc

3

��^�@sTddlmZddlmZddlmZmZddgZGdd�de�Z	Gdd�de
�ZdS)	�)�
get_dbus_path)�Publishable)�ObjPath�List�DBusContainerError�
DBusContainerc@seZdZdZdS)rz,General exception for DBus container errors.N)�__name__�
__module__�__qualname__�__doc__�rr�/usr/lib/python3.6/container.pyrsc@s�eZdZdZddd�Zdd�Zed�dd	�Zed
�dd�Ze	ed
�dd�Z
e	ed
�dd�Zdd�Ze
d�dd�Zdd�Zdd�Zdd�ZdS)ra�The container of DBus objects.

    A DBus container should be used to dynamically publish Publishable
    objects within the same namespace. It generates a unique DBus path
    for each object. It is able to resolve a DBus path into an object
    and an object into a DBus path.

    Example:

    .. code-block:: python

        # Create a container of tasks.
        container = DBusContainer(
            namespace=("my", "project"),
            basename="Task",
            message_bus=DBus
        )

        # Publish a task.
        path = container.to_object_path(MyTask())

        # Resolve an object path into a task.
        task = container.from_object_path(path)

    NcCsD||_|r||f�}|dd�|_|d|_i|_t�|_d|_dS)z�Create a new container.

        :param message_bus: a message bus
        :param namespace: a sequence of names
        :param basename: a string with the base name
        N�r���r)�_message_bus�
_namespace�	_basename�
_container�set�
_published�_counter)�selfZmessage_bus�	namespace�basenamerrr
�__init__?s

zDBusContainer.__init__cCs
||_dS)z�Set the namespace.

        All DBus objects from the container should use the same
        namespace, so the namespace should be set up before any
        of the DBus objects are published.

        :param namespace: a sequence of names
        N)r)rrrrr
�
set_namespaceRs	zDBusContainer.set_namespace)�object_pathcCs
|j|�S)z�Convert a DBus path to a published object.

        If no published object is found for the given DBus path,
        raise DBusContainerError.

        :param object_path: a DBus path
        :return: a published object
        )�_find_object)rrrrr
�from_object_path]s	zDBusContainer.from_object_path)�returncCs<t|t�stdjt|�j���|j|�s2|j|�|j|�S)a4Convert a publishable object to a DBus path.

        If no DBus path is found for the given object, publish
        the object on the container message bus with a unique
        DBus path generated from the container namespace.

        :param obj: a publishable object
        :return: a DBus path
        zType '{}' is not publishable.)	�
isinstancer�	TypeError�format�typer�_is_object_published�_publish_object�_find_object_path)r�objrrr
�to_object_pathhs



zDBusContainer.to_object_path)�object_pathscCstt|j|��S)z�Convert DBus paths to published objects.

        :param object_paths: a list of DBus paths
        :return: a list of published objects
        )�list�mapr)rr)rrr
�from_object_path_list|sz#DBusContainer.from_object_path_listcCstt|j|��S)z�Convert publishable objects to DBus paths.

        :param objects: a list of publishable objects
        :return: a list of DBus paths
        )r*r+r()rZobjectsrrr
�to_object_path_list�sz!DBusContainer.to_object_path_listcCst|�|jkS)z�Is the given object published?

        :param obj: an object
        :return: True if the object is published, otherwise False
        )�idr)rr'rrr
r$�sz"DBusContainer._is_object_published)r'cCs8|j�}|jj||j��||j|<|jjt|��|S)zlPublish the given object.

        :param obj: an object to publish
        :return: an object path
        )�_generate_object_pathrZpublish_objectZfor_publicationrr�addr.)rr'rrrr
r%�s

zDBusContainer._publish_objectcCs0x"|jj�D]\}}||kr|SqWtd��dS)z�Find a DBus path of the object.

        :param obj: a published object
        :return: a DBus path
        :raise: DBusContainerError if no object path is found
        zNo object path found.N)r�itemsr)rr'rZ	found_objrrr
r&�s
zDBusContainer._find_object_pathcCs&||jkr|j|Stdj|���dS)z�Find an object by its DBus path.

        :param object_path: a DBus path
        :return: a published object
        :raise: DBusContainerError if no object is found
        zUnknown object path '{}'.N)rrr")rrrrr
r�s

zDBusContainer._find_objectcCs(|jd7_t|j|jt|j�f��S)zwGenerate a unique object path.

        This method is not thread safe.

        :return: a unique object path
        r)rrrr�str)rrrr
r/�s
z#DBusContainer._generate_object_path)N)rr	r
rrrrrr(rr,r-r$rr%r&rr/rrrr
r$s
N)Zdasbus.namespacerZdasbus.server.publishablerZ
dasbus.typingrr�__all__�	Exceptionr�objectrrrrr
�<module>s