Your IP : 3.144.99.39


Current Path : /usr/lib/python3.6/site-packages/tuned/exports/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/tuned/exports/__pycache__/dbus_exporter.cpython-36.pyc

3

�<�eO�@sddlmZddlZddlZddlZddlZddlZddlZ	ddl
jZddlZddl
Z
ddlmZddlmZddlmZddlmZddlmZdd	lmZydd
lmZdd�ZWn ek
r�dd
lmZYnXe	jj�Zdd�ZGdd�dej �Z!dS)�)�
interfaces�N)�ismethod)�polkit)�GLib)�FunctionType)�
DBusException)�ErrorMessage)�getfullargspeccCst|�S)N)r
)�func�r�#/usr/lib/python3.6/dbus_exporter.py�
getargspecsr)rcCs�t|dd�}|dk	rn0t|dd�dkr4d|jj}nd|j|jjf}t|t�rZ|j�}ndjtj	|j|��}t
|||�}|j�s�|j|�dS)NZ_dbus_error_name�
__module__��__main__zorg.freedesktop.DBus.Python.%sz!org.freedesktop.DBus.Python.%s.%s)rr)
�getattr�	__class__�__name__r�
isinstancerZget_dbus_message�join�	traceback�format_exception_onlyr	Zget_no_replyZsend_message)Z
connection�messageZ	exception�name�contentsZreplyrrr
�_method_reply_error$s

rc@s�eZdZdZdd�Zedd��Zedd��Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�DBusExportera+
	Export method calls through DBus Interface.

	We take a method to be exported and create a simple wrapper function
	to call it. This is required as we need the original function to be
	bound to the original object instance. While the wrapper will be bound
	to an object we dynamically construct.
	cCs�tj�tjkrttj_tjjj	dd�d|_
d|_i|_t
�|_||_||_||_||_d|_d|_t�|_tjtj�}tj�|_tjtj|�dS)NT)Zset_as_default)�logZgetEffectiveLevel�logging�DEBUGr�dbus�serviceZmainloopZglibZ
DBusGMainLoop�_dbus_object_clsZ_dbus_object�
_dbus_methods�set�_signals�	_bus_name�_interface_name�_object_name�
_namespace�_thread�_bus_objectr�_polkit�signal�	getsignal�SIGINTrZMainLoop�
_main_loop)�self�bus_name�interface_name�object_name�	namespaceZsignal_handlerrrr
�__init__Bs"
zDBusExporter.__init__cCs|jS)N)r')r2rrr
r3`szDBusExporter.bus_namecCs|jS)N)r()r2rrr
r4dszDBusExporter.interface_namecCs|jS)N)r))r2rrr
r5hszDBusExporter.object_namecCs
|jdk	S)N)r+)r2rrr
�runninglszDBusExporter.runningcCsNdj|jdjt|j�j�d�}t|dt|j�d�}t	|j
dt�|j�}|S)Nz2def {name}({args}):
					return wrapper({args})
		z, )r�argsz<decorator-gen-%d>�execr)�formatrrr�__func__r9�compile�lenr$r�	co_consts�locals)r2�method�wrapper�source�coderrrr
�_prepare_for_dbusoszDBusExporter._prepare_for_dbuscsjt��std���j}|�jkr(td����fdd�}�j�|�}tjj�j||dd�|�}|�j|<dS)Nz#Only bound methods can be exported.z*Method with this name is already exported.cs
�jd�j}|d}tjd||f��jj||�}|}|dkrXtjd||f�n�|dkrttjd||f�n�|dkr�tjd||f�t|dd
��d	g}nZ|dkr�tjd
||f�t|dd��d	g}n(tj	d||f�t|dd��d	g}�||�S)N�.rz?checking authorization for action '%s' requested by caller '%s'zJaction '%s' requested by caller '%s' was successfully authorized by polkit�zepolkit error, but action '%s' requested by caller '%s' was successfully authorized by fallback methodrzLaction '%s' requested by caller '%s' wasn't authorized, ignoring the requestrzppolkit error and action '%s' requested by caller '%s' wasn't authorized by fallback method, ignoring the requestzvpolkit error and unable to use fallback method to authorize action '%s' requested by caller '%s', ignoring the request���rHrHrHrH)
r*rr�debugr-Zcheck_authorization�warn�info�list�error)�ownerr9�kwargsZ	action_id�caller�retZ	args_copy)rAr2rr
rB�s$z$DBusExporter.export.<locals>.wrapperrP)Zsender_keyword)	r�	Exceptionrr$rEr!r"rAr()r2rAZin_signature�
out_signature�method_namerBr)rAr2r
�export}s
zDBusExporter.exportcsnt��std���j}||jkr(td���fdd�}|j�|�}tjj|j|�|�}||j|<|j	j
|�dS)Nz#Only bound methods can be exported.z*Method with this name is already exported.cs
�||�S)Nr)rNr9rO)rArr
rB�sz$DBusExporter.signal.<locals>.wrapper)rrRrr$rEr!r"r.r(r&�add)r2rArSrTrBr)rAr
r.�s

zDBusExporter.signalcOsfd}||jks|jdkrd}yt|j|�}Wntk
rDd}YnX|rXtd|��n
|||�dS)NFTzSignal '%s' doesn't exist.)r&r,r�AttributeErrorrR)r2r.r9rO�errrArrr
�send_signal�s
zDBusExporter.send_signalcCs<|jdk	rtd��dt|�}t|tjjf|j�}||_dS)Nz%The exporter class was already build.zDBusExporter_%d)r#rR�id�typer!r"ZObjectr$)r2Zunique_name�clsrrr
�_construct_dbus_object_class�s

z)DBusExporter._construct_dbus_object_classcCsn|j�rdS|jdkr|j�|j�tj�}tjj|j|�}|j||j	|�|_
tj|j
d�|_|jj�dS)N)�target)r8r#r]�stopr!Z	SystemBusr"ZBusNamer'r)r,�	threadingZThread�_thread_coder+�start)r2Zbusr3rrr
rb�s
zDBusExporter.startcCs2|jdk	r.|jj�r.|jj�|jj�d|_dS)N)r+Zis_aliver1�quitr)r2rrr
r_�s

zDBusExporter.stopcCs|jj�|`d|_dS)N)r1Zrunr,)r2rrr
ra�s
zDBusExporter._thread_codeN)rr�__qualname__�__doc__r7�propertyr3r4r5r8rErUr.rYr]rbr_rarrrr
r8s"
	
r)"rrZdbus.servicer!Zdbus.mainloop.glibZdbus.exceptionsr`r.Z
tuned.logsZtunedZtuned.constsZconstsrr�inspectrZtuned.utils.polkitrZ
gi.repositoryr�typesrrZ
dbus.lowlevelr	r
r�ImportErrorZlogs�getrrZExporterInterfacerrrrr
�<module>s.



?>