Your IP : 18.223.238.150


Current Path : /usr/lib/python3.6/site-packages/slip/dbus/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/slip/dbus/__pycache__/polkit.cpython-36.pyc

3

�uAcI$�@s�dZddlmZddlZddlZddlmZddlmZddlm	Z	dd	d
ddd
gZ
dd�ZdZGdd
�d
e
�Zdeddfdd	�ZGdd�dej�ZGdd�de
�Ze�Zdd�Zdifdd
�ZdS)zmThis module contains convenience decorators and functions for using
PolicyKit with dbus services and clients.�)�absolute_importN)�	decorator)�reduce�)�method_call_no_timeout�require_auth�enable_proxy�AUTHFAIL_DONTCATCH�NotAuthorizedException�AreAuthorizationsObtainable�IsSystemBusNameAuthorizedAsynccs�fdd�}|S)u�Decorator for DBus service methods.

    Specify that a user needs a specific PolicyKit authorization `polkit_auth´
    to execute it.cst|d�st�t|d��|S)NZ_dbus_is_methodZ_slip_polkit_auth_required)�hasattr�AssertionError�setattr)�method)�polkit_auth��/usr/lib/python3.6/polkit.py�require_auth_decorator/sz,require_auth.<locals>.require_auth_decoratorr)rrr)rrr)szBorg.fedoraproject.slip.dbus.service.PolKit.NotAuthorizedException.c@seZdZdS)r	N)�__name__�
__module__�__qualname__rrrrr	<scs�|dkst|tj�st��dtfks0�dks0t��dksHt�tj�sHt��dks^t�t�s^t����fdd��|dk	r�t�|�S�fdd�}|SdS)u�Decorator for DBus proxy methods.

    Let's you (optionally) specify either a result value or an exception type
    and a callback which is returned, thrown or called respectively if a
    PolicyKit authorization doesn't exist or can't be obtained in the DBus
    mechanism, i.e. an appropriate DBus exception is thrown.

    An exception constructor may and a callback must accept an `action_id´
    parameter which will be set to the id of the PolicyKit action for which
    authorization could not be obtained.

    Examples:

    1) Return `False´ in the event of an authorization problem, and call
    `error_handler´:

        def error_handler(action_id=None):
            print "Authorization problem:", action_id

        class MyProxy(object):
            @polkit.enable_proxy(authfail_result=False,
                                 authfail_callback=error_handler)
            def some_method(self, ...):
                ...

    2) Throw a `MyAuthError´ instance in the event of an authorization problem:

        class MyAuthError(Exception):
            def __init__(self, *args, **kwargs):
                action_id = kwargs.pop("action_id")
                super(MyAuthError, self).__init__(*args, **kwargs)
                self.action_id = action_id

        class MyProxy(object):
            @polkit.enable_proxy(authfail_exception=MyAuthError)
            def some_method(self, ...):
                ...Ncs�y
|||�Stjk
r�}zr|j�}|jt�s2�|tt�d�}�dk	rT�|d��dk	r�y�|d�}Wn��}YnX|��tkr���Sd}~XnXdS)N)�	action_id)�dbus�
DBusExceptionZ
get_dbus_name�
startswith�AUTH_EXC_PREFIX�lenr	)�func�p�k�eZexc_namerZaf_exc)�authfail_callback�authfail_exception�authfail_resultrr�
_enable_proxyvs$


z#enable_proxy.<locals>._enable_proxycs
t�|�S)N)r)r)r%rr�decorate�szenable_proxy.<locals>.decorate)�
isinstance�collections�Callablerr	�
issubclass�	Exceptionr)rr$r#r"r&r)r%r"r#r$rr@s*
cs$eZdZdZdZ�fdd�Z�ZS)r
zqException which a DBus service method throws if an authorization
    required for executing it can't be obtained.zAorg.fedoraproject.slip.dbus.service.PolKit.NotAuthorizedExceptioncs(|jjd||_tt|�j||�dS)N�.)�	__class__�_dbus_error_name�superr
�__init__)�selfrrr )r-rrr0�s
zNotAuthorizedException.__init__)rrr�__doc__r.r0�
__classcell__rr)r-rr
�sc@s�eZdZdZdZdZdZdZdZdZ	dZ
edd��Ze
dd	��Ze
d
d��Ze
dd
��Ze
dd��Zdd�Zdd�Zdd�Zdifdd�ZdS)�PolKitz"Convenience wrapper around polkit.zorg.freedesktop.PolicyKit1z%/org/freedesktop/PolicyKit1/Authorityz$org.freedesktop.PolicyKit1.AuthorityNcCs4||jkr0tjr0tjjtj�dt_dt_dt_dS)N)�
_dbus_namer4�_PolKit__busZremove_signal_receiver�_PolKit__signal_receiver�_PolKit__interface)�cls�nameZ	old_ownerZ	new_ownerrrr�_on_name_owner_changed�s
zPolKit._on_name_owner_changedcCs0tjs*tj�t_tjj|jdd|jd�t_tjS)NZNameOwnerChangedzorg.freedesktop.DBus)Zhandler_functionZsignal_nameZdbus_interfaceZarg0)r4r6rZ	SystemBusZadd_signal_receiverr;r5r7)r1rrr�_bus�s
zPolKit._buscCstjs|jj�t_tjS)N)r4�_PolKit__bus_namer<Zget_unique_name)r1rrr�	_bus_name�szPolKit._bus_namecCsFtjs@y"tj|jj|j|j�|j�t_Wntj	k
r>YnXtjS)N)
r4r8r�	Interfacer<�
get_objectr5�
_dbus_path�_dbus_interfacer)r1rrr�
_interface�s

zPolKit._interfacecCs
t|j�S)N)�boolrC)r1rrr�_polkit_present�szPolKit._polkit_presentc	Cs>|jjdd�}tj|d�}y|j|�}Wnd}YnX|S)Nzorg.freedesktop.DBusz/org/freedesktop/DBus)r<r@rr?ZGetConnectionUnixUser)r1�system_bus_nameZ
bus_objectZ
bus_interfaceZuidrrrZ__dbus_system_bus_name_uid�s
z!PolKit.__dbus_system_bus_name_uidcCs6|js
dS|jjdd|jif|idd�\}}}|p4|S)NTzsystem-bus-namer:r�)rErC�CheckAuthorizationr>)r1Z
authorization�
is_authorized�is_challenge�detailsrrrZ__authorization_is_obtainable�sz$PolKit.__authorization_is_obtainablecs8�js
dSt|tttf�s |f}t�fdd�|d�}|S)NTcs|o�j|�S)N)�$_PolKit__authorization_is_obtainable)�x�y)r1rr�<lambda>�sz4PolKit.AreAuthorizationsObtainable.<locals>.<lambda>)rEr'�tuple�list�setr)r1�authorizationsZ
obtainabler)r1rr�s
z"PolKit.AreAuthorizationsObtainableTc	
sd|js �|dkp|j|�dk�Sd}|r0|dO}�fdd�}|jjdd|if|||d||td�dS)	Nrrcs|\}}}�|�dS)Nr)�argsrIrJrK)�
reply_handlerrr�reply_cbs
z7PolKit.IsSystemBusNameAuthorizedAsync.<locals>.reply_cbzsystem-bus-namer:rG)rU�
error_handlerZtimeout)rE�!_PolKit__dbus_system_bus_name_uidrCrHr)	r1rFrrUrW�	challengerK�flagsrVr)rUrrs

z%PolKit.IsSystemBusNameAuthorizedAsync)rrrr2r5rArBr8r6r=r7�classmethodr;�propertyr<r>rCrErXrLrrrrrrr4�s"
r4cCs
tj|�S)N)�__polkitr)rSrrrrsTcCstj||||||�S)N)r]r)rFrrUrWrYrKrrrrs
)r2Z
__future__rr(rr�	functoolsrZ	constantsr�__all__rr�objectr	rrr
r4r]rrrrrr�<module>s(Wo

?>