# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/py27compat.py
# def add_metaclass(metaclass):
#     def wrapper(cls):
# 
# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/util/escape.py
# def escape(value):
#     """
#     Escapes given string so the result consists of alphanumeric chars and
#     underscore only.
#     """
#     return "".join(_escape_char(c) for c in value.encode('utf-8'))
# 
# 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/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.
#     """
# 
# class ExceptionRaisedContext(object):
#     """
#     An exception-trapping context that indicates whether an exception was
#     raised.
#     """
#     def __init__(self, ExpectedException=Exception):
#         self.ExpectedException = ExpectedException
#         self.exc_info = None
# 
#     def __enter__(self):
#         self.exc_info = object.__new__(ExceptionInfo)
#         return self.exc_info
# 
#     def __exit__(self, *exc_info):
#         self.exc_info.__init__(*exc_info)
#         return self.exc_info.type and issubclass(
#             self.exc_info.type, self.ExpectedException)


import functools
        import pywintypes
        import win32cred
from ..py27compat import unicode_str
from ..util import escape, properties
from ..backend import KeyringBackend
from ..errors import PasswordDeleteError, ExceptionRaisedContext
    from win32ctypes import pywintypes
    from win32ctypes import win32cred

def has_pywin32():
    """
    Does this environment have pywin32?
    Should return False even when Mercurial's Demand Import allowed import of
    win32cred.
    """
    with ExceptionRaisedContext() as exc:
        win32cred.__name__
    return not bool(exc)


class WinVaultKeyring(KeyringBackend):
    """
    WinVaultKeyring stores encrypted passwords using the Windows Credential
    Manager.

    Requires pywin32

    This backend does some gymnastics to simulate multi-user support,
    which WinVault doesn't support natively. See
    https://bitbucket.org/kang/python-keyring-lib/issue/47/winvaultkeyring-only-ever-returns-last#comment-731977
    for details on the implementation, but here's the gist:

    Passwords are stored under the service name unless there is a collision
    (another password with the same service name but different user name),
    in which case the previous password is moved into a compound name:
    {username}@{service}
    """


# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/py27compat.py
# def add_metaclass(metaclass):
#     def wrapper(cls):
# 
# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/util/escape.py
# def escape(value):
#     """
#     Escapes given string so the result consists of alphanumeric chars and
#     underscore only.
#     """
#     return "".join(_escape_char(c) for c in value.encode('utf-8'))
# 
# 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/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.
#     """
# 
# class ExceptionRaisedContext(object):
#     """
#     An exception-trapping context that indicates whether an exception was
#     raised.
#     """
#     def __init__(self, ExpectedException=Exception):
#         self.ExpectedException = ExpectedException
#         self.exc_info = None
# 
#     def __enter__(self):
#         self.exc_info = object.__new__(ExceptionInfo)
#         return self.exc_info
# 
#     def __exit__(self, *exc_info):
#         self.exc_info.__init__(*exc_info)
#         return self.exc_info.type and issubclass(
#             self.exc_info.type, self.ExpectedException)


# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/keyring/backends/Windows.py
import functools
        import pywintypes
        import win32cred
from ..py27compat import unicode_str
from ..util import escape, properties
from ..backend import KeyringBackend
from ..errors import PasswordDeleteError, ExceptionRaisedContext
    from win32ctypes import pywintypes
    from win32ctypes import win32cred


def has_pywin32():
    """
    Does this environment have pywin32?
    Should return False even when Mercurial's Demand Import allowed import of
    win32cred.
    """
    with ExceptionRaisedContext() as exc:
        win32cred.__name__
    return not bool(exc)


class WinVaultKeyring(KeyringBackend):
    """
    WinVaultKeyring stores encrypted passwords using the Windows Credential
    Manager.

    Requires pywin32

    This backend does some gymnastics to simulate multi-user support,
    which WinVault doesn't support natively. See
    https://bitbucket.org/kang/python-keyring-lib/issue/47/winvaultkeyring-only-ever-returns-last#comment-731977
    for details on the implementation, but here's the gist:

    Passwords are stored under the service name unless there is a collision
    (another password with the same service name but different user name),
    in which case the previous password is moved into a compound name:
    {username}@{service}
    """


    @properties.ClassProperty