Ë
    ^žìM)  ã                   óL   — d Z dZdZddlmZ ddlZddlZddlmZm	Z	m
Z
 d„ Zd	„ Zy)
z%Utils for using deferreds with D-Bus.z%Sebastian Heinlein <devel@glatzor.de>)Údbus_deferred_methodÚ	deferableé    ©ÚwrapsNé   )ÚdeferÚDeferredÚDeferredExceptionc                  ó   ‡ ‡— ˆ ˆfd„}|S )a¦  Export the decorated method on the D-Bus and handle a maybe
    returned Deferred.

    This decorator can be applied to methods in the same way as the
    @dbus.service.method method, but it correctly handles the case where
    the method returns a Deferred.

    This decorator was kindly taken from James Henstridge blog post and
    adopted:
    http://blogs.gnome.org/jamesh/2009/07/06/watching-iview-with-rygel/
    c                 óˆ   •‡ —  t        j                  j                  ‰i ‰¤Ž‰ «      Š t        ‰ «      ˆ fd„«       }d|_        |S )Nc                  óÀ   •‡‡— ˆfd„}|j                  d«      Š|j                  d«      Št        ‰g| ¢­i |¤Ž}|j                  |«       |j                  ˆfd„«       y )Nc                  ó*   •— | dk(  r ‰«        y  ‰| Ž  y )N©N© )Úcb_argsÚdbus_callbacks    €ú-/usr/lib/python3/dist-packages/defer/utils.pyÚignore_none_callbackzVdbus_deferred_method.<locals>.decorator.<locals>.wrapper.<locals>.ignore_none_callback5   s   ø€ ð ˜gÒ%Ù!•Oá! 7Ò+ó    Ú_dbus_callbackÚ_dbus_errbackc                 ó(   •—  ‰| j                   «      S r   )Úvalue)ÚerrorÚdbus_errbacks    €r   ú<lambda>zJdbus_deferred_method.<locals>.decorator.<locals>.wrapper.<locals>.<lambda>@   s   ø€ ©|¸E¿K¹KÓ/H€ r   )Úpopr   Úadd_callbackÚadd_errback)ÚargsÚkwargsr   Údeferredr   r   Úfunctions       @@€r   Úwrapperz8dbus_deferred_method.<locals>.decorator.<locals>.wrapper3   sY   ú€ ô,ð #ŸJ™JÐ'7Ó8ˆMØ!Ÿ:™: oÓ6ˆLÜ˜XÐ7¨Ò7°Ñ7ˆHØ×!Ñ!Ð"6Ô7Ø× Ñ Ó!HÕIr   )r   r   )ÚdbusÚserviceÚmethodr   Ú_dbus_async_callbacks)r#   r$   r    r!   s   ` €€r   Ú	decoratorz'dbus_deferred_method.<locals>.decorator1   sK   ù€ Ø7”4—<‘<×&Ñ&¨Ð7°Ñ7¸ÓAˆÜ	ˆx‹ó	Jó 
ð	Jð  )LˆÔ%Øˆr   r   )r    r!   r)   s   `` r   r   r   %   s   ù€ õð* Ðr   c                 ó.   ‡ — t        ‰ «      ˆ fd„«       }|S )a:  Add a defer attribute to the decorated function and return a Deferred
    object. The callback of the Deferred will be passed as reply_handler
    argument and the errback as the error_handler argument to the decorated
    function.

    This decorator allows to easily make use of Deferreds in a DBus client.
    c                  ó   •‡‡— d„ Š	 |j                  d«      }|r,t        «       Š‰j                  |d<   ˆˆfd„|d	<    ‰| i |¤Ž ‰S  ‰| i |¤ŽS # t        $ r5 t        j                  «       }	 |d   d   dk(  }n# t        $ r d}Y nw xY wY Œsw xY w)
Nc                 ó|   — t        | t        «      r|j                  | «       y |j                  t        | «      «       y r   )Ú
isinstancer
   Úerrback)r   r"   s     r   Úon_errorz/deferable.<locals>._deferable.<locals>.on_errorR   s/   € ä˜%Ô!2Ô3Ø× Ñ  Õ'à× Ñ Ô!2°5Ó!9Õ:r   r   é   é   Ú_inline_callbacksFÚreply_handlerc                 ó   •—  ‰| ‰«      S r   r   )Úerrr"   r/   s    €€r   r   z/deferable.<locals>._deferable.<locals>.<lambda>h   s   ø€ ±(¸3ÀÓ2I€ r   Úerror_handler)r   ÚKeyErrorÚinspectÚstackÚ
IndexErrorr	   Úcallback)r    r!   Úto_deferr9   r"   r/   Úfuncs       @@€r   Ú
_deferablezdeferable.<locals>._deferableP   s­   ú€ ò	;ð
	!à—z‘z 'Ó*ˆHñ Ü“zˆHØ&.×&7Ñ&7ˆF�?Ñ#Ü&IˆF�?Ñ#Ù�$Ð!˜&Ò!ØˆOÙ�TÐ$˜VÑ$Ð$øô ò 	!ô —M‘M“OˆEð!Ø  ™8 A™;Ð*=Ñ=‘øÜò !Ø ’ð!üð	!ús5   ˆA ÁBÁ-A9Á8BÁ9BÂBÂBÂBÂBr   )r=   r>   s   ` r   r   r   H   s#   ø€ ô ˆ4ƒ[ó%ó ð%ð6 Ðr   )Ú__doc__Ú
__author__Ú__all__Ú	functoolsr   r8   r%   Ú r   r	   r
   r   r   r   r   r   ú<module>rD      s0   ðñ ,ð, 6€
à
/€å Û ã ç 0Ñ 0ò!óF$r   