o t3bl@sdZdZddlZddlZddlZddlmZmZm Z m Z m Z m Z m Z ddlmZddlmZmZmZmZmZddlmZddlmZmZerMdd lmZndd lmZed Zd d ZGddde Z!GdddeZdS)) Connection SignalMatchreStructuredTextN)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.connectioncOdSN)argskwargsrr1/usr/lib/python3/dist-packages/dbus/connection.py_noop3src@seZdZgdZeredeeZ    dddZddZ d d Z d d Z e d dZ ddZddZddZddZddZddZdS)r)_sender_name_owner_member _interface_sender_path_handler _args_match_rule _byte_arrays _conn_weakref_destination_keyword_interface_keyword_message_keyword_member_keyword_sender_keyword _path_keyword_int_args_match _utf8_stringsFNc Ks\|durt||durt||durt||dur t|d|_t||_||_||_ ||_ ||_ ||_ ||_ trE|dd|_nd|vrMtd||_||_| |_| |_| |_| |_| |_||_|sld|_dSi|_|D]:}|ds~td|z t|dd}Wn tytd|w|dks|dkrtd ||||j|<qqdS) N utf8_stringsF*unexpected keyword argument 'utf8_strings'argz(SignalMatch: unknown keyword argument %sr?z9SignalMatch: arg match index must be in range(64), not %d)r rrr r$weakrefrefr&r rrr!r"rrpopr. TypeErrorr%r+r,r*r(r)r'r#r- startswithint ValueError)selfconnsender object_pathdbus_interfacememberhandler byte_arrayssender_keyword path_keywordinterface_keywordmember_keywordmessage_keyworddestination_keywordrkwargindexrrr__init__Csb    zSignalMatch.__init__cCs tt|Sz-SignalMatch objects are compared by identity.)hashidr;rrr__hash__~s zSignalMatch.__hash__cCs||uSrLrr;otherrrr__eq__zSignalMatch.__eq__cCs||uSrLrrQrrr__ne__rTzSignalMatch.__ne__cCs|jSr)r rOrrrszSignalMatch.cCs|jdurZdg}|jdur|d|j|jdur"|d|j|jdur/|d|j|jdur<|d|j|jdurT|jD] \}}|d||fqFd||_|jS)Nz type='signal'z sender='%s'z path='%s'zinterface='%s'z member='%s'z arg%d='%s',) r$r appendr!rrr-itemsjoin)r;rulerJvaluerrr__str__s       zSignalMatch.__str__cCsd|jt||j|fS)Nz<%s at %x "%s" on conn %r>) __class__rNr$r&rOrrr__repr__szSignalMatch.__repr__cCs ||_dSr)r)r;new_namerrrset_sender_name_owners z!SignalMatch.set_sender_name_ownercKs\|d|jfvr dS||jkrdS||jkrdS||jkrdS||jkr%dS||jkr,dSdS)NFT)r"r r!rrr#)r;r=r>r?r@rArrrrmatches_removal_specs     z SignalMatch.matches_removal_speccCsd}|jd|fvr dS|jdurKtdd}trtnt}tr#d|d<|jdi|}|j D]\}}|t |ksGt |||rG|||krJdSq0|j d| fvrVdS|jd|fvradS|jd|fvrldSzvtoq|j}|dus{|r{|jst|jd}tr|j|d<|jdi|}i}|jdur|||j<|jdur|||j<|jdur|||j<|jdur| ||j<|jdur|||j<|jdur|||j<|j|i|WdSttjdddYdS) NFTrBr/z&Exception in handler for D-Bus signal:exc_infor) r get_senderr-dictrrrr get_args_listrYlen isinstancer get_memberr get_interfacer!get_pathr.r%r+r'get_destinationr,r*r(r)r"logging basicConfig_loggererror)r;messagerrarg_typerJr\r/rrrmaybe_handle_messages`                z SignalMatch.maybe_handle_messagecCs<|}|dur|j||j|j|j|jfi|jdSdSr)r&remove_signal_receiverrrr r!r#)r;r<rrrremoves  zSignalMatch.remove)FNNNNNN)__name__ __module__ __qualname___slotsrrXtuple __slots__rKrPrSrUpropertyr=r]r_rarbrvrxrrrrr7s(  ;  :rcseZdZdZeZfddZddZddd Z    dd d Z d d Z    dddZ ddZ ddZ  dddZ  dddZddZZS) rzzA connection to another application. In this base class there is assumed to be no bus daemon. :Since: 0.81.0 csVtt|j|i|t|ds)d|_g|_i|_ t|_ | |j j dSdS)N_dbus_Connection_initializedrd) superrrKhasattrr"_Connection__call_on_disconnection!_signal_recipients_by_object_path threadingLock _signals_lockadd_message_filterr^ _signal_func)r;rrr^rrrKs  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)r;bus_namerrractivate_name_ownerszConnection.activate_name_ownerNTcKsn|dd}|dur!|durtdddlm}|dtdd|}|r.td d ||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_serviceN3bus_name and named_service cannot both be specifiedrwarnziPassing 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)r6r7warningsrDeprecationWarningrZkeysProxyObjectClass)r;rr>rrrrrrr get_object&s    zConnection.get_objectc Ks||dd}|dur%|durtd|}ddlm}|dtddt||||||fi|} |jz |j |i} | |i} | |g} | | W|j | S|j w) 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`. rNrrrzrPassing the named_service parameter to add_signal_receiver by name is deprecated: please use positional parametersrr) _require_main_loopr6r7rrrrracquirer setdefaultrXrelease) r;handler_function signal_namer?rpathkeywordsrrmatch by_interface by_membermatchesrrradd_signal_receiverKs4G         zConnection.add_signal_receiverc cs|dur d|f}nd}|durd|f}nd}|dur d|f}nd}|D]5}|j|}|dur1q$|D]%}||d}|dur@q3|D]}||d} | durOqB| D]} | VqQqBq3q$dS)Nr)rget) r;rr?r@ path_keysinterface_keys member_keysrrrmrrr_iter_easy_matchess8      zConnection._iter_easy_matchescKsb|dd}|dur!|durtd|}ddlm}|dtddg} g} |jzt|j|d} | dur>W|j dS| |d} | durPW|j dS| |d} | durbW|j dS| D]}||usw|j |||||fi|r}| |qd| |qd| r| | |<n| |=| s| |=| s|j|=W|j n|j w| D]}| |qdS)NrrrrzuPassing the named_service parameter to remove_signal_receiver by name is deprecated: please use positional parametersrr) r6r7rrrrrrrrrbrX_clean_up_signal_match)r;handler_or_matchrr?rrrrrnew deletionsrrrrrrrrwsh         z!Connection.remove_signal_receivercCrrr)r;rrrrrsz!Connection._clean_up_signal_matchc Cst|tstS|}|}|}||||D]}||q|tkrN|t krN|dkrN|j D]}z||Wq1t yMt tjdddYq1wtS)zvD-Bus filter function. Handle signals by dispatching to Python callbacks kept in the match-rule tree. Disconnectedz-Exception in handler for Disconnected signal:rdre)rkrr rmrnrlrrvrrr Exceptionrprqrrrs)r;rtr?rrrcbrrrr s,      zConnection._signal_funcFc  s |tkr tdt|tkrtdtt| dtr$| ddd<nd| vr,tdt||||d} z | j|d|iWnt yY}zt t d |||j|d }~wwd urid uri|| d Sd urotd urutfd 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 1Methods may not be called on the reserved path %s6Methods may not be called on the reserved interface %srcr/Fr0 destinationr interfacemethod signature.msg_reply_handler)require_main_loop)rr rrhrrr7rrXrrprqrrrsr^ send_messagersend_message_with_reply)r;rr>r?rrrrrtimeoutrBrrrterrrr call_async)sP     zConnection.call_asyncc  Ks|tkr tdt|tkrtdtt|d} tr$| dd| d<nd| vr,tdt||||d} z | j|d|iWnt yY} zt t d ||| j| d } ~ ww|| |} | jd i| }t|d krpd St|d krz|d St|S)zECall the given method, synchronously. :Since: 0.81.0 rrrcr/Fr0rrrNrrdr)rr rrhrrr7rrXrrprqrrrsr^!send_message_with_reply_and_blockrirjr})r;rr>r?rrrrrBrrrtr reply_message args_listrrr call_blockingisJ    zConnection.call_blockingcCs|j|dS)zArrange for `callable` to be called with one argument (this Connection object) when the Connection becomes disconnected. :Since: 0.83.0 N)rrX)r;callablerrrcall_on_disconnectionsz Connection.call_on_disconnection)NNT)NNNN)rFT)rF)ryrzr{__doc__rrrKrrrrrwrrrrr __classcell__rrrrrs4  & d ;  A -r)"__all__ __docformat__rprr4_dbus_bindingsr _Connectionrrrrr r dbus.exceptionsr dbus.lowlevelr r rrr dbus.proxiesr dbus._compatrrrr getLoggerrrrobjectrrrrrs$$    D