3 iRV}l@sdZdZddlZddlZddlZddlmZmZm Z m Z m Z m Z m Z ddlmZddlmZmZmZmZmZddlmZdd lmZmZerdd lmZn dd lmZejd Zd dZGddde Z!GdddeZdS) Connection SignalMatchZreStructuredTextN)r LOCAL_IFACE LOCAL_PATHvalidate_bus_namevalidate_interface_namevalidate_member_namevalidate_object_path) DBusException) ErrorMessageHANDLER_RESULT_NOT_YET_HANDLEDMethodCallMessageMethodReturnMessage SignalMessage) ProxyObject)is_py2is_py3)String) UTF8Stringzdbus.connectioncOsdS)N)argskwargsrr"/usr/lib64/python3.6/connection.py_noop1src@seZdZddddddddd d d d d ddddgZerszSignalMatch.cCs|jdkrdg}|jdk r*|jd|j|jdk rD|jd|j|jdk r^|jd|j|jdk rx|jd|j|jdk rx(|jjD]\}}|jd||fqWdj||_|jS)Nz type='signal'z sender='%s'z path='%s'zinterface='%s'z member='%s'z arg%d='%s',) r!rappendrrrr*itemsjoin)r7Zruler?valuerrr__str__s       zSignalMatch.__str__cCsd|jt||j|jfS)Nz<%s at %x "%s" on conn %r>) __class__rBr!r#)r7rrr__repr__szSignalMatch.__repr__cCs ||_dS)N)r)r7new_namerrrset_sender_name_ownersz!SignalMatch.set_sender_name_ownercKs\|d|jfkrdS||jkr dS||jkr.dS||jkrr,z&Exception in handler for D-Bus signal:)exc_info) rZ get_senderr*dictrrrr get_args_listrJlen isinstancer get_memberr get_interfacerget_pathr+r"r(r$Zget_destinationr)r'r%r&rlogging basicConfig_loggererror)r7messagerrZarg_typer?rLr,rrrmaybe_handle_messagesZ                 z SignalMatch.maybe_handle_messagecCs4|j}|dk r0|j||j|j|j|jf|jdS)N)r#remove_signal_receiverrrrrr )r7r8rrrremoves  zSignalMatch.remove)FNNNNNN)__name__ __module__ __qualname__Z_slotsrrItuple __slots__r@rCrErFpropertyr9rMrOrQrRrarcrrrrr5s.   7 :cs~eZdZdZeZfddZddZddd Zdd d Z d d Z dddZ ddZ ddZ d ddZd"ddZddZZS)#rzzA connection to another application. In this base class there is assumed to be no bus daemon. :Since: 0.81.0 csJtt|j||t|dsFd|_g|_i|_tj|_ |j |j j dS)N_dbus_Connection_initializedrS) superrr@hasattrrj"_Connection__call_on_disconnection!_signal_recipients_by_object_path threadingZLock _signals_lockZadd_message_filterrN _signal_func)r7rr)rNrrr@s  zConnection.__init__cCs|S)aReturn the unique name for the given bus name, activating it if necessary and possible. If the name is already unique or this connection is not to a bus daemon, just return it. :Returns: a bus name. If the given `bus_name` exists, the returned name identifies its current owner; otherwise the returned name does not exist. :Raises DBusException: if the implementation has failed to activate the given bus name. :Since: 0.81.0 r)r7bus_namerrractivate_name_ownerszConnection.activate_name_ownerNTcKsn|jdd}|dk rB|dk r$tdddlm}|dtdd|}|r\td d j|j|j||||d S) aReturn a local proxy for the given remote object. Method calls on the proxy are translated into method calls on the remote object. :Parameters: `bus_name` : str A bus name (either the unique name or a well-known name) of the application owning the object. The keyword argument named_service is a deprecated alias for this. `object_path` : str The object path of the desired object `introspect` : bool If true (default), attempt to introspect the remote object to find out supported methods and their signatures :Returns: a `dbus.proxies.ProxyObject` named_serviceNz3bus_name and named_service cannot both be specifiedr)warnziPassing the named_service parameter to get_object by name is deprecated: please use positional parameters) stacklevelz4get_object does not take these keyword arguments: %sz, ) introspect)r2r3warningsruDeprecationWarningrKkeysProxyObjectClass)r7rrr:rxrrtrurrr get_object$s    zConnection.get_objectc Ks|j|jdd}|dk rJ|dk r,td|}ddlm}|dtddt||||||f|} |jjz4|j j |i} | j |i} | j |g} | j | Wd|jj X| S) aArrange for the given function to be called when a signal matching the parameters is received. :Parameters: `handler_function` : callable The function to be called. Its positional arguments will be the arguments of the signal. By default it will receive no keyword arguments, but see the description of the optional keyword arguments below. `signal_name` : str The signal name; None (the default) matches all names `dbus_interface` : str The D-Bus interface name with which to qualify the signal; None (the default) matches all interface names `bus_name` : str A bus name for the sender, which will be resolved to a unique name if it is not already; None (the default) matches any sender. `path` : str The object path of the object which must have emitted the signal; None (the default) matches any object path :Keywords: `utf8_strings` : bool If True, the handler function will receive any string arguments as dbus.UTF8String objects (a subclass of str guaranteed to be UTF-8). If False (default) it will receive any string arguments as dbus.String objects (a subclass of unicode). `byte_arrays` : bool If True, the handler function will receive any byte-array arguments as dbus.ByteArray objects (a subclass of str). If False (default) it will receive any byte-array arguments as a dbus.Array of dbus.Byte (subclasses of: a list of ints). `sender_keyword` : str If not None (the default), the handler function will receive the unique name of the sending endpoint as a keyword argument with this name. `destination_keyword` : str If not None (the default), the handler function will receive the bus name of the destination (or None if the signal is a broadcast, as is usual) as a keyword argument with this name. `interface_keyword` : str If not None (the default), the handler function will receive the signal interface as a keyword argument with this name. `member_keyword` : str If not None (the default), the handler function will receive the signal name as a keyword argument with this name. `path_keyword` : str If not None (the default), the handler function will receive the object-path of the sending object as a keyword argument with this name. `message_keyword` : str If not None (the default), the handler function will receive the `dbus.lowlevel.SignalMessage` as a keyword argument with this name. `arg...` : unicode or UTF-8 str If there are additional keyword parameters of the form ``arg``\ *n*, match only signals where the *n*\ th argument is the value given for that keyword parameter. As of this time only string arguments can be matched (in particular, object paths and signatures can't). `named_service` : str A deprecated alias for `bus_name`. rtNz3bus_name and named_service cannot both be specifiedr)ruzrPassing the named_service parameter to add_signal_receiver by name is deprecated: please use positional parametersrv)rw) Z_require_main_loopr2r3ryrurzrrpacquirern setdefaultrIrelease) r7Zhandler_function signal_namer;rrpathkeywordsrtrumatch by_interface by_membermatchesrrradd_signal_receiverIs(G         zConnection.add_signal_receiverc cs|dk rd|f}nd}|dk r(d|f}nd}|dk r>d|f}nd}x~|D]v}|jj|}|dkrbqHxZ|D]R}|j|d}|dkrqhx6|D].}|j|d} | dkrqx| D] } | VqWqWqhWqHWdS)N)N)N)N)rnget) r7rr;r<Z path_keysZinterface_keysZ member_keysrrrmrrr_iter_easy_matchess.          zConnection._iter_easy_matchesc Ks>|jdd}|dk rB|dk r$td|}ddlm}|dtddg} g} |jjz|jj|d} | dkrpdS| j|d} | dkrdS| j|d} | dkrdSx@| D]8}||ks|j |||||f|r| j |q| j |qW| r| | |<n | |=| s| |=| s|j|=Wd|jj Xx| D]}|j |q&WdS)Nrtz3bus_name and named_service cannot both be specifiedr)ruzuPassing the named_service parameter to remove_signal_receiver by name is deprecated: please use positional parametersrv)rw) r2r3ryrurzrpr~rnrrRrIr_clean_up_signal_match)r7Zhandler_or_matchrr;rrrrrtrunewZ deletionsrrrrrrrrbsT            z!Connection.remove_signal_receivercCsdS)Nr)r7rrrrrsz!Connection._clean_up_signal_matchc Cst|tstS|j}|j}|j}x |j|||D]}|j|q6W|tkr|t kr|dkrxF|j D]<}y ||Wqht k rt j tjdddYqhXqhWtS)zvD-Bus filter function. Handle signals by dispatching to Python callbacks kept in the match-rule tree. Z Disconnectedz-Exception in handler for Disconnected signal:rS)rT)rXrr rZr[rYrrarrrm Exceptionr\r]r^r_)r7r`r;rrrcbrrrrq s&     zConnection._signal_funcg?Fc  s|tkrtdt|tkr(tdtt| dtrH| jddd<nd| krXtdt||||d} y| j|d|iWn@t k r}z$t j t j d |||j|WYd d }~XnXd kr܈d kr|j| d Sd krtd krtfd d }|j| || | d S)aSCall the given method, asynchronously. If the reply_handler is None, successful replies will be ignored. If the error_handler is None, failures will be ignored. If both are None, the implementation may request that no reply is sent. :Returns: The dbus.lowlevel.PendingCall. :Since: 0.81.0 z1Methods may not be called on the reserved path %sz6Methods may not be called on the reserved interface %s)r>r,Fz*unexpected keyword argument 'utf8_strings') destinationr interfacemethod signaturez.msg_reply_handler)require_main_loop)rr rrUrrr3r rIrr\r]r^r_rNZ send_messagerZsend_message_with_reply)r7rrr:r;rrrrrtimeoutr>rrr`err)rrrr call_async'sB    zConnection.call_asyncc Ks|tkrtdt|tkr(tdtt|d} trH| jdd| d<nd| krXtdt||||d} y| j|d|iWn@t k r} z$t j t j d ||| j| WYd d } ~ XnX|j| |} | jf| }t|d krd St|d kr|d St|Sd S) zECall the given method, synchronously. :Since: 0.81.0 z1Methods may not be called on the reserved path %sz6Methods may not be called on the reserved interface %s)r>r,Fz*unexpected keyword argument 'utf8_strings')rrrrrzrrr`rZ reply_messageZ args_listrrr call_blockinggs<    zConnection.call_blockingcCs|jj|dS)zArrange for `callable` to be called with one argument (this Connection object) when the Connection becomes disconnected. :Since: 0.83.0 N)rmrI)r7callablerrrcall_on_disconnectionsz Connection.call_on_disconnection)NNT)NNNN)NNNN)rFT)rF)rdrerf__doc__rr|r@rsr}rrrbrrqrrr __classcell__rr)rNrrs*  & ` 7  > +)rr)"__all__Z __docformat__r\ror0Z_dbus_bindingsrZ _Connectionrrrrrr Zdbus.exceptionsr Z dbus.lowlevelr r r rrZ dbus.proxiesrZ dbus._compatrrrrZ getLoggerr^robjectrrrrrs"$    D