+
    ic  c                   sb    ^ RI Ht ^ RIHt ^ RIHtHt RR.t ! R R]4      t	 ! R R]
4      tR# )	i    )get_dbus_pathPublishable)ObjPathListDBusContainerErrorDBusContainerc                   s    ] tR t^tRtRtR# )r   z,General exception for DBus container errors. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       </usr/lib/python3.14/site-packages/dasbus/server/container.pyr   r      s    6r   c                   s   a  ] tR t^$t o RtRR ltR tV 3R lR ltV 3R lR ltV 3R	 lR
 lt	V 3R lR lt
R tV 3R lR ltR tR tR tRtV tR# )r   ag  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                s    Wn         V'       d   . VOVN5pVRR V n        VR,          V n        / V n        \	        4       V n        ^ V n        R# )zCreate a new container.

:param message_bus: a message bus
:param namespace: a sequence of names
:param basename: a string with the base name
Ni)_message_bus
_namespace	_basename
_containerZset
_published_counter)selfZmessage_bus	namespaceZbasenames   &&&&r   __init__ZDBusContainer.__init__?   sK     (.).X.I#CR."2%r   c                s    Wn         R# )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   )r   r      &&r   set_namespaceZDBusContainer.set_namespaceR   s	     $r   c                    < V ^8  d   QhRS[ /# )   object_pathr   format__classdict__   "r   __annotate__DBusContainer.__annotate__]   s     	. 	.G 	.r   c                s$    V P                  V4      # )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_objectr   r   r   r   from_object_pathZDBusContainer.from_object_path]   s       --r   c                r   r   Zreturnr   r   r"   r   r#   r$   h   s     + +W +r   c                s    \        V\        4      '       g.   \        RP                  \	        V4      P
                  4      4      hV P                  V4      '       g   V P                  V4       V P                  V4      # )a  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
zType '{}' is not publishable.)	Z
isinstancer   Z	TypeErrorr    Ztyper   _is_object_published_publish_object_find_object_pathr   objr   r   to_object_pathZDBusContainer.to_object_pathh   sh     #{++/66tCy7I7IJ  ((--  %%%c**r   c                0   < V ^8  d   QhRS[ S[,          /# )r   object_pathsr   r   r   r"   r   r#   r$   |   s     > >$w- >r   c                @    \        \        V P                  V4      4      # )zyConvert DBus paths to published objects.

:param object_paths: a list of DBus paths
:return: a list of published objects
)listmapr'   )r   r0   r   r   from_object_path_listZ#DBusContainer.from_object_path_list|   s     C--|<==r   c                r/   r(   r1   r   r"   r   r#   r$      s     7 7d7m 7r   c                r2   )zxConvert publishable objects to DBus paths.

:param objects: a list of publishable objects
:return: a list of DBus paths
)r3   r4   r.   )r   Zobjectsr   r   to_object_path_listZ!DBusContainer.to_object_path_list   s     C++W566r   c                s2    \        V4      V P                  9   # )zpIs the given object published?

:param obj: an object
:return: True if the object is published, otherwise False
)idr   r,   r   r   r)   Z"DBusContainer._is_object_published   s     #w$//))r   c                r   )r   r-   r   r   r"   r   r#   r$      s      ; r   c                s    V P                  4       pV P                  P                  VVP                  4       4       WP                  V&   V P
                  P                  \        V4      4       V# )zTPublish the given object.

:param obj: an object to publish
:return: an object path
)_generate_object_pathr   Zpublish_objectZfor_publicationr   r   Zaddr7   )r   r-   r   s   && r   r*   ZDBusContainer._publish_object   s_     002((!	

 (+$BsG$r   c                sp    V P                   P                  4        F  w  r#W1J g   K  Vu # 	  \        R4      h)zFind a DBus path of the object.

:param obj: a published object
:return: a DBus path
:raise: DBusContainerError if no object path is found
zNo object path found.)r   Zitemsr   )r   r-   r   Z	found_objs   &&  r   r+   ZDBusContainer._find_object_path   s<     '+oo&;&;&="K"" '> !#
 	
r   c                s|    WP                   9   d   V P                   V,          # \        RP                  V4      4      h)zFind an object by its DBus path.

:param object_path: a DBus path
:return: a published object
:raise: DBusContainerError if no object is found
zUnknown object path '{}'.)r   r   r    r&   r   r   r%   ZDBusContainer._find_object   s8     //)??;// '..{;
 	
r   c                s    V ;P                   ^,          un         \        . V P                  OV P                  N\	        V P                   4      N5!  # )z_Generate a unique object path.

This method is not thread safe.

:return: a unique object path
)r   r    r   r   Zstr)r   s   &r   r8   Z#DBusContainer._generate_object_path   sJ     	 
__
NN
 
 	
r   )r   r   r   r   r   r   )N)r   r	   r
   r   r   r   r   r'   r.   r5   r6   r)   r*   r+   r%   r8   r   Z__classdictcell__)r!   s   @r   r   r   $   s_     4&	$	. 	.+ +(> >7 7* "


 
r   N)Zdasbus.namespacer    Zdasbus.server.publishabler   Zdasbus.typingr   r   Z__all__Z	Exceptionr   Zobjectr   r   r   r   <module>r9      s9   * + 1 ' 	 	
k
F k
r   