Mini Shell

Direktori : /lib/python3.6/site-packages/blivet/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/blivet/__pycache__/safe_dbus.cpython-36.pyc

3

{)cK �@s�dZddlZejdd�ejdd�ddlmZmZddlZdZdZd	Z	Gd
d�de
�ZGdd
�d
e�ZGdd�de�Z
dd�Zdd�Zddd�Zddd�Zddd�Zd dd�ZdS)!z?Module providing thread-safe and mainloop-safe DBus operations.�N�GLibz2.0�Gio)rr�zorg.freedesktop.DBus.Propertiesz#org.freedesktop.DBus.Introspectablec@seZdZdZdS)�
SafeDBusErrorz,Class for exceptions defined in this module.N)�__name__�
__module__�__qualname__�__doc__�r
r
�/usr/lib/python3.6/safe_dbus.pyr&src@seZdZdZdS)�
DBusCallErrorz:Class for the errors related to calling methods over DBus.N)rrrr	r
r
r
rr*src@seZdZdZdS)�DBusPropertyErrorzBClass for the errors related to getting property values over DBus.N)rrrr	r
r
r
rr
.sr
cCs*tjjtjtjjd�tjjtjjBdd�S)z*Return a new connection to the system bus.N)	r�DBusConnection�new_for_address_sync�dbus_address_get_for_bus_sync�BusTypeZSYSTEM�DBusConnectionFlags�AUTHENTICATION_CLIENT�MESSAGE_BUS_CONNECTIONr
r
r
r�get_new_system_connection2s
rcCs�d}dtjkr*tj�}tjttjd��zdy.tjjtjtj	j
d�tjjtjj
Bdd�}Wn0tjk
r�}ztd|��WYdd}~XnXWd|dk	r�tj|�X|j�r�td��|S)a�
    Get a connection handle for the per-user-login-session message bus.

    !!! RUN THIS EARLY !!! like, before any other threads start. Connections to
    the session bus must be made with the effective UID of the login user,
    which in live installs is not the UID of anaconda. This means we need to
    call seteuid in this method, and doing that after threads have started will
    probably do something weird.

    Live installs use consolehelper to run as root, which sets the original
    UID in $USERHELPER_UID.

    :return: the session connection handle
    :rtype: Gio.DBusConnection
    :raise DBusCallError: if some DBus related error appears
    :raise OSError: if unable to set the effective UID
    NZUSERHELPER_UIDz$Unable to connect to session bus: %szConnection is closed)�os�environ�geteuid�seteuid�intrrrrrZSESSIONrrrr�GErrorr�	is_closed)Zold_euid�
connection�gerrr
r
r�get_new_session_connection<s"
"rc
 Cs�|s@y
t�}Wn0tjk
r>}ztd|��WYdd}~XnX|j�rPtd��y$|j|||||dtjjt	|d�
}Wn>tjk
r�}z d||||j
f}	t|	��WYdd}~XnX|dkr�d|||f}	t|	��|dj�S)a
    Safely call a given method on a given object of a given service over DBus
    passing given arguments. If a connection is given, it is used, otherwise a
    new connection is established. Safely means that it is a synchronous,
    thread-safe call not using any main loop.

    :param service: DBus service to use
    :type service: str
    :param obj_path: object path of the object to call method on
    :type obj_path: str
    :param iface: interface to use
    :type iface: str
    :param method: name of the method to call
    :type method: str
    :param args: arguments to pass to the method
    :type args: GVariant
    :param connection: connection to use (if None, a new connection is
                       established)
    :type connection: Gio.DBusConnection
    :param fds: list of file descriptors for the call
    :type: Gio.UnixFDList
    :return: unpacked value returned by the method
    :rtype: tuple with elements that depend on the method
    :raise DBusCallError: if some DBus related error appears

    z#Unable to connect to system bus: %sNzConnection is closedz4Failed to call %s method on %s with %s arguments: %sz0No return from %s method on %s with %s argumentsr)rrrrrZcall_with_unix_fd_list_syncrZ
DBusCallFlagsZNONE�DEFAULT_DBUS_TIMEOUT�message�unpack)
�service�obj_path�iface�method�argsrZfdsr�ret�msgr
r
r�	call_syncfs&
r*cCsBtjd||f�}t||td||�}|dkr>d||f}t|��|S)a?
    Get value of a given property of a given object provided by a given service.

    :param service: DBus service to use
    :type service: str
    :param obj_path: object path
    :type obj_path: str
    :param iface: interface to use
    :type iface: str
    :param prop_name: name of the property
    :type prop_name: str
    :param connection: connection to use (if None, a new connection is
                       established)
    :type connection: Gio.DBusConnection
    :return: unpacked value of the property
    :rtype: tuple with elements that depend on the type of the property
    :raise DBusCallError: when the internal dbus_call_safe_sync invocation
                          raises an exception
    :raise DBusPropertyError: when the given object doesn't have the given
                              property

    z(ss)ZGetNz(No value for the %s object's property %s)r�Variantr*�DBUS_PROPS_IFACEr
)r#r$r%Z	prop_namerr'r(r)r
r
r�get_property_sync�sr-cCs$tjd|f�}t||td||�}|S)a~
    Get all properties of a given object provided by a given service.

    :param service: DBus service to use
    :type service: str
    :param obj_path: object path
    :type obj_path: str
    :param iface: interface to use
    :type iface: str
    :param connection: connection to use (if None, a new connection is
                       established)
    :type connection: Gio.DBusConnection
    :return: unpacked value of the property
    :rtype: tuple with elements that depend on the type of the property
    :raise DBusCallError: when the internal dbus_call_safe_sync invocation
                          raises an exception

    z(s)ZGetAll)rr+r*r,)r#r$r%rr'r(r
r
r�get_properties_sync�sr.csJt||tdd�}tjj|d�}�s.t|j�St�fdd�|jD��SdS)NZ
Introspectrc3s|]}|j�kVqdS)N)�name)�.0Zintface)r%r
r�	<genexpr>�sz)check_object_available.<locals>.<genexpr>)r*�DBUS_INTRO_IFACErZDBusNodeInfoZnew_for_xml�boolZ
interfaces�any)r#r$r%Z
intro_dataZ	node_infor
)r%r�check_object_available�s

r5���)NN)N)N)N)r	ZgiZrequire_versionZ
gi.repositoryrrrr r,r2�	Exceptionrrr
rrr*r-r.r5r
r
r
r�<module>s"
+
6
"