a F `=@sddlmZmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZddlmZmZmZdd lZed d ed d dd lmZmZgdZGdddeZGdddedZGdddeZd S))ABCMetaabstractmethod)partial) PropertyProxy) ErrorMapper)Signal)DBUS_FLAG_NONEDBusSpecification) get_variantget_variant_typeunwrap_variantNGioz2.0GLib)rr) GLibClientAbstractClientObjectHandlerClientObjectHandlerc@seZdZdZejZeeefddZ edeefddZ eddZ edefd d Z ed d Z ed dZeddZeddZeddZdS)rz0The low-level DBus client library based on GLib.c Cs||||||||| d S)zVSynchronously call a DBus method. :return: a result of the DBus call N)Z call_sync) cls connection service_name object_pathinterface_name method_name parameters reply_typeflagstimeoutr9/usr/lib/python3.9/site-packages/dasbus/client/handler.py sync_call1szGLibClient.sync_callrc Cs(|j||||||| | |j|| fd dS)z"Asynchronously call a DBus method.callback user_dataN)call_async_call_finish) rrrrrrrrr! callback_argsrrrrr async_callEszGLibClient.async_callcs&|\}}|fddg|RdS)z(Finish an asynchronous DBus method call.cs SN)Z call_finishr result_object source_objectrr`z/GLibClient._async_call_finish..Nr)rr*r)r"r!r%rr(rr$Xs  zGLibClient._async_call_finishc Cs.|j||||d||j||fd} t|j|| S)zKSubscribe to a signal. :return: a callback to unsubscribe Nr )Zsignal_subscribe_signal_callbackr_unsubscribe_signal) rrrrr signal_namer!r%rsubscription_idrrrsubscribe_signalds zGLibClient.subscribe_signalc Cs|\}} ||g| RdSz8A callback that is called when a DBus signal is emitted.Nr) rrZ sender_namerrr/rr"r!r%rrrr-}szGLibClient._signal_callbackcCs||dS)zUnsubscribe from a signal.N)Zsignal_unsubscribe)rrr0rrrr.szGLibClient._unsubscribe_signalcCst|tjotj|S)zIs it a remote DBus error?) isinstancerErrorr DBusErroris_remote_errorrerrorrrrr6s  zGLibClient.is_remote_errorcCs tj|S)z)Get a DBus name of the remote DBus error.)rr5Zget_remote_errorr7rrrget_remote_error_namesz GLibClient.get_remote_error_namecCs:||}|j}dd|}||r6|t|dS|S)z'Get a message of the remote DBus error.z{}:{}: z GDBus.ErrorN)r9messageformat startswithlen)rr8namer:prefixrrrget_remote_error_messages    z#GLibClient.get_remote_error_messageN)__name__ __module__ __qualname____doc__rZMAXINTZDBUS_TIMEOUT_NONE classmethodrrr&r$r1r-r.r6r9r@rrrrr+s2        rc@seZdZdZgdZddZeddZeddZed d Z e d d Z d dZ ddZ ddZe ddZe ddZe ddZe ddZdS)rz-The abstract handler of a remote DBus object. _message_bus _service_name _object_path_specificationcCs||_||_||_d|_dS)zCreate a new handler. :param message_bus: a message bus :param service_name: a DBus name of the service :param object_path: a DBus path the object NrF)self message_busrrrrr__init__sz$AbstractClientObjectHandler.__init__cCs|jS)z9DBus service name. :return: a DBus name )rHrKrrrrsz(AbstractClientObjectHandler.service_namecCs|jS)z8DBus object path. :return: a DBus path )rIrNrrrrsz'AbstractClientObjectHandler.object_pathcCs|js||_|jS)zDBus specification.)rJ_get_specificationrNrrr specifications z)AbstractClientObjectHandler.specificationcCstS)zKIntrospect the DBus object. :return: a DBus specification r rNrrrrOsz.AbstractClientObjectHandler._get_specificationcCs"|||}|t|}||S)zCreate a member of the DBus object. :param interface_name: a name of the interface :param member_name: a name of the member :return: a signal, a method or a property )_find_member_spec _find_handlertype)rKr member_namespecZhandlerrrr create_members z)AbstractClientObjectHandler.create_membercCs|j||S)zFind a specification of the DBus member. :param interface_name: a name of the interface :param member_name: a name of the member :return: a specification of the member )rPZ get_member)rKrrTrrrrQsz-AbstractClientObjectHandler._find_member_speccCsD|tjur|jS|tjur |jS|tjur0|jStd|j dS)zFind a handler for the given member type. :param member_type: a type of the member :return: a callback zUnsupported type: {}N) r ZProperty _get_propertyZMethod _get_methodr _get_signal TypeErrorr;rA)rK member_typerrrrRs    z)AbstractClientObjectHandler._find_handlercCsdS)zGet a proxy of the DBus property. :param property_spec: a property_specification :return: a property object Nr)rK property_specrrrrWsz)AbstractClientObjectHandler._get_propertycCsdS)zGet a proxy of the DBus method. :param method_spec: a method specification :return: a callable object NrrKZ method_specrrrrX sz'AbstractClientObjectHandler._get_methodcCsdS)z}Get a proxy of the DBus signal. :param signal_spec: a signal specification :return: a signal object Nr)rK signal_specrrrrYsz'AbstractClientObjectHandler._get_signalcCsdS)zDisconnect members of the DBus object. Unsubscribe from DBus signals and disconnect all registered callbacks of the proxy signals. NrrNrrrdisconnect_memberssz.AbstractClientObjectHandler.disconnect_membersN)rArBrCrD __slots__rMpropertyrrrPrrOrVrQrRrWrXrYr_rrrrrs,          r) metaclasscseZdZdZgdZdeeffdd ZddZdd Z d d Z d d Z ddZ ddZ ddZddZddZddZddZddZddZZS) rz$The client handler of a DBus object.)_client_signal_factory _error_mapper_subscriptionsNcs2t|||||_||_|p$t|_g|_dS)aBCreate a new handler. :param message_bus: a message bus :param service_name: a DBus name of the service :param object_path: a DBus path the object :param error_mapper: a DBus error mapper :param client: a DBus client library :param signal_factory: a signal factory N)superrMrcrdrrerf)rKrLrrZ error_mapperZclientZsignal_factory __class__rrrM2s  zClientObjectHandler.__init__cCs|dddd}t|S)zIntrospect the DBus object.z#org.freedesktop.DBus.IntrospectableZ IntrospectNz(s)) _call_methodr Zfrom_xml)rKZxmlrrrrODsz&ClientObjectHandler._get_specificationc CsR|}|jj|jj|j|j|j|j|j |j fd}|j ||j |j |S)zGet a proxy of the DBus signal.r!r%)rdrcr1rGrrHrIrr>r-emitrfappendZ disconnect)rKr^signalZ unsubscriberrrrYOs zClientObjectHandler._get_signalcCs|t|dSr2)r )rKrr!rrrr-esz$ClientObjectHandler._signal_callbackcCs6d}d}|jrt|j|}|jr,t|j|}t||S)z!Get a proxy of the DBus property.N)readabler_get_property_valuewritable_set_property_valuer)rKr\gettersetterrrrrWis  z!ClientObjectHandler._get_propertycCs |dddd|j|j}t|S)z!Get a value of the DBus property.org.freedesktop.DBus.PropertiesZGetz(ss)z(v))rjrr>r )rKr\Zvariantrrrrpvsz'ClientObjectHandler._get_property_valuec Cs"|dddd|j|jt|j|S)z!Set a value of the DBus property.ruSetz(ssv)N)rjrr>r rS)rKr\Zproperty_valuerrrrrs z'ClientObjectHandler._set_property_valuecCst|j|j|j|j|jS)z(Get a callable proxy of the DBus method.)rrjrr>in_typeout_typer]rrrrXszClientObjectHandler._get_methodc Os|sd}|durt||}d}|dur.t|}|jj|j|j||||f}|dd} |dt} | s|j|j j g|Ri|S|j j |i||j | | fdSdS)zKCall a DBus method. :return: a result of the call or None Nr!r%rk) r r rGrrHrIpoptuple_get_method_replyrcrr&_method_callback) rKrrrwrxrkwargsrargsr!r%rrrrjsB  z ClientObjectHandler._call_methodcs|fddg|RdS)z/A callback of an asynchronous DBus method call.cs Sr')r{rrsrKrrr+r,z6ClientObjectHandler._method_callback..Nr)rKrsr!r%rrrr|s  z$ClientObjectHandler._method_callbackc OsNz||i|}||WStyH}z||WYd}~Sd}~00dS)a Get a result of a DBus call. :param call: a callback :param args: arguments of the callback :param kwargs: keyword arguments of the callback :return: a result of the callback :raise: an exception raised by the callback N)_handle_method_result Exception_handle_method_error)rKr#r~r}resultr8rrrr{s  z%ClientObjectHandler._get_method_replycCsL|j|s||j|}|j|}|j|}||}||_|ddS)zcHandle an error of a DBus call. :param error: an exception raised during the call N)rcr6r9reZget_exception_typer@Z dbus_name)rKr8r>rr: exceptionrrrrs    z(ClientObjectHandler._handle_method_errorcCs(t|}|sdSt|dkr$|dS|S)zPHandle a result of a DBus call. :param result: a variant tuple Nr)r r=)rKrvaluesrrrrs  z)ClientObjectHandler._handle_method_resultcCs|jr|j}|qdS)z&Disconnect members of the DBus object.N)rfry)rKr!rrrr_s z&ClientObjectHandler.disconnect_members)rArBrCrDr`rrrMrOrYr-rWrprrrXrjr|r{rrr_ __classcell__rrrhrr(s$     1r)abcrr functoolsrZdasbus.client.propertyrZ dasbus.errorrZ dasbus.signalrZdasbus.constantsrZdasbus.specificationr Z dasbus.typingr r r ZgiZrequire_versionZ gi.repositoryrr__all__objectrrrrrrrs         y