Your IP : 3.147.78.249


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.opt-1.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��|S)NZ_slip_polkit_auth_required)�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	<scs6���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, ...):
                ...cs�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_proxyNcs
t�|�S)N)r)r)r#rr�decorate�szenable_proxy.<locals>.decorate)r)rr"r!r r$r)r#r r!r"rr@s
6
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&rrr)�s
zNotAuthorizedException.__init__)rrr�__doc__r'r)�
__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_namer-�_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)r-r/rZ	SystemBusZadd_signal_receiverr4r.r0)r*rrr�_bus�s
zPolKit._buscCstjs|jj�t_tjS)N)r-�_PolKit__bus_namer5Zget_unique_name)r*rrr�	_bus_name�szPolKit._bus_namecCsFtjs@y"tj|jj|j|j�|j�t_Wntj	k
r>YnXtjS)N)
r-r1r�	Interfacer5�
get_objectr.�
_dbus_path�_dbus_interfacer)r*rrr�
_interface�s

zPolKit._interfacecCs
t|j�S)N)�boolr<)r*rrr�_polkit_present�szPolKit._polkit_presentc	Cs>|jjdd�}tj|d�}y|j|�}Wnd}YnX|S)Nzorg.freedesktop.DBusz/org/freedesktop/DBus)r5r9rr8ZGetConnectionUnixUser)r*�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-namer3r�)r>r<�CheckAuthorizationr7)r*Z
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)r*rr�<lambda>�sz4PolKit.AreAuthorizationsObtainable.<locals>.<lambda>)r>�
isinstance�tuple�list�setr)r*�authorizationsZ
obtainabler)r*rr�s
z"PolKit.AreAuthorizationsObtainableTc	
sd|js �|dkp|j|�dk�Sd}|r0|dO}�fdd�}|jjdd|if|||d||td�dS)	Nrrcs|\}}}�|�dS)Nr)�argsrBrCrD)�
reply_handlerrr�reply_cbs
z7PolKit.IsSystemBusNameAuthorizedAsync.<locals>.reply_cbzsystem-bus-namer3r@)rO�
error_handlerZtimeout)r>�!_PolKit__dbus_system_bus_name_uidr<rAr)	r*r?rrOrQ�	challengerD�flagsrPr)rOrrs

z%PolKit.IsSystemBusNameAuthorizedAsync)rrrr+r.r:r;r1r/r6r0�classmethodr4�propertyr5r7r<r>rRrErrrrrrr-�s"
r-cCs
tj|�S)N)�__polkitr)rMrrrrsTcCstj||||||�S)N)rWr)r?rrOrQrSrDrrrrs
)r+Z
__future__r�collectionsrr�	functoolsrZ	constantsr�__all__rr�objectr	rrr
r-rWrrrrrr�<module>s(Wo

?>