a F `*@sddlZddlZddlmZmZddlmZmZddlm Z m Z ddl m Z ddl mZddlZedddd lmZeeZgd ZGd d d eZGd ddedZGdddeZGdddeZGdddeZGdddeZdS)N)ABCMetaabstractmethod) DBUS_NAME_FLAG_ALLOW_REPLACEMENT%DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) ObjectProxyInterfaceProxy) ErrorMapper)ServerObjectHandlerGioz2.0)r )GLibConnection MessageBusSystemMessageBusSessionMessageBusAddressedMessageBusc@sPeZdZdZejjejjBZe d ddZ e d ddZ e eddfddZ dS) r z4The low-level DBus connection library based on GLib.NcCstdttjj|S)zGet a system bus connection.Connecting to the system bus.)loginfor bus_get_syncBusTypeZSYSTEM cancellabler5/usr/lib/python3.9/site-packages/dasbus/connection.pyget_system_bus_connection6s  z(GLibConnection.get_system_bus_connectioncCstdttjj|S)zGet a session bus connection.Connecting to the session bus.)rrr rrZSESSIONrrrrget_session_bus_connection?s  z)GLibConnection.get_session_bus_connectioncCstj||||S)3Get a connection to a bus at the specified address.)r ZDBusConnectionZnew_for_address_sync)Z bus_addressflagsZobserverrrrrget_addressed_bus_connectionHs z+GLibConnection.get_addressed_bus_connection)N)N) __name__ __module__ __qualname____doc__r ZDBusConnectionFlagsZAUTHENTICATION_CLIENTZMESSAGE_BUS_CONNECTIONZ DEFAULT_FLAGS staticmethodrrrrrrrr .s  r c@sZeZdZdZeeddZddZedddZed d Z ed d Z ed dZ dS)AbstractMessageBusa Abstract representation of a message bus. The property connection represents a connection to the bus. You can register a service name with register_service, or publish an object with publish_object and get a proxy of a remote object with get_proxy. cCsdS)The DBus connection.Nrselfrrr connection\szAbstractMessageBus.connectionc CsDz |jduWSty>}ztd|WYd}~dSd}~00dS)znCheck if the connection is set up. :return: True if the connection is set up otherwise False NzConnection can't be created: %sF)r( ExceptionrZwarning)r'errrcheck_connectionbs   z#AbstractMessageBus.check_connectionNcKsdS)aReturns a proxy of a remote DBus object. :param service_name: a DBus name of a service :param object_path: a DBus path of an object :param interface_name: a DBus name of an interface or None :return: a proxy object Nr)r' service_name object_pathinterface_namekwargsrrr get_proxyms zAbstractMessageBus.get_proxycKsdS)aRegister a service on DBus. A service can be registered by requesting its name on DBus. This method should be called only after all of the required objects of the service are published on DBus. :param service_name: a DBus name of a service Nr)r'r,r/rrrregister_serviceys z#AbstractMessageBus.register_servicecKsdS)zPublish an object on DBus. :param object_path: a DBus path of an object :param obj: an instance of @dbus_interface or @dbus_class Nr)r'r-objr/rrrpublish_objectsz!AbstractMessageBus.publish_objectcCsdS)Disconnect from DBus.Nrr&rrr disconnectszAbstractMessageBus.disconnect)N) rr r!r"propertyrr(r+r0r1r3r5rrrrr$Ts     r$) metaclasscs|eZdZdZdeffdd ZeddZeddZ ed d Z dd d Z d dZ e fddZefddZddZZS)r z/Representation of a message bus based on D-Bus.Ncs:t||_|pt|_d|_d|_g|_t|_ dS)zCreate a new message bus. :param error_mapper: a DBus error mapper :param provider: a provider of DBus connections N) super__init__ _providerr _error_mapper _connection_proxy_registrationsset_requested_names)r' error_mapperZprovider __class__rrr9s  zMessageBus.__init__cCs|js||_|jS)r%)r<_get_connectionr&rrrr(s zMessageBus.connectioncCsdS)zReturn a DBus connection.Nrr&rrrrDszMessageBus._get_connectioncCs|js|dd|_|jS)zThe proxy of DBus.zorg.freedesktop.DBusz/org/freedesktop/DBus)r=r0r&rrrproxys zMessageBus.proxycKs@|||s|rtnt}|r&||d<||||fd|ji|S)aReturns a proxy of a remote DBus object. If the proxy factory is not specified, we will use a default one. If the interface name is set, we will choose InterfaceProxy, otherwise ObjectProxy. If the interface name is set, we will add it to the additional arguments for the proxy factory. :param service_name: a DBus name of a service :param object_path: a DBus path of an object :param interface_name: a DBus name of an interface or None :param proxy_factory: a factory of a DBus object proxy :param proxy_arguments: additional arguments for the proxy factory :return: a proxy object r.rA)_check_service_accessrrr;)r'r,r-r.Z proxy_factoryZproxy_argumentsrrrr0s  zMessageBus.get_proxycCs4||jvrdSttur"dStd|dS)aCheck if we can access a DBus service. FIXME: This is a temporary check that should be later removed. This is useful during the transition of the Anaconda code from UI to DBus modules. This check prevents a deadlock in case that a DBus module tries to access a service, that it provides, from the main thread. :param service_name: a DBus name of a service :raises: RuntimeError if the service cannot be accessed Nz4Can't access DBus service '{}' from the main thread.)r@ threadingcurrent_thread main_thread RuntimeErrorformatr'r,rrrrFs z MessageBus._check_service_accesscsVtdj|}|tkr0td|jj fdddS)zRegister a service on DBus. :param service_name: a DBus name of a service :param flags: the flags argument of the RequestName DBus method zRegistering a service name %s.zName request has failed: {}cs jS)N)rEZ ReleaseNamerrLrr z-MessageBus.register_service..N) rdebugrEZ RequestNamerConnectionErrorrKr@addr>append)r'r,rresultrrLrr1s  zMessageBus.register_servicecCs8td||||||jd}||j|jdS)zPublish an object on DBus. :param object_path: a DBus path of an object :param obj: an instance of @dbus_interface or @dbus_class :param server_factory: a factory of a DBus server object handler zPublishing an object at %s.)rAN)rrOr;Zconnect_objectr>rRZdisconnect_object)r'r-r2Zserver_factoryZobject_handlerrrrr3s zMessageBus.publish_objectcCs4td|jr"|j}|q d|_t|_dS)r4zDisconnecting from the bus.N)rrOr>popr<r?r@)r'callbackrrrr5#s   zMessageBus.disconnect)NN)rr r!r"r r9r6r(rrDrEr0rFrr1r r3r5 __classcell__rrrBrr s"    "  r c@seZdZdZddZdS)r z*Representation of a system bus connection.cCstd|jS)zGet a system DBus connection.r)rrr:rr&rrrrD2s z SystemMessageBus._get_connectionNrr r!r"rDrrrrr /sr c@seZdZdZddZdS)rz+Representation of a session bus connection.cCstd|jS)zGet a session DBus connection.r)rrr:rr&rrrrD;s z!SessionMessageBus._get_connectionNrWrrrrr8srcs4eZdZdZfddZeddZddZZS)rz9Representation of a connection for the specified address.cstj|i|||_dS)z\Create a new representation of a connection. :param address: a bus address N)r8r9_address)r'addressargsr/rBrrr9DszAddressedMessageBus.__init__cCs|jS)zThe bus address.)rXr&rrrrYLszAddressedMessageBus.addresscCstd|j|j|jS)rzConnecting to a bus at %s.)rrrXr:rr&rrrrDQsz#AddressedMessageBus._get_connection) rr r!r"r9r6rYrDrVrrrBrrAs   r)ZloggingrGabcrrZdasbus.constantsrrZdasbus.client.proxyrrZ dasbus.errorrZdasbus.server.handlerr ZgiZrequire_versionZ gi.repositoryr Z getLoggerrr__all__objectr r$r r rrrrrrs$      &@