3 iRV@s:dZdZddlZddlZddlZddlZddlmZddlZdd l m Z m Z m Z m Z mZmZmZdd lmZmZdd lmZmZmZdd lmZmZmZdd lmZddlmZej dZ!Gddde"Z#Gddde"Z$ddZ%ddZ&ddZ'Gddde(Z)e)de"fiZ*e"Z+Gddde*Z,Gddde,Z-dS)BusNameObjectFallbackObjectmethodsignalZrestructuredtextN)Sequence)INTROSPECTABLE_IFACE ObjectPath SessionBus SignatureStructvalidate_bus_namevalidate_object_path)rr) DBusExceptionNameExistsExceptionUnknownMethodException) ErrorMessageMethodReturnMessageMethodCallMessage) LOCAL_PATH)is_py2z dbus.servicec@s(eZdZdZddZddZer$eZdS)_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/lib64/python3.6/service.py__iter__8sz_VariantSignature.__iter__cCsdS)zReturn 'v' whenever called.vr)rrrr__next__<sz_VariantSignature.__next__N)__name__ __module__ __qualname____doc__rrrnextrrrrr2s rc@sFeZdZdZdddZddZdd Zd d Zd d ZddZ e Z dS)ra^A 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|dkr4ddl}|jdtddt}||jkrH|j|S|rRtjpTd|r^tjp`dB|rltj pndB}|j ||}|tj krn<|tj krn0|tj krt|n|tjkrntd ||ftj|} || _|| _| |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)Zallow_well_knownZ allow_uniqueNrzKOmitting the "bus" parameter to dbus.service.BusName.__init__ is deprecated) stacklevelz3requesting bus name %s returned unexpected value %s)r warningswarnDeprecationWarningr Z _bus_names_dbus_bindingsZNAME_FLAG_ALLOW_REPLACEMENTZNAME_FLAG_REPLACE_EXISTINGZNAME_FLAG_DO_NOT_QUEUEZ request_nameZ REQUEST_NAME_REPLY_PRIMARY_OWNERZREQUEST_NAME_REPLY_IN_QUEUEZREQUEST_NAME_REPLY_EXISTSrZ REQUEST_NAME_REPLY_ALREADY_OWNER RuntimeErrorobject__new___bus_name) clsnameZbusZallow_replacementZreplace_existingZ do_not_queuer%Z name_flagsretvalbus_namerrrr+Ts2           zBusName.__new__cOsdS)Nr)rargskeywordsrrr__init__szBusName.__init__cCs|jj|jdS)N)r,Z release_namer-)rrrr__del__szBusName.__del__cCs|jS)zGet the Bus this Service is on)r,)rrrrget_busszBusName.get_buscCs|jS)zGet the name of this service)r-)rrrrget_nameszBusName.get_namecCsd|j|jt|fS)Nz&)r-r,id)rrrr__repr__szBusName.__repr__)NFFF) rrr r!r+r4r5r6r7r9__str__rrrrrDs OcCs^d}d}d}|rx|jjD]}| rz||jkrzd|j|jkrvd|j|jkrv|j|j|krz|}|j|}d}Pqzn|}|r||jkrd|j|jkrd|j|jkr|j|j|kr|j|}d}PqWnTxR|jjD]F}| r||jkr|}|r||jkrd|j|jkr|j|}d}PqW|r6|j||fS|rNtd||fn td|dS)zWalks the Python MRO of the given class to find the method to invoke. Returns two methods, the one to call, and the one it inherits from which defines its D-Bus interface name, signature, and attributes. NF_dbus_is_method_dbus_interfaceTz(%s is not a valid method of interface %sz%s is not a valid method) __class____mro____dict__r<r)r method_nameZdbus_interface parent_methodZcandidate_classZ successfulr.rrr_method_lookupsF   rBc Gst|}y|j|d|iWntk r}zvtj|dkry|j|d}Wn6tk r}ztjd||j|WYdd}~XnXtjd|||j|WYdd}~XnX|j |dS)N signaturez (guessed)z2Unable to guess signature for arguments %r: %s: %sz8Unable to append %r to message with signature %s: %s: %s) rappend ExceptionloggingZ basicConfigZguess_signature_loggererrorr= send_message) connectionmessager@rCr0replyerrr_method_reply_returns  rNc Cst|dd}|dk rn0t|dddkr4d|jj}nd|j|jjf}tj\}}}t|trp|j rp|j }n2||krdj t j |||}ndj t j |j|}t|||}|j|dS)NZ_dbus_error_namer__main__zorg.freedesktop.DBus.Python.%sz!org.freedesktop.DBus.Python.%s.%s)rOrP)getattrr=rrsysexc_info isinstancerZinclude_tracebackZget_dbus_messagejoin tracebackformat_exceptionformat_exception_onlyrrI) rJrK exceptionr/ZetZevZetbcontentsrLrrr_method_reply_errors    r[cs,eZdZfddZddZddZZS) InterfaceTypec st|di}||_i}||jd|<xX|D]P}|jd|j}t|ddr.x.||jD]\}} |j|i} | j| q\Wq.Wx4|jD](} t| ddr|j| ji} | | | j<qWt t |j |||dS)N_dbus_class_table.Fr<) rQr]rritems setdefaultupdatevaluesr<superr\r4) r.r/basesZdctZ class_tableZinterface_tablebZ base_nameZ interfaceZ method_tableZour_method_tablefunc)r=rrr4,s     zInterfaceType.__init__cCs|j}|jrtt|j}nt}|jr4t|j}ng}d|j}xt||D]}|d|7}qNWx|D]}|d|7}qhW|d7}|S)Nz z2 z( z ) _dbus_argsZ_dbus_in_signaturetupler r_dbus_out_signaturerzip)r.rfr2Zin_sigZout_sigreflection_datapairtyperrr_reflect_on_methodFs   z InterfaceType._reflect_on_methodcCsX|j}|jrtt|j}nt}d|j}xt||D]}|d|}q8W|d}|S)Nz z" z )rgZ_dbus_signaturerhr rrrj)r.rfr2Zsigrkrlrrr_reflect_on_signalcs z InterfaceType._reflect_on_signal)rrr r4rnro __classcell__rr)r=rr\+s 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|dk rt|t|tr(|}|j}n|dkr@|dk r@|j}d|_d|_g|_tj|_ d|_ ||_ |dkr|dk rt d|dk r|dk r|j ||dS)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|dk rg}xN|jD]6}|dksb|d|krJ|dksv|d|krJ|j|qJWn |j}g|_|std|||fxf|D]^}y|dj|dWntk rYnX|jry|jj|Wqt k r YqXqWWd|jj XdS)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)) rvrrrrs LookupErrorrtrDZ_unregister_object_pathremoverr)rrJrZdroppedlocationrrrremove_from_connectionPs4    zObject.remove_from_connectioncCstjd||dS)Nz5Unregistering exported object %r from some path on %r)rGinfo)rrJrrrrszObject._unregister_cbcsttsdSy`jj}t||\}}jf|j}i}|jdk rZt|jnd|j r|j \}} fdd||<fdd|| <|j rj ||j <|j rj ||j <|jr^j } | } xx|jD]n} | dkr| | dkrd} P| ddkrq| j| ddr| t| dd} t| t| kr| } qWt| } | ||j<|jrtj||j<|jr||j<|jr||j<||f||}|j rdSdk r(t}t|dkr|dkrf}n tdn4t|dkr|f}nt|trntdfn2|dkr8f}n"t|trTt|t rTn|f}tf|Wn0tk r}zt|WYdd}~XnXdS) Ncstf|S)N)rN)r0)rJrKr@rCrrsz$Object._message_cb..cs t|S)N)r[)rY)rJrKrrrsrr/z8%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)rTrZ get_memberZ get_interfacerBZ get_args_listZ_dbus_get_args_optionsrir Z_dbus_async_callbacksZ_dbus_sender_keywordZ get_senderZ_dbus_path_keywordget_pathZ_dbus_rel_path_keywordrt startswithlenr Z_dbus_destination_keywordZget_destinationZ_dbus_message_keywordZ_dbus_connection_keywordrhrxrr rNrEr[)rrJrKZinterface_nameZcandidate_methodrAr2r3Zreturn_callbackZerror_callbackrZrel_pathZexpsuffixr0Zsignature_tuplerYr)rJrKr@rCrrs               zObject._message_cbrOsr{rJ)Z in_signatureZ out_signatureZ path_keywordZconnection_keywordcCstj}|d|7}|j|jjd|jj}xt|jD]h\}}|d|7}xJ|jD]>}t|ddrv||jj |7}qTt|ddrT||jj |7}qTW|d7}q6Wx|j |D]}|d|7}qW|d 7}|S) ziReturn a string of XML encoding this object's supported interfaces, methods and signals. z r^z r;FZ_dbus_is_signalz z z ) r(Z)DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODEr]r=rrr_rbrQrnroZlist_exported_child_objects)rr{rJrkZ interfacesr/Zfuncsrfrrr Introspects     zObject.IntrospectcCs>d}|jtk r"|jdk r"d|j}d|jj|jj|t|fS)NrOz at %sz<%s.%s%s at %#x>)rrr|r=rrr8)rwhererrrr9s   zObject.__repr__)NNN)NN)rrr r!rrr4propertyr~rJrryrrrrrrr9r:rrrrrs =   ; 1ncs&eZdZdZdZdfdd ZZS)rzaAn object that implements an entire subtree of the object-path tree. :Since: 0.82.0 TNcsPtt|jd|_|dkr.|dk rLtdn|dkr@tdn |j||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)rcrr4rwrxry)rrzr{)r=rrr4#s  zFallbackObject.__init__)NN)rrr r!rr4rprr)r=rrs)rrrrr).__all__Z __docformat__rRrFrurV collectionsrr(Zdbusrr r r r r rZdbus.decoratorsrrZdbus.exceptionsrrrZ dbus.lowlevelrrrZ dbus.proxiesrZ dbus._compatrZ getLoggerrGr*rrrBrNr[rmr\rqr|rrrrrrs6 $   uBM