home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- '''
- Helper class to do authentication via PolicyKit
- '''
- import dbus
- import os
- import logging
-
- class PolicyKitAuthentication(object):
- '''
- Helper class to do authentication via PolicyKit
- '''
-
- def __init__(self):
- super(PolicyKitAuthentication, self).__init__()
- self._PolicyKitAuthentication__pk = None
- self._PolicyKitAuthentication__pa = None
-
-
- def is_authorized(self, action_id, pid = None):
- '''
- Ask PolicyKit whether we are already authorized.
- '''
- if pid == None:
- pid = os.getpid()
-
- pid = dbus.UInt32(pid)
- authorized = self.policy_kit.IsProcessAuthorized(action_id, pid, False)
- logging.debug('%s: authorized=%r', action_id, authorized)
- return 'yes' == authorized
-
-
- def obtain_authorization(self, action_id, widget = None):
- '''
- Try to obtain authoriztation for the specified action.
- '''
- if self.is_authorized(action_id):
- return True
- if not widget or widget.get_toplevel().window.xid:
- pass
- xid = 0
- xid = dbus.UInt32(xid)
- pid = dbus.UInt32(os.getpid())
- granted = self.auth_agent.ObtainAuthorization(action_id, xid, pid)
- logging.debug('%s: granted=%r', action_id, granted)
- return bool(granted)
-
-
- def __get_policy_kit(self):
- '''Retreive the D-Bus interface of PolicyKit.'''
- if self._PolicyKitAuthentication__pk:
- return self._PolicyKitAuthentication__pk
- service = dbus.SystemBus().get_object('org.freedesktop.PolicyKit', '/')
- self._PolicyKitAuthentication__pk = dbus.Interface(service, 'org.freedesktop.PolicyKit')
- return self._PolicyKitAuthentication__pk
-
-
- def __get_auth_agent(self):
- '''
- Retreive the D-Bus interface of the PolicyKit
- authentication agent.
- '''
- if self._PolicyKitAuthentication__pa:
- return self._PolicyKitAuthentication__pa
- self._PolicyKitAuthentication__pa = dbus.SessionBus().get_object('org.freedesktop.PolicyKit.AuthenticationAgent', '/')
- return self._PolicyKitAuthentication__pa
-
- auth_agent = property(__get_auth_agent)
- policy_kit = property(__get_policy_kit)
-
-