a F `@sTddlmZddlmZddlmZmZddgZGdddeZ Gddde Z dS) ) get_dbus_path) Publishable)ObjPathListDBusContainerError 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@seZdZdZdddZddZeddd Zed d d Ze ed ddZ e ed ddZ ddZ e dddZddZddZddZdS)raThe 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)zCreate a new container. :param message_bus: a message bus :param namespace: a sequence of names :param basename: a string with the base name Nr) _message_bus _namespace _basename _containerset _published_counter)selfZ message_bus namespacebasenamer r r __init__?s zDBusContainer.__init__cCs ||_dS)zSet 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)zConvert 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_objectrrr r r from_object_path]s zDBusContainer.from_object_path)returncCs<t|tstdt|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 TypeErrorformattyper_is_object_published_publish_object_find_object_pathrobjr r r to_object_pathhs   zDBusContainer.to_object_path) object_pathscCstt|j|S)zConvert DBus paths to published objects. :param object_paths: a list of DBus paths :return: a list of published objects )listmapr)rr*r r r from_object_path_list|sz#DBusContainer.from_object_path_listcCstt|j|S)zConvert 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_listsz!DBusContainer.to_object_path_listcCst||jvS)zIs 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|<|jt||S)zlPublish the given object. :param obj: an object to publish :return: an object path )_generate_object_pathrZpublish_objectZfor_publicationrraddr/)rr(rr r r r%s zDBusContainer._publish_objectcCs0|jD]\}}||ur |Sq tddS)zFind 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)ritemsr)rr(rZ found_objr r r r&s  zDBusContainer._find_object_pathcCs&||jvr|j|Std|dS)zFind 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 rs   zDBusContainer._find_objectcCs.|jd7_tg|j|jt|jRS)zwGenerate a unique object path. This method is not thread safe. :return: a unique object path )rrrrstr)rr r r r0sz#DBusContainer._generate_object_path)N)rr r r rrrrr)rr-r.r$rr%r&rr0r r r r r$s   N) Zdasbus.namespacerZdasbus.server.publishablerZ dasbus.typingrr__all__ Exceptionrobjectrr r r r s