
/Nc           @   s  d  d d d f Z  d Z d d l Z d d l Z d d l Z d d l Z y d d l Z Wn e k
 rw d d l Z n Xd d l	 Z	 d d l
 m Z m Z m Z m Z m Z m Z m Z d d l m Z m Z d d	 l m Z m Z m Z d d
 l m Z m Z m Z d d l m Z e j d  Z  d e! f d     YZ" d  e! f d     YZ# d   Z$ d   Z% d   Z& d e' f d     YZ( d e! f d     YZ) e!   Z* d e) f d     YZ+ d e+ f d     YZ, d S(   t   BusNamet   Objectt   methodt   signalt   restructuredtextiN(   t
   SessionBust	   Signaturet   Structt   validate_bus_namet   validate_object_patht   INTROSPECTABLE_IFACEt
   ObjectPath(   R   R   (   t   DBusExceptiont   NameExistsExceptiont   UnknownMethodException(   t   ErrorMessaget   MethodReturnMessaget   MethodCallMessage(   t
   LOCAL_PATHs   dbus.servicet   _VariantSignaturec           B   s    e  Z d  Z d   Z d   Z RS(   s   A fake method signature which, when iterated, yields an endless stream
    of 'v' characters representing variants (handy with zip()).

    It has no string representation.
    c         C   s   |  S(   s   Return self.(    (   t   self(    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   __iter__:   s    c         C   s   d S(   s   Return 'v' whenever called.t   v(    (   R   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   next>   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyR   4   s   	c           B   sV   e  Z d  Z d e e e d  Z d   Z d   Z d   Z d   Z	 d   Z
 e
 Z RS(   s^  A base class for exporting your own Named Services across the Bus.

    When instantiated, objects of this class attempt to claim the given
    well-known name on the given bus for the current process. The name is
    released when the BusName object becomes unreferenced.

    If a well-known name is requested multiple times, multiple references
    to the same BusName object will be returned.

    Caveats
    -------
    - Assumes that named services are only ever requested using this class -
      if you request names from the bus directly, confusion may occur.
    - Does not handle queueing.
    c   
   
   C   sS  t  | d t d t | d k rP d d l } | j d t d d t   } n  | | j k rj | j | S| ry t	 j
 p| d | r t	 j p d B| r t	 j p d B} | j | |  } | t	 j k r nX | t	 j k r nF | t	 j k r t |   n( | t	 j k rn t d	 | | f   t j |   }	 | |	 _ | |	 _ |	 | j | <|	 S(
   sS  Constructor, which may either return an existing cached object
        or a new object.

        :Parameters:
            `name` : str
                The well-known name to be advertised
            `bus` : dbus.Bus
                A Bus on which this service will be advertised.

                Omitting this parameter or setting it to None has been
                deprecated since version 0.82.1. For backwards compatibility,
                if this is done, the global shared connection to the session
                bus will be used.

            `allow_replacement` : bool
                If True, other processes trying to claim the same well-known
                name will take precedence over this one.
            `replace_existing` : bool
                If True, this process can take over the well-known name
                from other processes already holding it.
            `do_not_queue` : bool
                If True, this service will not be placed in the queue of
                services waiting for the requested name if another service
                already holds it.
        t   allow_well_knownt   allow_uniqueiNsK   Omitting the "bus" parameter to dbus.service.BusName.__init__ is deprecatedt
   stackleveli   i    s3   requesting bus name %s returned unexpected value %s(   R   t   Truet   Falset   Nonet   warningst   warnt   DeprecationWarningR   t
   _bus_namest   _dbus_bindingst   NAME_FLAG_ALLOW_REPLACEMENTt   NAME_FLAG_REPLACE_EXISTINGt   NAME_FLAG_DO_NOT_QUEUEt   request_namet    REQUEST_NAME_REPLY_PRIMARY_OWNERt   REQUEST_NAME_REPLY_IN_QUEUEt   REQUEST_NAME_REPLY_EXISTSR   t    REQUEST_NAME_REPLY_ALREADY_OWNERt   RuntimeErrort   objectt   __new__t   _bust   _name(
   t   clst   namet   bust   allow_replacementt   replace_existingt   do_not_queueR!   t
   name_flagst   retvalt   bus_name(    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyR0   R   s2    	%		c         O   s   d  S(   N(    (   R   t   argst   keywords(    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   __init__   s    c         C   s   |  j  j |  j  d  S(   N(   R1   t   release_nameR2   (   R   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   __del__   s    c         C   s   |  j  S(   s   Get the Bus this Service is on(   R1   (   R   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   get_bus   s    c         C   s   |  j  S(   s   Get the name of this service(   R2   (   R   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   get_name   s    c         C   s   d |  j  |  j t |   f S(   Ns&   <dbus.service.BusName %s on %r at %#x>(   R2   R1   t   id(   R   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   __repr__   s    N(   R   R   R   R    R   R0   R>   R@   RA   RB   RD   t   __str__(    (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyR    B   s   O					c      	   C   s  d } d } t } | r!x~|  j j D] } | r | | j k r d | j | j k r d | j | j k r | j | j | k r | } | j | } t } Pq q | } n  | r% | | j k r% d | j | j k r% d | j | j k r% | j | j | k r% | j | } t } Pq% q% Wnx xu |  j j D]g } | rS| | j k rS| } n  | r.| | j k r.d | j | j k r.| j | } t } Pq.q.W| r| j | | f S| rt d | | f   n t d |   d S(   s   Walks the Python MRO of the given class to find the method to invoke.

    Returns two methods, the one to call, and the one it inherits from which
    defines its D-Bus interface name, signature, and attributes.
    t   _dbus_is_methodt   _dbus_interfaces(   %s is not a valid method of interface %ss   %s is not a valid methodN(   R    R   t	   __class__t   __mro__t   __dict__RG   R   R   (   R   t   method_namet   dbus_interfacet   parent_methodt   candidate_classt
   successfulR3   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   _method_lookup   sF    		c         G   s   t  |  } y | j d | |  Wn t k
 r } t j   | d  k r y | j |  d } Wq t k
 r } t j d | | j	 |    q Xn  t j d | | | j	 |    n X|  j
 |  d  S(   Nt	   signatures
    (guessed)s2   Unable to guess signature for arguments %r: %s: %ss8   Unable to append %r to message with signature %s: %s: %s(   R   t   appendt	   Exceptiont   loggingt   basicConfigR    t   guess_signaturet   _loggert   errorRH   t   send_message(   t
   connectiont   messageRK   RQ   R:   t   replyt   e(    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   _method_reply_return   s     
	
	c   	      C   s  t  | d d   } | d  k	 r! nD t  | d d  d k rL d | j j } n d | j | j j f } t j   \ } } } t | t  r | j	 r | j
   } nK | | k r d j t j | | |   } n d j t j | j |   } t | | |  } |  j |  d  S(   Nt   _dbus_error_nameR   t    t   __main__s   org.freedesktop.DBus.Python.%ss!   org.freedesktop.DBus.Python.%s.%s(   R`   s   __main__(   t   getattrR    RH   R   R   t   syst   exc_infot
   isinstanceR   t   include_tracebackt   get_dbus_messaget   joint	   tracebackt   format_exceptiont   format_exception_onlyR   RY   (	   RZ   R[   t	   exceptionR4   t   ett   evt   etbt   contentsR\   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   _method_reply_error  s    !t   InterfaceTypec           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s  t  |  d i   } | |  _ i  } | |  j d | <xw | D]o } | j d | j } t  | d t  r; x@ | | j   D]+ \ } }	 | j | i   }
 |
 j |	  qx Wq; q; WxK | j   D]= } t  | d t  r | j | j	 i   }	 | |	 | j <q q Wt
 t |   j | | |  d  S(   Nt   _dbus_class_tablet   .RG   (   Rb   Rs   R   R   R   t	   iteritemst
   setdefaultt   updatet   valuesRG   t   superRr   R>   (   R3   R4   t   basest   dctt   class_tablet   interface_tablet   bt	   base_namet	   interfacet   method_tablet   our_method_tablet   func(    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyR>   *  s    	c         C   s   | j  } | j r* t t | j   } n	 t   } | j rN t | j  } n g  } d | j } x% t | |  D] } | d | 7} qq Wx | D] } | d | 7} q W| d 7} | S(   Ns       <method name="%s">
s2         <arg direction="in"  type="%s" name="%s" />
s(         <arg direction="out" type="%s" />
s       </method>
(   t
   _dbus_argst   _dbus_in_signaturet   tupleR   R   t   _dbus_out_signatureR   t   zip(   R3   R   R<   t   in_sigt   out_sigt   reflection_datat   pairt   type(    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   _reflect_on_methodD  s    				
c         C   sv   | j  } | j r* t t | j   } n	 t   } d | j } x% t | |  D] } | d | } qP W| d } | S(   Ns       <signal name="%s">
s"         <arg type="%s" name="%s" />
s       </signal>
(   R   t   _dbus_signatureR   R   R   R   R   (   R3   R   R<   t   sigR   R   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   _reflect_on_signala  s    			
(   R   R   R>   R   R   (    (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyRr   )  s   		t	   Interfacec           B   s   e  Z e Z RS(    (   R   R   Rr   t   __metaclass__(    (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyR   s  s   c        
   B   s   e  Z d  Z e Z e Z d d d d  Z e d    Z	 e d    Z
 e d    Z d   Z d d d  Z d   Z d   Z e e d	 d
 d d d d d d d    Z d   Z e Z RS(   s  A base class for exporting your own Objects across the Bus.

    Just inherit from Object and mark exported methods with the
    @\ `dbus.service.method` or @\ `dbus.service.signal` decorator.

    Example::

        class Example(dbus.service.object):
            def __init__(self, object_path):
                dbus.service.Object.__init__(self, dbus.SessionBus(), path)
                self._last_input = None

            @dbus.service.method(interface='com.example.Sample',
                                 in_signature='v', out_signature='s')
            def StringifyVariant(self, var):
                self.LastInputChanged(var)      # emits the signal
                return str(var)

            @dbus.service.signal(interface='com.example.Sample',
                                 signature='v')
            def LastInputChanged(self, var):
                # run just before the signal is actually emitted
                # just put "pass" if nothing should happen
                self._last_input = var

            @dbus.service.method(interface='com.example.Sample',
                                 in_signature='', out_signature='v')
            def GetLastInput(self):
                return self._last_input
    c         C   s   | d k	 r t |  n  t | t  r= | } | j   } n* | d k rg | d k	 rg | j   } qg n  d |  _ d |  _ g  |  _ t j	   |  _
 t |  _ | |  _ | d k r | d k	 r t d   n  | d k	 r | d k	 r |  j | |  n  d S(   s  Constructor. Either conn or bus_name is required; object_path
        is also required.

        :Parameters:
            `conn` : dbus.connection.Connection or None
                The connection on which to export this object.

                If None, use the Bus associated with the given ``bus_name``.
                If there is no ``bus_name`` either, the object is not
                initially available on any Connection.

                For backwards compatibility, if an instance of
                dbus.service.BusName is passed as the first parameter,
                this is equivalent to passing its associated Bus as
                ``conn``, and passing the BusName itself as ``bus_name``.

            `object_path` : str or None
                A D-Bus object path at which to make this Object available
                immediately. If this is not None, a `conn` or `bus_name` must
                also be provided.

            `bus_name` : dbus.service.BusName or None
                Represents a well-known name claimed by this process. A
                reference to the BusName object will be held by this
                Object, preventing the name from being released during this
                Object's lifetime (unless it's released manually).
        s<   If object_path is given, either conn or bus_name is requiredN(   R    R	   Re   R    RA   t   _object_patht   _connectiont
   _locationst   threadt   allocate_lockt   _locations_lockR   t	   _fallbackR2   t	   TypeErrort   add_to_connection(   R   t   connt   object_pathR;   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyR>     s$    					c         C   sO   |  j  t k r" t d |    n) |  j  d k rD t d |    n |  j  Sd S(   s   The object-path at which this object is available.
        Access raises AttributeError if there is no object path, or more than
        one object path.

        Changed in 0.82.0: AttributeError can be raised.
        sE   Object %r has more than one object path: use Object.locations insteads    Object %r has no object path yetN(   R   t   _MANYt   AttributeErrorR    (   R   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   __dbus_object_path__  s    c         C   sO   |  j  t k r" t d |    n) |  j  d k rD t d |    n |  j  Sd S(   s   The Connection on which this object is available.
        Access raises AttributeError if there is no Connection, or more than
        one Connection.

        Changed in 0.82.0: AttributeError can be raised.
        sF   Object %r is on more than one Connection: use Object.locations insteads   Object %r has no Connection yetN(   R   R   R   R    (   R   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyRZ     s    c         C   s   t  |  j  S(   se  An iterable over tuples representing locations at which this
        object is available.

        Each tuple has at least two items, but may have more in future
        versions of dbus-python, so do not rely on their exact length.
        The first two items are the dbus.connection.Connection and the object
        path.

        :Since: 0.82.0
        (   t   iterR   (   R   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt	   locations  s    c      	   C   st  | t  k r t d t    n  |  j j   z3|  j d k	 rs |  j | k	 rs |  j rs t d |  |  j f   n  |  j d k	 r |  j r |  j | k r t d |  |  j f   n  | j	 | |  j
 |  j |  j  |  j d k r | |  _ n |  j | k	 rt |  _ n  |  j d k r'| |  _ n |  j | k rBt |  _ n  |  j j | | |  j f  Wd |  j j   Xd S(   sN  Make this object accessible via the given D-Bus connection and
        object path.

        :Parameters:
            `connection` : dbus.connection.Connection
                Export the object on this connection. If the class attribute
                SUPPORTS_MULTIPLE_CONNECTIONS is False (default), this object
                can only be made available on one connection; if the class
                attribute is set True by a subclass, the object can be made
                available on more than one connection.

            `path` : dbus.ObjectPath or other str
                Place the object at this object path. If the class attribute
                SUPPORTS_MULTIPLE_OBJECT_PATHS is False (default), this object
                can only be made available at one object path; if the class
                attribute is set True by a subclass, the object can be made
                available with more than one object path.

        :Raises ValueError: if the object's class attributes do not allow the
            object to be exported in the desired way.
        :Since: 0.82.0
        s3   Objects may not be exported on the reserved path %ss'   %r is already exported on connection %rs(   %r is already exported at object path %sN(   R   t
   ValueErrorR   t   acquireR   R    t   SUPPORTS_MULTIPLE_CONNECTIONSR   t   SUPPORTS_MULTIPLE_OBJECT_PATHSt   _register_object_patht   _message_cbt   _unregister_cbR   R   R   RR   t   release(   R   RZ   t   path(    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyR     s8    


 c         C   sz  |  j  j   zX|  j d k s. |  j d k rA t d |    n  | d k	 sY | d k	 r g  } xn |  j D]N } | d k s | d | k ri | d k s | d | k ri | j |  qi qi Wn |  j } g  |  _ | s t d |  | | f   n  xo | D]g } y | d j | d  Wn t k
 r+n X|  j r y |  j j	 |  Wq`t
 k
 r\q`Xq q WWd |  j  j   Xd S(   s  Make this object inaccessible via the given D-Bus connection
        and object path. If no connection or path is specified,
        the object ceases to be accessible via any connection or path.

        :Parameters:
            `connection` : dbus.connection.Connection or None
                Only remove the object from this Connection. If None,
                remove from all Connections on which it's exported.
            `path` : dbus.ObjectPath or other str, or None
                Only remove the object from this object path. If None,
                remove from all object paths.
        :Raises LookupError:
            if the object was not exported on the requested connection
            or path, or (if both are None) was not exported at all.
        :Since: 0.81.1
        s   %r is not exportedi    i   s1   %r is not exported at a location matching (%r,%r)N(   R   R   R   R    R   t   LookupErrorR   RR   t   _unregister_object_patht   removeR   R   (   R   RZ   R   t   droppedt   location(    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   remove_from_connectionK  s4    			c         C   s   t  j d |  |  d  S(   Ns5   Unregistering exported object %r from some path on %r(   RW   t   info(   R   RZ   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyR   |  s    	c            sy  t    t  s d  Sy<  j      j   } t |   |  \ } }   j | j   } i  } | j d  k	 r t	 | j   n d   | j
 r | j
 \ } }	      f d   | | <   f d   | |	 <n  | j r   j   | | j <n  | j r  j   | | j <n  | j r  j   }
 |
 } x |  j D] } | d  k r5|
 | d k red } Pn  | d d k r{q5n  |
 j | d d  r|
 t | d  } t |  t |  k  r| } qqq5q5Wt |  } | | | j <n  | j r  j   | | j <n  | j r%  | | j <n  | j r> | | j <n  | |  | |  } | j
 r]d  S d  k	 rt   } t |  d k r| d  k rd } qt d    q8t |  d k r| f } q8t j |  rq8t d   f   n@ | d  k rd	 } n+ t  | t  r/t  | t  r/n	 | f } t      |  Wn# t k
 rt} t    |  n Xd  S(
   Nc             s   t       |   S(   N(   R^   (   R:   (   RK   RZ   RQ   R[   (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   <lambda>  s    c            s   t     |   S(   N(   Rq   (   Rl   (   R[   RZ   (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyR     s    i    i   t   /s8   %s has an empty output signature but did not return NonesK   %s has multiple output values in signature %s but did not return a sequence(    (    (    Re   R   t
   get_membert   get_interfaceRP   t   get_args_listt   _dbus_get_args_optionsR   R    R   t   _dbus_async_callbackst   _dbus_sender_keywordt
   get_sendert   _dbus_path_keywordt   get_patht   _dbus_rel_path_keywordR   t
   startswitht   lenR   t   _dbus_destination_keywordt   get_destinationt   _dbus_message_keywordt   _dbus_connection_keywordR   R   t   operatort   isSequenceTypeR   R^   RS   Rq   (   R   RZ   R[   t   interface_namet   candidate_methodRM   R<   R=   t   return_callbackt   error_callbackR   t   rel_patht   expt   suffixR:   t   signature_tupleRl   (    (   R[   RK   RZ   RQ   s0   /usr/lib/python2.7/dist-packages/dbus/service.pyR     s    											t   in_signatureR`   t   out_signaturet   st   path_keywordR   t   connection_keywordRZ   c         C   s  t  j } | d | 7} |  j |  j j d |  j j } x | j   D] \ } } | d | 7} xj | j   D]\ } t | d t	  r | |  j j
 |  7} ql t | d t	  rl | |  j j |  7} ql ql W| d 7} qE Wx% | j |  D] } | d | 7} q W| d 7} | S(	   si   Return a string of XML encoding this object's supported interfaces,
        methods and signals.
        s   <node name="%s">
Rt   s     <interface name="%s">
RF   t   _dbus_is_signals     </interface>
s     <node name="%s"/>
s   </node>
(   R%   t)   DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODERs   RH   R   R   Ru   Rx   Rb   R   R   R   t   list_exported_child_objects(   R   R   RZ   R   t
   interfacesR4   t   funcsR   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt
   Introspect  s    	!
c         C   sZ   d } |  j  t k	 r4 |  j  d  k	 r4 d |  j  } n  d |  j j |  j j | t |   f S(   NR`   s    at %ss   <%s.%s%s at %#x>(   R   R   R    RH   R   R   RC   (   R   t   where(    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyRD   
  s    N(   R   R   R   R   R   R   R    R>   t   propertyR   RZ   R   R   R   R   R   R   R
   R   RD   RE   (    (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyR   z  s   =	;1		m	t   FallbackObjectc           B   s#   e  Z d  Z e Z d d d  Z RS(   sa   An object that implements an entire subtree of the object-path
    tree.

    :Since: 0.82.0
    c         C   su   t  t |   j   t |  _ | d k rF | d k	 rq t d   qq n+ | d k ra t d   n |  j | |  d S(   sH  Constructor.

        Note that the superclass' ``bus_name`` __init__ argument is not
        supported here.

        :Parameters:
            `conn` : dbus.connection.Connection or None
                The connection on which to export this object. If this is not
                None, an `object_path` must also be provided.

                If None, the object is not initially available on any
                Connection.

            `object_path` : str or None
                A D-Bus object path at which to make this Object available
                immediately. If this is not None, a `conn` must also be
                provided.

                This object will implements all object-paths in the subtree
                starting at this object-path, except where a more specific
                object has been added.
        s)   If object_path is given, conn is requireds)   If conn is given, object_path is requiredN(   Ry   R   R>   R   R   R    R   R   (   R   R   R   (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyR>     s    	N(   R   R   R   R   R   R    R>   (    (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyR     s   (-   t   __all__t   __docformat__Rc   RT   R   Ri   R   t   ImportErrort   dummy_threadR%   t   dbusR   R   R   R   R	   R
   R   t   dbus.decoratorsR   R   t   dbus.exceptionsR   R   R   t   dbus.lowlevelR   R   R   t   dbus.proxiesR   t	   getLoggerRW   R/   R   R    RP   R^   Rq   R   Rr   R   R   R   R   (    (    (    s0   /usr/lib/python2.7/dist-packages/dbus/service.pyt   <module>   s6   4u	B		J	 