HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/dasbus/server/__pycache__/container.cpython-39.pyc
a

װ_�@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.9/site-packages/dasbus/server/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)

    NcCsH||_|rg|�|�R}|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)�_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
|�|�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�std�t|�j���|�|�s2|�|�|�|�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|�|jvS)z�Is the given object published?

        :param obj: an object
        :return: True if the object is published, otherwise False
        )�idrr'rrr
r$�sz"DBusContainer._is_object_published)r(cCs8|��}|j�||���||j|<|j�t|��|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_objectcCs0|j��D]\}}||ur
|Sq
td��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&||jvr|j|Std�|���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"rrrr
r�s


�zDBusContainer._find_objectcCs.|jd7_tg|j�|j�t|j��R�S)zwGenerate a unique object path.

        This method is not thread safe.

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