o t3b`@sddlZzddlmZWneyddlmZYnwddlZddlmZddlm Z m Z m Z m Z dZ edZddlmZmZmZmZmZddlmZGd d d ZGd d d ZGd ddeZGdddeZdS)N)RLock)process_introspection_data) DBusExceptionIntrospectionParserExceptionMissingErrorHandlerExceptionMissingReplyHandlerExceptionrestructuredtextz dbus.proxies)BUS_DAEMON_IFACEBUS_DAEMON_NAMEBUS_DAEMON_PATHINTROSPECTABLE_IFACE LOCAL_PATH)is_py2c@(eZdZdZddZddZddZdS) _DeferredMethodzXA proxy method which will only get called once we have its introspection reply. cCs||_|j|_||_||_dSN) _proxy_method _method_name_append_block)self proxy_methodappendblockr./usr/lib/python3/dist-packages/dbus/proxies.py__init__8s z_DeferredMethod.__init__cOs@d|vs |ddr||j||dS||j|i|S)N reply_handler ignore_replyF)getrrrrargskeywordsrrr__call__?s z_DeferredMethod.__call__cOs||j||dSr)rrr rrr call_asyncJsz_DeferredMethod.call_asyncN__name__ __module__ __qualname____doc__rr#r$rrrrr4s  rc@r) _ProxyMethodzA proxy method. Typically a member of a ProxyObject. Calls to the method produce messages that travel over the Bus and are routed to a specific named Service. cCsX|tkr tdt||_||_||_||_t|||_|dur't |||_ dS)Nz1Methods may not be called on the reserved path %s) r r_proxy _connection_named_service _object_path_dbus_bindingsvalidate_member_namervalidate_interface_name_dbus_interface)rproxy connectionbus_name object_path method_nameifacerrrrUs   z_ProxyMethod.__init__c Os|dd}|dd}|dd}|dd}|dus |dur4|dur't|dur.t|r4td|d|j}|durV|durG|j}n|d|j}|jj|d}|s\|durr|j j |j |j ||j||||fi|dS|j j |j |j ||j||fi|S) Nr error_handlerrF signaturez6ignore_reply and reply_handler cannot be used togetherdbus_interface.)poprr TypeErrorr2rr+_introspect_method_maprr,r$r-r. call_blocking) rr!r"rr9rr:r;keyrrrr#isL       z_ProxyMethod.__call__c Os|dd}|dd}|dd}|d|j}|dur2|r'|d|j}n|j}|jj|d}|jj|j|j ||j||||fi|dS)Nrr9r:r;r<) r=r2rr+r?rr,r$r-r.)rr!r"rr9r:r;rArrrr$s(     z_ProxyMethod.call_asyncNr%rrrrr*Ns  ,r*c@seZdZdZeZeZdZdZ dZ  d%dd Z e d d ddd Z e d d dddZe dd dddZd&ddZddZddZddZddZddZddZdd Zd&d!d"Zd#d$ZeZdS)' ProxyObjectzA proxy to the remote Object. A ProxyObject is provided by the Bus. ProxyObjects have member functions, and can be called like normal Python objects. rNTFc Ks8|dd}|dur!|durtd|}ddlm}|dtdd|d d} | durB|dur3td | }ddlm}|d tdd|rOtd d ||rU|||_|durat |||_ |_ t |||_|sw|||_ d|_g|_i|_t|_|r|jtkr|j|_dS|j|_||_dS)aInitialize the proxy object. :Parameters: `conn` : `dbus.connection.Connection` The bus or connection on which to find this object. The keyword argument `bus` is a deprecated alias for this. `bus_name` : str A bus name for the application owning the object, to be used as the destination for method calls and the sender for signal matches. The keyword argument ``named_service`` is a deprecated alias for this. `object_path` : str The object path at which the application exports the object `introspect` : bool If true (default), attempt to introspect the remote object to find out supported methods and their signatures `follow_name_owner_changes` : bool If true (default is false) and the `bus_name` is a well-known name, follow ownership changes for that name busNz%conn and bus cannot both be specifiedr)warnz`Passing the bus parameter to ProxyObject by name is deprecated: please use positional parametersrD) stacklevel named_servicez3bus_name and named_service cannot both be specifiedzjPassing the named_service parameter to ProxyObject by name is deprecated: please use positional parametersz>ProxyObject.__init__ does not take these keyword arguments: %sz, )r=r>warningsrFDeprecationWarningjoinkeys_require_main_loop_busr/validate_bus_namer-_requested_bus_namevalidate_object_path__dbus_object_path__activate_name_owner_pending_introspect_pending_introspect_queuer?r_introspect_lockr INTROSPECT_STATE_DONT_INTROSPECT_introspect_state'INTROSPECT_STATE_INTROSPECT_IN_PROGRESS _Introspect) rconnr5r6 introspectfollow_name_owner_changeskwargsrErFrHrrrrsP          zProxyObject.__init__cC|jSr)r-rrrrzProxyObject.aThe bus name to which this proxy is bound. (Read-only, may change.) If the proxy was instantiated using a unique name, this property is that unique name. If the proxy was instantiated with a well-known name and with ``follow_name_owner_changes`` set false (the default), this property is the unique name of the connection that owned that well-known name when the proxy was instantiated, which might not actually own the requested well-known name any more. If the proxy was instantiated with a well-known name and with ``follow_name_owner_changes`` set true, this property is that well-known name. cCr_r)rPr`rrrra rbz[The bus name which was requested when this proxy was instantiated. cCr_r)rRr`rrrra&rbzThe object-path of this proxy.cKs"|jj|f|||j|jd|S)ax Arrange for the given function to be called when the given signal is received. :Parameters: `signal_name` : str The name of the signal `handler_function` : callable A function to be called when the signal is emitted by the remote object. Its positional arguments will be the arguments of the signal; optionally, it may be given keyword arguments as described below. `dbus_interface` : str Optional interface with which to qualify the signal name. If None (the default) the handler will be called whenever a signal of the given member name is received, whatever its interface. :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). ) signal_namer;r5path)rNadd_signal_receiverr-rRrrchandler_functionr;r"rrrconnect_to_signal2s <zProxyObject.connect_to_signalc Cs>i}trd|d<|jj|j|jtddd|j|jfddi|S)NT utf8_strings Introspectrrequire_main_loopF)rrNr$r-rRr _introspect_reply_handler_introspect_error_handler)rr^rrrrZus zProxyObject._IntrospectcCs*|jD] \}}}||i|qg|_dSr)rU)rrr!r"rrr_introspect_execute_queues z%ProxyObject._introspect_execute_queuec Cs|jz9zt||_Wnty+}z||WYd}~W|jdSd}~ww|j|_d|_ | W|jdS|jwr) rVacquirerr?rrnrelease INTROSPECT_STATE_INTROSPECT_DONErXrTro)rdataerrrrms    z%ProxyObject._introspect_reply_handlercCspttd|j|j|jj|jj||j zt d|j |_ d|_|W|j dS|j w)Nz$Introspect error on %s:%s: %s.%s: %sz'Executing introspect queue due to error)logging basicConfig_loggererrorr-rR __class__r'r&rVrpdebugrWrXrTrorq)rrxrrrrns    z%ProxyObject._introspect_error_handlercCsL|jz|jdur|jW|jdSW|jdS|jwr)rVrprTrrqr`rrr_introspect_blocks   zProxyObject._introspect_blockcCsf|jz'|j|jkr|j|||fn||i|W|jdSW|jdS|jwr)rVrprXrYrUrrq)rcallbackr!r^rrr_introspect_add_to_queues  z$ProxyObject._introspect_add_to_queuecCs&|dr|drt|||SN__) startswithendswithAttributeErrorget_dbus_methodrmemberrrr __getattr__s zProxyObject.__getattr__cCs<|||j|j|j||}|j|jkr|||j|j}|S)a,Return a proxy method representing the given D-Bus method. The returned proxy method can be called in the usual way. For instance, :: proxy.get_dbus_method("Foo", dbus_interface='com.example.Bar')(123) is equivalent to:: proxy.Foo(123, dbus_interface='com.example.Bar') or even:: getattr(proxy, "Foo")(123, dbus_interface='com.example.Bar') However, using `get_dbus_method` is the only way to call D-Bus methods with certain awkward names - if the author of a service implements a method called ``connect_to_signal`` or even ``__getattr__``, you'll need to use `get_dbus_method` to call them. For services which follow the D-Bus convention of CamelCaseMethodNames this won't be a problem. ) ProxyMethodClassrNr-rRrXrYDeferredMethodClassr}r{)rrr;retrrrrs  zProxyObject.get_dbus_methodcCsd|j|j|jt|fS)Nz&)rNr-rRidr`rrr__repr__szProxyObject.__repr__)NNNTFr)r&r'r(r)r*rrrrWrYrrrpropertyr5requested_bus_namer6rhrZrormrnr{r}rrr__str__rrrrrBs@ S C   &rBc@seZdZdZddZedddddZeZeddddd Zed dddd Z ed dddd Z edddddZ dddZ ddZ dddZddZeZdS) InterfacezAn interface into a remote object. An Interface can be used to wrap ProxyObjects so that calls can be routed to their correct D-Bus interface. cCs$t|tr |j|_n||_||_dS)a:Construct a proxy for the given interface on the given object. :Parameters: `object` : `dbus.proxies.ProxyObject` or `dbus.Interface` The remote object or another of its interfaces `dbus_interface` : str An interface the `object` implements N) isinstancer proxy_object_objr2)robjectr;rrrrs  zInterface.__init__cC|jjSr)rr6r`rrrrazInterface.Nz.The D-Bus object path of the underlying objectcCrr)rr5r`rrrrarz:The bus name to which the underlying proxy object is boundcCrr)rrr`rrrra rzGThe bus name which was requested when the underlying object was createdcCr_r)rr`rrrrarbzThe underlying proxy objectcCr_r)r2r`rrrrarbzThe D-Bus interface representedcKs"|s|j}|jj|||fi|S)aaArrange for a function to be called when the given signal is emitted. The parameters and keyword arguments are the same as for `dbus.proxies.ProxyObject.connect_to_signal`, except that if `dbus_interface` is None (the default), the D-Bus interface that was passed to the `Interface` constructor is used. )r2rrhrfrrrrhs  zInterface.connect_to_signalcCs,|dr|drt||j||jSr~)rrrrrr2rrrrr$szInterface.__getattr__cCs|dur|j}|j||S)a&Return a proxy method representing the given D-Bus method. This is the same as `dbus.proxies.ProxyObject.get_dbus_method` except that if `dbus_interface` is None (the default), the D-Bus interface that was passed to the `Interface` constructor is used. N)r2rr)rrr;rrrr*szInterface.get_dbus_methodcCsd|j|jt|fS)Nz%)rr2rr`rrrr6szInterface.__repr__r)r&r'r(r)rrr6rRr5rrr;rhrrrrrrrrrs4       r)ru threadingr ImportErrordummy_threadingr/dbus._expat_introspect_parserrdbus.exceptionsrrrr __docformat__ getLoggerrwr r r r r dbus._compatrrr*rrBrrrrrs&    `B