# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/backend.py
# class KeyringBackend(object):
#     """The abstract base class of the keyring, every backend must implement
#     this interface.
#     """
# 
#     #@abc.abstractproperty
#     def priority(cls):
#         """
#         Each backend class must supply a priority, a number (float or integer)
#         indicating the priority of the backend relative to all other backends.
#         The priority need not be static -- it may (and should) vary based
#         attributes of the environment in which is runs (platform, available
#         packages, etc.).
# 
#         A higher number indicates a higher priority. The priority should raise
#         a RuntimeError with a message indicating the underlying cause if the
#         backend is not suitable for the current environment.
# 
#         As a rule of thumb, a priority between zero but less than one is
#         suitable, but a priority of one or greater is recommended.
#         """
# 
#     @properties.ClassProperty
#     @classmethod
#     def viable(cls):
#         with errors.ExceptionRaisedContext() as exc:
#             cls.priority
#         return not bool(exc)
# 
#     @abc.abstractmethod
#     def get_password(self, service, username):
#         """Get password of the username for the service
#         """
#         return None
# 
#     @abc.abstractmethod
#     def set_password(self, service, username, password):
#         """Set password for the username of the service
#         """
#         raise errors.PasswordSetError("reason")
# 
#     # for backward-compatibility, don't require a backend to implement
#     #  delete_password
#     #@abc.abstractmethod
#     def delete_password(self, service, username):
#         """Delete the password for the username of the service.
#         """
#         raise errors.PasswordDeleteError("reason")
# 
# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/errors.py
# class PasswordDeleteError(Exception):
#     """Raised when the password can't be deleted.
#     """
# 
# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/errors.py
# class PasswordSetError(Exception):
#     """Raised when the password can't be set.
#     """
# 
# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/util/properties.py
# class ClassProperty(property):
# class NonDataProperty(object):
#     def __get__(self, cls, owner):
#     def __init__(self, fget):
#     def __get__(self, obj, objtype=None):


from ..backend import KeyringBackend
from ..errors import PasswordDeleteError
from ..errors import PasswordSetError
from ..util import properties
    import dbus
    def get_password(self, service, username):
        """Get password of the username for the service
        """
        key = username + '@' + service
        if not self.connected():
            # the user pressed "cancel" when prompted to unlock their keyring.
            return None
        if not self.iface.hasEntry(self.handle, self.folder, key, self.appid):
            return None
        return self.iface.readPassword(
            self.handle, self.folder, key, self.appid)

    def set_password(self, service, username, password):
        """Set password for the username of the service
        """
        key = username + '@' + service
        if not self.connected():
            # the user pressed "cancel" when prompted to unlock their keyring.
            raise PasswordSetError("Cancelled by user")
        self.iface.writePassword(
            self.handle, self.folder, key, password, self.appid)

    def delete_password(self, service, username):
        """Delete the password for the username of the service.
        """
        key = username + '@' + service
        if not self.connected():
            # the user pressed "cancel" when prompted to unlock their keyring.
            raise PasswordDeleteError("Cancelled by user")
        if not self.iface.hasEntry(self.handle, self.folder, key, self.appid):

# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/backend.py
# class KeyringBackend(object):
#     """The abstract base class of the keyring, every backend must implement
#     this interface.
#     """
# 
#     #@abc.abstractproperty
#     def priority(cls):
#         """
#         Each backend class must supply a priority, a number (float or integer)
#         indicating the priority of the backend relative to all other backends.
#         The priority need not be static -- it may (and should) vary based
#         attributes of the environment in which is runs (platform, available
#         packages, etc.).
# 
#         A higher number indicates a higher priority. The priority should raise
#         a RuntimeError with a message indicating the underlying cause if the
#         backend is not suitable for the current environment.
# 
#         As a rule of thumb, a priority between zero but less than one is
#         suitable, but a priority of one or greater is recommended.
#         """
# 
#     @properties.ClassProperty
#     @classmethod
#     def viable(cls):
#         with errors.ExceptionRaisedContext() as exc:
#             cls.priority
#         return not bool(exc)
# 
#     @abc.abstractmethod
#     def get_password(self, service, username):
#         """Get password of the username for the service
#         """
#         return None
# 
#     @abc.abstractmethod
#     def set_password(self, service, username, password):
#         """Set password for the username of the service
#         """
#         raise errors.PasswordSetError("reason")
# 
#     # for backward-compatibility, don't require a backend to implement
#     #  delete_password
#     #@abc.abstractmethod
#     def delete_password(self, service, username):
#         """Delete the password for the username of the service.
#         """
#         raise errors.PasswordDeleteError("reason")
# 
# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/errors.py
# class PasswordDeleteError(Exception):
#     """Raised when the password can't be deleted.
#     """
# 
# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/errors.py
# class PasswordSetError(Exception):
#     """Raised when the password can't be set.
#     """
# 
# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/util/properties.py
# class ClassProperty(property):
# class NonDataProperty(object):
#     def __get__(self, cls, owner):
#     def __init__(self, fget):
#     def __get__(self, obj, objtype=None):


# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/backends/kwallet.py
from ..backend import KeyringBackend
from ..errors import PasswordDeleteError
from ..errors import PasswordSetError
from ..util import properties
    import dbus

    def get_password(self, service, username):
        """Get password of the username for the service
        """
        key = username + '@' + service
        if not self.connected():
            # the user pressed "cancel" when prompted to unlock their keyring.
            return None
        if not self.iface.hasEntry(self.handle, self.folder, key, self.appid):
            return None
        return self.iface.readPassword(
            self.handle, self.folder, key, self.appid)

    def set_password(self, service, username, password):
        """Set password for the username of the service
        """
        key = username + '@' + service
        if not self.connected():
            # the user pressed "cancel" when prompted to unlock their keyring.
            raise PasswordSetError("Cancelled by user")
        self.iface.writePassword(
            self.handle, self.folder, key, password, self.appid)

    def delete_password(self, service, username):
        """Delete the password for the username of the service.
        """
        key = username + '@' + service
        if not self.connected():
            # the user pressed "cancel" when prompted to unlock their keyring.
            raise PasswordDeleteError("Cancelled by user")
        if not self.iface.hasEntry(self.handle, self.folder, key, self.appid):

            raise PasswordDeleteError("Password not found")