U º±K^žlã@sÜdZdZddlZddlZddlZddlmZmZm Z m Z m Z m Z m Z ddlmZddlmZmZmZmZmZddlmZddlmZmZeršdd lmZn dd lmZe d ¡Zd d „ZGdd„de ƒZ!Gdd„deƒZdS))Ú ConnectionÚ SignalMatchZreStructuredTextéN)rÚ LOCAL_IFACEÚ LOCAL_PATHÚvalidate_bus_nameÚvalidate_interface_nameÚvalidate_member_nameÚvalidate_object_path)Ú DBusException)Ú ErrorMessageÚHANDLER_RESULT_NOT_YET_HANDLEDÚMethodCallMessageÚMethodReturnMessageÚ SignalMessage)Ú ProxyObject)Úis_py2Úis_py3)ÚString)Ú UTF8Stringzdbus.connectioncOsdS©N©)ÚargsÚkwargsrrú1/usr/lib/python3/dist-packages/dbus/connection.pyÚ_noop3src@s¦eZdZddddddddd d d d d ddddgZerŠózSignalMatch.cCsº|jdkr´dg}|jdk r*| d|j¡|jdk rD| d|j¡|jdk r^| d|j¡|jdk rx| d|j¡|jdk r¨|j ¡D]\}}| d||f¡qŒd |¡|_|jS)Nz type='signal'z sender='%s'z path='%s'zinterface='%s'z member='%s'z arg%d='%s'ú,) r"rÚappendrrrr+ÚitemsÚjoin)r9ZrulerAÚvaluerrrÚ__str__Œs       zSignalMatch.__str__cCsd|jt|ƒ|j| ¡fS)Nz<%s at %x "%s" on conn %r>)Ú __class__rEr"r$rFrrrÚ__repr__ŸsÿzSignalMatch.__repr__cCs ||_dSr)r)r9Únew_namerrrÚset_sender_name_owner£sz!SignalMatch.set_sender_name_ownercKs\|d|jfkrdS||jkr dS||jkr.dS||jkrr?rrrrÚmatches_removal_spec¦s     z SignalMatch.matches_removal_speccCsîd}|jd| ¡fkrdS|jdk r’tdd}tr6tnt}trFd|d<|jf|Ž}|j  ¡D]4\}}|t |ƒksŠt |||ƒrŠ|||kr\dSq\|j d|  ¡fkr¨dS|jd| ¡fkr¾dS|jd| ¡fkrÔdSzòtoÞ|j}|dksô|rô|jst|jd}tr|j|d<|jf|Ž}i}|jdk r:| ¡||j<|jdk rT| ¡||j<|jdk rn| ¡||j<|jdk rˆ|  ¡||j<|jdk r¢| ¡||j<|jdk r¸|||j<|j||ŽWn"t ¡tjdddYnXdS)NFT©r@r-z&Exception in handler for D-Bus signal:é©Úexc_info) rZ get_senderr+ÚdictrrrrÚ get_args_listrPÚlenÚ isinstancerÚ get_memberrÚ get_interfacerÚget_pathr,r#r)r%Zget_destinationr*r(r&r'r ÚloggingÚ basicConfigÚ_loggerÚerror)r9ÚmessagerrZarg_typerArRr-rrrÚmaybe_handle_message¶s^      ÿ þ           z SignalMatch.maybe_handle_messagecCs4| ¡}|dk r0|j||j|j|j|jf|jŽdSr)r$Úremove_signal_receiverrrrrr!)r9r:rrrÚremoveðs þýzSignalMatch.remove)FNNNNNN)Ú__name__Ú __module__Ú __qualname__Z_slotsrrOÚtupleÚ __slots__rBrGrJrKÚpropertyr;rSrUrWrXrirkrrrrr7sHû ü ; :rcs~eZdZdZeZ‡fdd„Zdd„Zddd „Zdd d „Z d d „Z ddd„Z dd„Z dd„Z ddd„Zd dd„Zdd„Z‡ZS)!rzzA connection to another application. In this base class there is assumed to be no bus daemon. :Since: 0.81.0 csJtt|ƒj||Žt|dƒsFd|_g|_i|_t ¡|_ |  |j j ¡dS)NÚ_dbus_Connection_initializedrZ) ÚsuperrrBÚhasattrrrÚ"_Connection__call_on_disconnectionÚ!_signal_recipients_by_object_pathÚ threadingZLockÚ _signals_lockZadd_message_filterrTÚ _signal_func)r9rr©rTrrrBs  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)r9Úbus_namerrrÚactivate_name_ownerszConnection.activate_name_ownerNTcKsn| dd¡}|dk rB|dk r$tdƒ‚ddlm}|dtdd|}|r\td d  | ¡¡ƒ‚|j||||d S) aÕReturn 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_serviceNú3bus_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)r4r5Úwarningsr€ÚDeprecationWarningrQÚkeysÚProxyObjectClass)r9r{r<r„rr}r€rrrÚ get_object&s"  þ ÿ ÿzConnection.get_objectc Ks°| ¡| dd¡}|dk rJ|dk r,tdƒ‚|}ddlm}|dtddt||||||f|Ž} |j ¡z4|j   |i¡} |   |i¡} |   |g¡} |   | ¡W5|j  ¡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`. r}Nr~rrzrPassing the named_service parameter to add_signal_receiver by name is deprecated: please use positional parametersrr‚) Z_require_main_loopr4r5r…r€r†rrxÚacquireÚreleaservÚ setdefaultrO) r9Zhandler_functionÚ signal_namer=r{ÚpathÚkeywordsr}r€ÚmatchÚ by_interfaceÚ by_memberÚmatchesrrrÚadd_signal_receiverKs8G  þ ÿÿ ÿ   zConnection.add_signal_receiverc cs¶|dk rd|f}nd}|dk r(d|f}nd}|dk r>d|f}nd}|D]j}|j |¡}|dkr`qF|D]J}| |d¡}|dkr~qd|D]*}| |d¡} | dkrœq‚| D] } | Vq q‚qdqFdS)Nr)rvÚget) r9rŽr=r>Z path_keysZinterface_keysZ member_keysr‘r’r“ÚmrrrÚ_iter_easy_matches¯s.      zConnection._iter_easy_matchescKsB| dd¡}|dk rB|dk r$tdƒ‚|}ddlm}|dtddg} g} |j ¡zÆ|j  |d¡} | dkrtW¢¬dS|   |d¡} | dkrW¢dS|   |d¡} | dkr¬W¢tdS| D]8}||ksÒ|j |||||f|ŽrÞ|   |¡q°|   |¡q°| rø| | |<n | |=| s| |=| s|j|=W5|j ¡X| D]}|  |¡q,dS)Nr}r~rrzuPassing the named_service parameter to remove_signal_receiver by name is deprecated: please use positional parametersrr‚) r4r5r…r€r†rxrŠr‹rvr•rXrOÚ_clean_up_signal_match)r9Zhandler_or_matchrr=r{rŽrr}r€ÚnewZ deletionsr‘r’r“rrrrrjÌs`  ý ÿ  üûÿ     z!Connection.remove_signal_receivercCsdSrr)r9rrrrr˜sz!Connection._clean_up_signal_matchc Cs¤t|tƒstS| ¡}| ¡}| ¡}| |||¡D]}| |¡q4|tkr |t kr |dkr |j D]<}z ||ƒWqbt k rœt   ¡tjdddYqbXqbtS)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:rZr[)r`rr rbrcrar—rirrruÚ Exceptionrdrerfrg)r9rhr=rŽrrÚcbrrrry s. ÿ ÿþ  ÿzConnection._signal_funcçð¿Fc  s|tkrtdtƒ‚|tkr(tdtƒ‚t| d‰trH|  dd¡ˆd<nd| krXtdƒ‚t||||d} z| j|d|iŽWn@t k r¼}z"t   ¡t   d |||j|¡‚W5d }~XYnXˆd kr܈d krÜ| | ¡d Sˆd krèt‰ˆd krôt‰‡‡‡fd 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 %sú6Methods may not be called on the reserved interface %srYr-Fr.©Z destinationrŽZ interfaceÚmethodÚ signatureú.msg_reply_handler)Úrequire_main_loop)rr rr]rr•r5r rOršrdrerfrgrTZ send_messagerZsend_message_with_reply)r9r{r<r=r r¡rr§r¥Útimeoutr@r©rrhÚer¨rr¤rÚ call_async)sR ÿÿ ýþ  þzConnection.call_asyncc  Ks|tkrtdtƒ‚|tkr(tdtƒ‚t|d} trH|  dd¡| d<nd| krXtdƒ‚t||||d} z| j|d|iŽWn@t k r¼} z"t   ¡t   d ||| j| ¡‚W5d } ~ XYnX| | |¡} | jf| Ž}t|ƒd kræd St|ƒd krú|d St|ƒSd S) zECall the given method, synchronously. :Since: 0.81.0 rržrYr-Fr.rŸr¡r¢NrrZ)rr rr]rr•r5r rOršrdrerfrgrTZ!send_message_with_reply_and_blockr^r_ro)r9r{r<r=r r¡rrªr@rr¦rhr«Z reply_messageZ args_listrrrÚ call_blockingisNÿÿ ýþÿ   zConnection.call_blockingcCs|j |¡dS)z©Arrange for `callable` to be called with one argument (this Connection object) when the Connection becomes disconnected. :Since: 0.83.0 N)rurO)r9ÚcallablerrrÚcall_on_disconnection–sz Connection.call_on_disconnection)NNT)NNNN)NNNN)rœFT)rœF)rlrmrnÚ__doc__rrˆrBr|r‰r”r—rjr˜ryr¬r­r¯Ú __classcell__rrrzrrús4  &ü dü ; ý Aþ -r)"Ú__all__Z __docformat__rdrwr2Z_dbus_bindingsrZ _Connectionrrrrrr Zdbus.exceptionsr Z dbus.lowlevelr r r rrZ dbus.proxiesrZ dbus._compatrrrrZ getLoggerrfrÚobjectrrrrrÚs"$    D