관리-도구
편집 파일: container.cpython-39.pyc
a ����װ_����������������������@���sT���d�dl�mZ�d�dlmZ�d�dlmZmZ�ddgZG�dd��de�Z G�dd��de �ZdS�) �����)� get_dbus_path)�Publishable)�ObjPath�List�DBusContainerError� DBusContainerc�������������������@���s���e�Zd�ZdZdS�)r���z,General exception for DBus container errors.N)�__name__� __module__�__qualname__�__doc__��r���r����;/usr/lib/python3.9/site-packages/dasbus/server/container.pyr������s���c�������������������@���s����e�Zd�ZdZddd�Zdd��Zed�dd �Zed �dd�Ze e�d �dd�Z e e�d �dd�Zdd��Ze d�dd�Zdd��Zdd��Zdd��ZdS�)r���a���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) Nc�����������������C���sH���||�_�|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__c�����������������C���s ���||�_�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���)r���r���r���r���r ���� set_namespaceR���s���� zDBusContainer.set_namespace)�object_pathc�����������������C���s ���|���|�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�r���r���r���r���r ����from_object_path]���s���� zDBusContainer.from_object_path)�returnc�����������������C���s<���t�|t�std�t|�j���|��|�s2|��|��|��|�S�)a4��Convert 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_pathh���s���� � zDBusContainer.to_object_path)�object_pathsc�����������������C���s���t�t|�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���)r���r*���r���r���r ����from_object_path_list|���s����z#DBusContainer.from_object_path_listc�����������������C���s���t�t|�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)���)r���Zobjectsr���r���r ����to_object_path_list����s����z!DBusContainer.to_object_path_listc�����������������C���s���t�|�|�jv�S�)z�Is the given object published? :param obj: an object :return: True if the object is published, otherwise False )�idr���r'���r���r���r ���r$�������s����z"DBusContainer._is_object_published)r(���c�����������������C���s8���|�����}|�j�||�����||�j|<�|�j�t|���|S�)zlPublish the given object. :param obj: an object to publish :return: an object path )�_generate_object_pathr���Zpublish_objectZfor_publicationr���r����addr/���)r���r(���r���r���r���r ���r%�������s����� zDBusContainer._publish_objectc�����������������C���s0���|�j����D�]\}}||u�r |��S�q 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���)r���r(���r���Z found_objr���r���r ���r&�������s���� �zDBusContainer._find_object_pathc�����������������C���s&���||�j�v�r|�j�|�S�td�|���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)r���r���r"���r���r���r���r ���r�������s ���� �zDBusContainer._find_objectc�����������������C���s.���|��j�d7��_�tg�|�j�|�j�t|�j���R���S�)zwGenerate a unique object path. This method is not thread safe. :return: a unique object path ����)r���r���r���r����str)r���r���r���r ���r0�������s�������z#DBusContainer._generate_object_path)N)r���r ���r ���r���r���r���r���r���r)���r���r-���r.���r$���r���r%���r&���r���r0���r���r���r���r ���r���$���s��� N)Zdasbus.namespacer���Zdasbus.server.publishabler���Z dasbus.typingr���r����__all__� Exceptionr����objectr���r���r���r���r ����<module>���s����