ó ‹iÍZc@sØdZddlZddlmZddlmZddddd d gZd „Zd Zdefd „ƒYZ de ddd„Z dej fd„ƒYZ defd„ƒYZeƒZd„Zeid„ZdS(smThis module contains convenience decorators and functions for using PolicyKit with dbus services and clients.iÿÿÿÿN(t decorator(tmethod_call_no_timeoutt require_autht enable_proxytAUTHFAIL_DONTCATCHtNotAuthorizedExceptiontAreAuthorizationsObtainabletIsSystemBusNameAuthorizedAsynccs‡fd†}|S(s‡Decorator for DBus service methods. Specify that a user needs a specific PolicyKit authorization `polkit_auth´ to execute it.cst|dˆƒ|S(Nt_slip_polkit_auth_required(tsetattr(tmethod(t polkit_auth(s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pytrequire_auth_decorator)s((R R ((R s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyR#ssBorg.fedoraproject.slip.dbus.service.PolKit.NotAuthorizedException.cBseZRS((t__name__t __module__(((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyR4scsE‡‡‡fd†‰|dk r.tˆ|ƒS‡fd†}|SdS(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, ...): ...csÉy|||ŽSWn±tjk rÄ}|jƒ}|jtƒsG‚n|ttƒ}ˆdk rsˆd|ƒnˆdk r®yˆd|ƒ}Wnˆƒ}nX|‚nˆtkrÀ‚nˆSXdS(Nt action_id(tdbust DBusExceptiont get_dbus_namet startswithtAUTH_EXC_PREFIXtlentNoneR(tfunctptktetexc_nameRtaf_exc(tauthfail_callbacktauthfail_exceptiontauthfail_result(s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyt _enable_proxyds$      cs tˆ|ƒS(N(R(R(R (s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pytdecorate‚sN(RR(RRRRR!((R RRRs4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyR7s -  cBseZdZdZd„ZRS(sqException which a DBus service method throws if an authorization required for executing it can't be obtained.sAorg.fedoraproject.slip.dbus.service.PolKit.NotAuthorizedExceptioncOs4|jjd||_tt|ƒj||ŽdS(Nt.(t __class__t_dbus_error_nametsuperRt__init__(tselfRRR((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyR&Žs(R Rt__doc__R$R&(((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyR†stPolKitcBs­eZdZdZdZdZd Zd Zd Z d Z e d„ƒZ e d„ƒZe d„ƒZe d„ƒZe d„ƒZd „Zd „Zd „Zeid „ZRS(s"Convenience wrapper around polkit.sorg.freedesktop.PolicyKit1s%/org/freedesktop/PolicyKit1/Authoritys$org.freedesktop.PolicyKit1.AuthoritycCsM||jkrItjrItjjtjƒdt_dt_dt_ndS(N(t _dbus_nameR)t _PolKit__bustremove_signal_receivert_PolKit__signal_receiverRt_PolKit__interface(tclstnamet old_ownert new_owner((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyt_on_name_owner_changed¢s   cCsItjsBtjƒt_tjjd|jddddƒt_ntjS(Nthandler_functiont signal_nametNameOwnerChangedtdbus_interfacesorg.freedesktop.DBus(R)R+Rt SystemBustadd_signal_receiverR3R-(R'((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyt_busªs   cCs%tjs|jjƒt_ntjS(N(R)t_PolKit__bus_nameR:tget_unique_name(R'((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyt _bus_name´s cCs[tjsTy1tj|jj|j|jƒ|jƒt_WqTtj k rPqTXntjS(N( R)R.Rt InterfaceR:t get_objectR*t _dbus_patht_dbus_interfaceR(R'((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyt _interfaceºs cCs t|jƒS(N(tboolRB(R'((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyt_polkit_presentÅscCsN|jjddƒ}tj|dƒ}y|j|ƒ}Wn d}nX|S(Nsorg.freedesktop.DBuss/org/freedesktop/DBus(R:R?RR>tGetConnectionUnixUserR(R'tsystem_bus_namet bus_objectt bus_interfacetuid((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyt__dbus_system_bus_name_uidÉs   cCsN|js tS|jjdi|jd6f|iddƒ\}}}|pM|S(Nssystem-bus-nameR0it(RDtTrueRBtCheckAuthorizationR=(R't authorizationt is_authorizedt is_challengetdetails((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyt__authorization_is_obtainableÓs   csGˆjs tSt|tƒr(|g}nt‡fd†|tƒ}|S(Ncs|oˆj|ƒS(N(t$_PolKit__authorization_is_obtainable(txty(R'(s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pytæs(RDRLt isinstancet basestringtreduce(R'tauthorizationst obtainable((R's4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyRÞs   c s•|js.ˆ|dkp*|j|ƒdkƒSd}|rG|dO}n‡fd†}|jjdi|d6f|||dd|d|d tƒdS( Niics|\}}}ˆ|ƒdS(N((targsRORPRQ(t reply_handler(s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pytreply_cb÷sssystem-bus-nameR0RKR]t error_handlerttimeout(RDRt!_PolKit__dbus_system_bus_name_uidRBRMR( R'RFRR]R_t challengeRQtflagsR^((R]s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyRës    N(R RR(R*R@RARR.R+R;R-t classmethodR3tpropertyR:R=RBRDRaRSRRLR(((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyR)•s"   cCs tj|ƒS(N(t__polkitR(RZ((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyRscCstj||||||ƒS(N(RfR(RFRR]R_RbRQ((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyR s (R(RRt constantsRt__all__RRtobjectRRRRRR)RfRRLR(((s4/usr/lib/python2.7/site-packages/slip/dbus/polkit.pyts    On