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))BusNameObjectFallbackObjectmethodsignalZrestructuredtextN)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__rrrnextrrrrr8src@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)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-Zs<            zBusName.__new__cOsdSNr)rargskeywordsrrr__init__szBusName.__init__cCs|j|jdSr4)r.Z release_namer/rrrr__del__szBusName.__del__cC|jS)zGet the Bus this Service is on)r.rrrrget_buszBusName.get_buscCr9)zGet the name of this service)r/rrrrget_namer;zBusName.get_namecCsd|j|jt|fS)Nz&)r/r.idrrrr__repr__szBusName.__repr__)NFFF) r r!r"r#r-r7r8r:r<r>__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 ExceptionloggingZ basicConfigZguess_signature_loggererrorrB get_no_reply send_message) connectionmessagerErHr2replyerrr_method_reply_returns0  rTc Cst|dd}|dur nt|dddvrd|jj}n d|j|jjf}t\}}}t|tr7|js7| }n||urFd t |||}n d t |j|}t|||}|sa||dSdS)NZ_dbus_error_namer!)rU__main__zorg.freedesktop.DBus.Python.%sz!org.freedesktop.DBus.Python.%s.%s)getattrrBr r!sysexc_info isinstancerZinclude_tracebackZget_dbus_messagejoin tracebackformat_exceptionformat_exception_onlyrrNrO) rPrQ exceptionr1etZevZetbcontentsrRrrr_method_reply_errors$    rbcs,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.FrA) rWrdr!r items setdefaultupdatevaluesrAsuperrcr7) r0r1basesZdctZ class_tableZinterface_tableb base_nameZ interfaceZ method_tableZour_method_tablefuncrBrrr74s       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_argsZ_dbus_in_signaturetupler r_dbus_out_signaturer zip)r0rnr5Zin_sigZout_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 )rpZ_dbus_signaturerqr rr rs)r0rnr5Zsigrtrurrr_reflect_on_signalks z InterfaceType._reflect_on_signal)r r!r"r7rwrx __classcell__rrrorrc3s rc 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)) rrr{r| LookupErrorr}rIZ_unregister_object_pathremoverr)rrPrZdroppedlocationrrrremove_from_connectionXsH        zObject.remove_from_connectioncCstd||dS)Nz5Unregistering exported object %r from some path on %r)rLinfo)rrPrrrrszObject._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|RSr4)rT)r2rPrQrErHrrsz$Object._message_cb..cs t|Sr4)rb)r_)rPrQrrrs 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)rZrZ get_memberZ get_interfacerGZ get_args_listZ_dbus_get_args_optionsrrr Z_dbus_async_callbacksZ_dbus_sender_keywordZ get_senderZ_dbus_path_keywordZget_pathZ_dbus_rel_path_keywordr} startswithlenr Z_dbus_destination_keywordZget_destinationZ_dbus_message_keywordZ_dbus_connection_keywordrqrrr rTrJrb)rrPrQZinterface_nameZcandidate_methodrFr5r6Zreturn_callbackZerror_callbackrZrel_pathZexpsuffixr2Zsignature_tupler_rrrrs                 zObject._message_cbrUsrrP)Z in_signatureZ out_signatureZ path_keywordZconnection_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 rez r@FZ_dbus_is_signalz z z ) r*Z)DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODErdrBr!r rfrirWrwrxZlist_exported_child_objects)rrrPrtZ interfacesr1Zfuncsrnrrr Introspects       zObject.IntrospectcCs>d}|jtur|jdurd|j}d|jj|jj|t|fS)NrUz at %sz<%s.%s%s at %#x>)r{rrBr!r r=)rwhererrrr>s  zObject.__repr__)NNNNN)r r!r"r#rrr7propertyrrPrrrrrrrrr>r?rrrrrs*# =    ;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)rjrr7rrr)rrrrorrr7+szFallbackObject.__init__r)r r!r"r#rr7ryrrrorr"sr)0__all__Z __docformat__rXrKr~r\Zcollections.abcr ImportError collectionsr*Zdbusrr r r r r rZdbus.decoratorsrrZdbus.exceptionsrrrZ dbus.lowlevelrrrZ dbus.proxiesrZ dbus._compatrZ getLoggerrLr,rrrGrTrbrvrcrzrrrrrrrs@ $   uBM