o t3b@s^dZdZddlZddlZddlZddlZzddlmZWney+ddl mZYnwddl Z ddl m Z m Z mZmZmZmZmZddlmZmZddlmZmZmZddlmZmZmZdd lmZdd l m!Z!e"d Z#Gd d d e$Z%Gddde$Z&ddZ'ddZ(ddZ)Gddde*Z+e+de$fiZ,e$Z-Gddde,Z.Gddde.Z/dS))BusNameObjectFallbackObjectmethodsignalrestructuredtextN)Sequence)INTROSPECTABLE_IFACE ObjectPath SessionBus SignatureStructvalidate_bus_namevalidate_object_path)rr) DBusExceptionNameExistsExceptionUnknownMethodException) ErrorMessageMethodReturnMessageMethodCallMessage) LOCAL_PATH)is_py2z dbus.servicec@s,eZdZdZddZddZereZdSdS)_VariantSignaturezA fake method signature which, when iterated, yields an endless stream of 'v' characters representing variants (handy with zip()). It has no string representation. cCs|S)z Return self.selfrr./usr/lib/python3/dist-packages/dbus/service.py__iter__>z_VariantSignature.__iter__cCsdS)zReturn 'v' whenever called.vrrrrr__next__Brz_VariantSignature.__next__N)__name__ __module__ __qualname____doc__rr rnextrrrrr8src@sFeZdZdZdddZddZdd Zd d Zd d ZddZ e Z dS)raaA base class for exporting your own Named Services across the Bus. When instantiated, objects of this class attempt to claim the given well-known name on the given bus for the current process. The name is released when the BusName object becomes unreferenced. If a well-known name is requested multiple times, multiple references to the same BusName object will be returned. :Caveats: - Assumes that named services are only ever requested using this class - if you request names from the bus directly, confusion may occur. - Does not handle queueing. NFc Cst|ddd|durddl}|jdtddt}||jvr$|j|S|r)tjp*d|r/tjp0dB|r6tj p7dB}| ||}|tj krEn|tj krKn|tj krTt||tjkrZntd ||ft|} || _|| _| |j|<| S) aSConstructor, which may either return an existing cached object or a new object. :Parameters: `name` : str The well-known name to be advertised `bus` : dbus.Bus A Bus on which this service will be advertised. Omitting this parameter or setting it to None has been deprecated since version 0.82.1. For backwards compatibility, if this is done, the global shared connection to the session bus will be used. `allow_replacement` : bool If True, other processes trying to claim the same well-known name will take precedence over this one. `replace_existing` : bool If True, this process can take over the well-known name from other processes already holding it. `do_not_queue` : bool If True, this service will not be placed in the queue of services waiting for the requested name if another service already holds it. TF)allow_well_known allow_uniqueNrzKOmitting the "bus" parameter to dbus.service.BusName.__init__ is deprecated) stacklevelz3requesting bus name %s returned unexpected value %s)rwarningswarnDeprecationWarningr _bus_names_dbus_bindingsNAME_FLAG_ALLOW_REPLACEMENTNAME_FLAG_REPLACE_EXISTINGNAME_FLAG_DO_NOT_QUEUE request_name REQUEST_NAME_REPLY_PRIMARY_OWNERREQUEST_NAME_REPLY_IN_QUEUEREQUEST_NAME_REPLY_EXISTSr REQUEST_NAME_REPLY_ALREADY_OWNER RuntimeErrorobject__new___bus_name) clsnamebusallow_replacementreplace_existing do_not_queuer* name_flagsretvalbus_namerrrr9Zs<            zBusName.__new__cOsdSNr)rargskeywordsrrr__init__szBusName.__init__cCs|j|jdSrE)r: release_namer;rrrr__del__szBusName.__del__cC|jS)zGet the Bus this Service is on)r:rrrrget_buszBusName.get_buscCrK)zGet the name of this service)r;rrrrget_namerMzBusName.get_namecCsd|j|jt|fS)Nz&)r;r:idrrrr__repr__szBusName.__repr__)NFFF) r!r"r#r$r9rHrJrLrNrP__str__rrrrrJs OrcCsNd}d}d}|rf|jjD]X}|s<||jvrz ||d}Wnty=}z td||j|d}~wwtd|||j|d}~ww| sY| |dSdS)N signaturez (guessed)z2Unable to guess signature for arguments %r: %s: %sz8Unable to append %r to message with signature %s: %s: %s) rappend Exceptionlogging basicConfigguess_signature_loggererrorrT get_no_reply send_message) connectionmessagerWr]rCreplyerrr_method_reply_returns0  rkc Cst|dd}|dur nt|dddvrd|jj}n d|j|jjf}t\}}}t|tr7|js7| }n||urFd t |||}n d t |j|}t|||}|sa||dSdS)N_dbus_error_namer")rm__main__zorg.freedesktop.DBus.Python.%sz!org.freedesktop.DBus.Python.%s.%s)getattrrTr!r"sysexc_info isinstancerinclude_tracebackget_dbus_messagejoin tracebackformat_exceptionformat_exception_onlyrrerf) rgrh exceptionr=etevetbcontentsrirrr_method_reply_errors$    r~cs,eZdZfddZddZddZZS) InterfaceTypec st|di}||_i}||jd|<|D]&}|jd|j}t|ddr<||D]\}} ||i} | | q,q|D]} t| ddrU|| ji} | | | j<qAt t | |||dS)N_dbus_class_table.FrS) rorr"r!items setdefaultupdatevaluesrSsuperrrH) r<r=basesdct class_tableinterface_tableb base_name interface method_tableour_method_tablefuncrTrrrH4s       zInterfaceType.__init__cCs|j}|jrtt|j}nt}|jrt|j}ng}d|j}t||D]}|d|7}q&|D]}|d|7}q1|d7}|S)Nz z2 z( z ) _dbus_args_dbus_in_signaturetupler r_dbus_out_signaturer!zip)r<rrFin_sigout_sigreflection_datapairtyperrr_reflect_on_methodNs  z InterfaceType._reflect_on_methodcCsT|j}|jrtt|j}nt}d|j}t||D]}|d|}q|d}|S)Nz z" z )r_dbus_signaturerr rr!r)r<rrFsigrrrrr_reflect_on_signalks z InterfaceType._reflect_on_signal)r!r"r#rHrr __classcell__rrrrr3s r Interfacec@seZdZdZdZdZdddZeddZedd Z ed d Z d d Z dddZ ddZ ddZeedddddddZddZeZdS)raA base class for exporting your own Objects across the Bus. Just inherit from Object and mark exported methods with the @\ `dbus.service.method` or @\ `dbus.service.signal` decorator. Example:: class Example(dbus.service.object): def __init__(self, object_path): dbus.service.Object.__init__(self, dbus.SessionBus(), path) self._last_input = None @dbus.service.method(interface='com.example.Sample', in_signature='v', out_signature='s') def StringifyVariant(self, var): self.LastInputChanged(var) # emits the signal return str(var) @dbus.service.signal(interface='com.example.Sample', signature='v') def LastInputChanged(self, var): # run just before the signal is actually emitted # just put "pass" if nothing should happen self._last_input = var @dbus.service.method(interface='com.example.Sample', in_signature='', out_signature='v') def GetLastInput(self): return self._last_input FNcCs|durt|t|tr|}|}n |dur |dur |}d|_d|_g|_t|_ d|_ ||_ |dur@|dur@t d|durP|durR| ||dSdSdS)aConstructor. Either conn or bus_name is required; object_path is also required. :Parameters: `conn` : dbus.connection.Connection or None The connection on which to export this object. If None, use the Bus associated with the given ``bus_name``. If there is no ``bus_name`` either, the object is not initially available on any Connection. For backwards compatibility, if an instance of dbus.service.BusName is passed as the first parameter, this is equivalent to passing its associated Bus as ``conn``, and passing the BusName itself as ``bus_name``. `object_path` : str or None A D-Bus object path at which to make this Object available immediately. If this is not None, a `conn` or `bus_name` must also be provided. `bus_name` : dbus.service.BusName or None Represents a well-known name claimed by this process. A reference to the BusName object will be held by this Object, preventing the name from being released during this Object's lifetime (unless it's released manually). NFz|dus9|d|kr>||q#n|j}g|_|sQtd|||f|D],}z |d|dWn tyiYnw|jrz|j|WqSt y~YqSwqSW|j dS|j w)aMake this object inaccessible via the given D-Bus connection and object path. If no connection or path is specified, the object ceases to be accessible via any connection or path. :Parameters: `connection` : dbus.connection.Connection or None Only remove the object from this Connection. If None, remove from all Connections on which it's exported. `path` : dbus.ObjectPath or other str, or None Only remove the object from this object path. If None, remove from all object paths. :Raises LookupError: if the object was not exported on the requested connection or path, or (if both are None) was not exported at all. :Since: 0.81.1 Nz%r is not exportedrz1%r is not exported at a location matching (%r,%r)) rrrr LookupErrorrr^_unregister_object_pathremoverr)rrgrdroppedlocationrrrremove_from_connectionXsB       zObject.remove_from_connectioncCstd||dS)Nz5Unregistering exported object %r from some path on %r)rcinfo)rrgrrrrszObject._unregister_cbc sttsdSz*}t||\}}jdi|j}i}|jdur/t|jnd|j rM|j \}} fdd||<fdd|| <|j rW ||j <|j ra ||j <|jr } | } |jD]6} | dur| | dkrd} n%| ddkrqm| | ddr| t| dd} t| t| kr| } qmt| } | ||j<|jr||j<|jr||j<|jrLj||j<||g|Ri|}|j rWdSdur t}t|dkr|dkrd}n7tdt|dkr|f}n't|trn td f|durd}nt|tr"t|ts"n|f}tg|RWdStyL}z t|WYd}~dSd}~ww) Ncstg|RSrE)rk)rCrgrhrWr]rrsz$Object._message_cb..cs t|SrE)r~)ry)rgrhrrrs rr/rz8%s has an empty output signature but did not return NonezK%s has multiple output values in signature %s but did not return a sequence)rrr get_member get_interfacer\ get_args_list_dbus_get_args_optionsrr _dbus_async_callbacks_dbus_sender_keyword get_sender_dbus_path_keywordget_path_dbus_rel_path_keywordr startswithlenr _dbus_destination_keywordget_destination_dbus_message_keyword_dbus_connection_keywordrrrr rkr_r~)rrgrhinterface_namecandidate_methodrYrFrGreturn_callbackerror_callbackrrel_pathexpsuffixrCsignature_tupleryrrrrs                 zObject._message_cbrmsrrg) in_signature out_signature path_keywordconnection_keywordcCstj}|d|7}|j|jjd|jj}|D]2\}}|d|7}|D]}t|ddr9||j |7}q(t|ddrG||j |7}q(|d7}q| |D]}|d|7}qR|d 7}|S) ziReturn a string of XML encoding this object's supported interfaces, methods and signals. z rz rRF_dbus_is_signalz z z ) r.)DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODErrTr"r!rrrorrlist_exported_child_objects)rrrgr interfacesr=funcsrrrr Introspects       zObject.IntrospectcCs>d}|jtur|jdurd|j}d|jj|jj|t|fS)Nrmz at %sz<%s.%s%s at %#x>)rrrTr"r!rO)rwhererrrrPs   zObject.__repr__)NNNNN)r!r"r#r$rrrHpropertyrrgrrrrrrr rrPrQrrrrrs*# =    ;1n rcs&eZdZdZdZdfdd ZZS)rzaAn object that implements an entire subtree of the object-path tree. :Since: 0.82.0 TNcsPtt|d|_|dur|durtddS|dur td|||dS)aHConstructor. Note that the superclass' ``bus_name`` __init__ argument is not supported here. :Parameters: `conn` : dbus.connection.Connection or None The connection on which to export this object. If this is not None, an `object_path` must also be provided. If None, the object is not initially available on any Connection. `object_path` : str or None A D-Bus object path at which to make this Object available immediately. If this is not None, a `conn` must also be provided. This object will implements all object-paths in the subtree starting at this object-path, except where a more specific object has been added. TNz)If object_path is given, conn is requiredz)If conn is given, object_path is required)rrrHrrr)rrrrrrrH+szFallbackObject.__init__r)r!r"r#r$rrHrrrrrr"sr)0__all__ __docformat__rpr`rrvcollections.abcr ImportError collectionsr.dbusr r r r r rrdbus.decoratorsrrdbus.exceptionsrrr dbus.lowlevelrrr dbus.proxiesr dbus._compatr getLoggerrcr8rrr\rkr~rrrrrrrrrrs@ $   uBM