MINI MINI MANI MO
iZc @ s d Z d d l Z d d l m Z d d l m Z d d d d d d
g Z d Z d Z d e f d
YZ d e d d d Z d e j f d YZ
d e f d YZ e Z d Z e i d Z d S( sm This module contains convenience decorators and functions for using
PolicyKit with dbus services and clients.iN( t decorator( t method_call_no_timeoutt require_autht enable_proxyt AUTHFAIL_DONTCATCHt NotAuthorizedExceptiont AreAuthorizationsObtainablet IsSystemBusNameAuthorizedAsyncc s f d } | S( s Decorator for DBus service methods.
Specify that a user needs a specific PolicyKit authorization `polkit_auth´
to execute it.c s) t | d s t t | d | S( Nt _dbus_is_methodt _slip_polkit_auth_required( t hasattrt AssertionErrort setattr( t method( t polkit_auth( s4 /usr/lib/python2.7/site-packages/slip/dbus/polkit.pyt require_auth_decorator) s ( ( R R ( ( R s4 /usr/lib/python2.7/site-packages/slip/dbus/polkit.pyR # s sB org.fedoraproject.slip.dbus.service.PolKit.NotAuthorizedException.c B s e Z RS( ( t __name__t
__module__( ( ( s4 /usr/lib/python2.7/site-packages/slip/dbus/polkit.pyR 4 s c s | d k s t | s t d t f k sB d k sB t d k s` t s` t d k s t t s t f d | d k r t | S f d } | Sd S( s 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, ...):
...c s y | | | SWn t j k
r } | j } | j t sG n | t t } d k rs d | n d k r y d | } Wn } n X| n t k r n SXd S( Nt action_id( t dbust
DBusExceptiont
get_dbus_namet
startswitht AUTH_EXC_PREFIXt lent NoneR ( t funct pt kt et exc_nameR t af_exc( t authfail_callbackt authfail_exceptiont authfail_result( s4 /usr/lib/python2.7/site-packages/slip/dbus/polkit.pyt
_enable_proxyd s$
c s
t | S( N( R ( R ( R# ( s4 /usr/lib/python2.7/site-packages/slip/dbus/polkit.pyt decorate s N( R t callableR R t
issubclasst ExceptionR ( R R"