[Python-modules-commits] [python-keyring] 01/05: Import python-keyring_8.3.orig.tar.gz
Dmitry Shachnev
mitya57 at moszumanska.debian.org
Sun Feb 7 10:38:49 UTC 2016
This is an automated email from the git hooks/post-receive script.
mitya57 pushed a commit to branch master
in repository python-keyring.
commit 0c2f0fcad1c1e3c82c780c6ac768856abac85284
Author: Dmitry Shachnev <mitya57 at gmail.com>
Date: Sun Feb 7 13:13:47 2016 +0300
Import python-keyring_8.3.orig.tar.gz
---
.hgtags | 7 +
CHANGES.rst | 59 ++++++
PKG-INFO | 47 ++++-
README.rst | 45 ++++-
conftest.py | 5 -
docs/index.rst | 8 +-
hook-keyring.backend.py | 3 +-
keyring.egg-info/PKG-INFO | 47 ++++-
keyring.egg-info/SOURCES.txt | 18 --
keyring.egg-info/requires.txt | 6 +-
keyring/__init__.py | 12 +-
keyring/backend.py | 5 +-
keyring/backends/Gnome.py | 108 -----------
keyring/backends/Google.py | 321 --------------------------------
keyring/backends/Windows.py | 141 --------------
keyring/backends/_win_crypto.py | 101 ----------
keyring/backends/fail.py | 4 +-
keyring/backends/file.py | 295 -----------------------------
keyring/backends/keyczar.py | 99 ----------
keyring/backends/kwallet.py | 114 +-----------
keyring/backends/multi.py | 63 -------
keyring/backends/pyfs.py | 272 ---------------------------
keyring/core.py | 2 -
keyring/tests/backends/test_Gnome.py | 35 ----
keyring/tests/backends/test_Google.py | 331 ---------------------------------
keyring/tests/backends/test_Windows.py | 31 ---
keyring/tests/backends/test_crypto.py | 32 ----
keyring/tests/backends/test_file.py | 52 ------
keyring/tests/backends/test_keyczar.py | 76 --------
keyring/tests/backends/test_kwallet.py | 77 --------
keyring/tests/backends/test_multi.py | 58 ------
keyring/tests/backends/test_pyfs.py | 136 --------------
keyring/tests/mocks.py | 217 ---------------------
keyring/tests/test_cli.py | 149 ---------------
keyring/tests/test_core.py | 122 ------------
keyring/tests/test_util.py | 43 -----
setup.cfg | 2 +-
setup.py | 16 +-
38 files changed, 199 insertions(+), 2960 deletions(-)
diff --git a/.hgtags b/.hgtags
index c04f181..bf70fa2 100644
--- a/.hgtags
+++ b/.hgtags
@@ -96,3 +96,10 @@ b49aea662a2ba2e30fb5288a5bfbd834be674505 7.1
8009ebf8badd5fc409a7f393209038b0057fb23e 7.1.2
510a876a75acdb3dbd7c7db44a12004b34c8ee90 7.2
ce25102896cdb5aeff5937bce37097b6bd960f67 7.3
+c8220affec79af112409b82a868333786f9a5e88 7.3.1
+3952633b87570a50aba6349bcc75f89f7a1db724 8.0
+fed334c57a38ea22886d311d4daf581be25b558a 8.0.1
+dbc981b43088e635228899e779747ce0eafde491 8.1
+81e61bc8edc2d6e9415005557fe216f027b5bfd6 8.1.1
+8f15c2addf681c11ce8f0437deebb338cab920d8 8.2
+d225d8ba8a020eed8170389090a5a82abc38289b 8.3
diff --git a/CHANGES.rst b/CHANGES.rst
index 2c15a3b..750a3f9 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -3,6 +3,65 @@ CHANGES
=======
---
+8.3
+---
+
+* Issue #207: Library now requires win32ctypes on Windows
+ systems, which will be installed automatically by
+ Setuptools 0.7 or Pip 6 (or later).
+* Actually removed QtKwallet, which was meant to be dropped in
+ 8.0 but somehow remained.
+
+---
+8.2
+---
+
+* Update readme to include how-to use with Linux
+ non-graphical environments.
+
+---
+8.1
+---
+
+* Issue #197: Add ``__version__`` attribute to keyring module.
+
+---
+8.0
+---
+
+* Issue #117: Removed all but the preferred keyring backends
+ for each of the major desktop platforms:
+
+ - keyring.backends.kwallet.DBusKeyring
+ - keyring.backends.OS_X.Keyring
+ - keyring.backends.SecretService.Keyring
+ - keyring.backends.Windows.WinVaultKeyring
+
+ All other keyrings
+ have been moved to a new package, `keyrings.alt
+ <https://pypi.python.org/pypi/keyrings.alt>`_ and
+ backward-compatibility aliases removed.
+ To retain
+ availability of these less preferred keyrings, include
+ that package in your installation (install both keyring
+ and keyrings.alt).
+
+ As these keyrings have moved, any keyrings indicated
+ explicitly in configuration will need to be updated to
+ replace "keyring.backends." with "keyrings.alt.". For
+ example, "keyring.backends.file.PlaintextKeyring"
+ becomes "keyrings.alt.file.PlaintextKeyring".
+
+-----
+7.3.1
+-----
+
+* Issue #194: Redirect away from docs until they have something
+ more than the changelog. Users seeking the changelog will
+ want to follow the `direct link
+ <https://pythonhosted.org/keyring/history.html>`_.
+
+---
7.3
---
diff --git a/PKG-INFO b/PKG-INFO
index 88ade69..402cad1 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: keyring
-Version: 7.3
+Version: 8.3
Summary: Store and access your passwords safely.
Home-page: https://github.com/jaraco/keyring
Author: Jason R. Coombs
@@ -22,15 +22,19 @@ Description: =======================================
The keyring library is licensed under both the `MIT license
<http://opensource.org/licenses/MIT>`_ and the PSF license.
- These primary keyring services are supported by the Python keyring lib:
+ These recommended keyring backends are supported by the Python keyring lib:
- * Mac OS X Keychain
- * Linux Secret Service
- * Windows Credential Vault
+ * Mac OS X `Keychain
+ <https://en.wikipedia.org/wiki/Keychain_%28software%29>`_
+ * Linux Secret Service (requires `secretstorage
+ <https://pypi.python.org/pypi/secretstorage>`_)
+ * `KWallet <https://en.wikipedia.org/wiki/KWallet>`_
+ (requires `dbus <https://pypi.python.org/pypi/dbus-python>`_)
+ * `Windows Credential Vault
+ <http://windows.microsoft.com/en-us/windows7/what-is-credential-manager>`_
- Other keyring implementations are provided as well. For more detail, `browse
- the source
- <https://github.com/jaraco/keyring/tree/master/keyring/backends>`_.
+ Other keyring implementations are provided in the `keyrings.alt
+ package <https://pypi.python.org/pypi/keyrings.alt>`_.
-------------------------
Installation Instructions
@@ -183,6 +187,29 @@ Description: =======================================
print("failed to store password")
print("password", keyring.get_password("demo-service", "tarek"))
+ Using Keyring on headless Linux systems
+ =======================================
+
+ It is possible to use the SecretService backend on Linux systems without
+ X11 server available (only D-Bus is required). To do that, you need the
+ following:
+
+ * Install the `GNOME Keyring`_ daemon.
+ * Start a D-Bus session, e.g. run ``dbus-run-session -- sh`` and run
+ the following commands inside that shell.
+ * Run ``gnome-keyring-daemon`` with ``--unlock`` option. The description of
+ that option says:
+
+ Read a password from stdin, and use it to unlock the login keyring
+ or create it if the login keyring does not exist.
+
+ When that command is started, enter your password into stdin and
+ press Ctrl+D (end of data). After that the daemon will fork into
+ background (use ``--foreground`` option to prevent that).
+ * Now you can use the SecretService backend of Keyring. Remember to
+ run your application in the same D-Bus session as the daemon.
+
+ .. _GNOME Keyring: https://wiki.gnome.org/Projects/GnomeKeyring
-----------------------------------------------
Integrate the keyring lib with your application
@@ -269,9 +296,9 @@ Description: =======================================
python setup.py develop
- You then need to install the test requirements with something like:
+ You then need to install the test requirements with something like::
- pip install `python -c "import setup, subprocess; print(subprocess.list2cmdline(setup.test_requirements))"`
+ pip install $( python -c "import setup, subprocess; print(subprocess.list2cmdline(setup.test_requirements))" )
Then, invoke your favorite test runner, e.g.::
diff --git a/README.rst b/README.rst
index 20ed7ce..19bbd98 100644
--- a/README.rst
+++ b/README.rst
@@ -14,15 +14,19 @@ from python. It can be used in any application that needs safe password storage.
The keyring library is licensed under both the `MIT license
<http://opensource.org/licenses/MIT>`_ and the PSF license.
-These primary keyring services are supported by the Python keyring lib:
+These recommended keyring backends are supported by the Python keyring lib:
-* Mac OS X Keychain
-* Linux Secret Service
-* Windows Credential Vault
+* Mac OS X `Keychain
+ <https://en.wikipedia.org/wiki/Keychain_%28software%29>`_
+* Linux Secret Service (requires `secretstorage
+ <https://pypi.python.org/pypi/secretstorage>`_)
+* `KWallet <https://en.wikipedia.org/wiki/KWallet>`_
+ (requires `dbus <https://pypi.python.org/pypi/dbus-python>`_)
+* `Windows Credential Vault
+ <http://windows.microsoft.com/en-us/windows7/what-is-credential-manager>`_
-Other keyring implementations are provided as well. For more detail, `browse
-the source
-<https://github.com/jaraco/keyring/tree/master/keyring/backends>`_.
+Other keyring implementations are provided in the `keyrings.alt
+package <https://pypi.python.org/pypi/keyrings.alt>`_.
-------------------------
Installation Instructions
@@ -175,6 +179,29 @@ Here's an example demonstrating how to invoke ``set_keyring``::
print("failed to store password")
print("password", keyring.get_password("demo-service", "tarek"))
+Using Keyring on headless Linux systems
+=======================================
+
+It is possible to use the SecretService backend on Linux systems without
+X11 server available (only D-Bus is required). To do that, you need the
+following:
+
+* Install the `GNOME Keyring`_ daemon.
+* Start a D-Bus session, e.g. run ``dbus-run-session -- sh`` and run
+ the following commands inside that shell.
+* Run ``gnome-keyring-daemon`` with ``--unlock`` option. The description of
+ that option says:
+
+ Read a password from stdin, and use it to unlock the login keyring
+ or create it if the login keyring does not exist.
+
+ When that command is started, enter your password into stdin and
+ press Ctrl+D (end of data). After that the daemon will fork into
+ background (use ``--foreground`` option to prevent that).
+* Now you can use the SecretService backend of Keyring. Remember to
+ run your application in the same D-Bus session as the daemon.
+
+.. _GNOME Keyring: https://wiki.gnome.org/Projects/GnomeKeyring
-----------------------------------------------
Integrate the keyring lib with your application
@@ -261,9 +288,9 @@ the environment by running::
python setup.py develop
-You then need to install the test requirements with something like:
+You then need to install the test requirements with something like::
- pip install `python -c "import setup, subprocess; print(subprocess.list2cmdline(setup.test_requirements))"`
+ pip install $( python -c "import setup, subprocess; print(subprocess.list2cmdline(setup.test_requirements))" )
Then, invoke your favorite test runner, e.g.::
diff --git a/conftest.py b/conftest.py
index 073f7f0..971898a 100644
--- a/conftest.py
+++ b/conftest.py
@@ -1,8 +1,3 @@
-import platform
-
collect_ignore = [
"hook-keyring.backend.py",
]
-
-if platform.system() != 'Windows':
- collect_ignore.append('keyring/backends/_win_crypto.py')
diff --git a/docs/index.rst b/docs/index.rst
index 3c0f3c6..a943d86 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -1,5 +1,8 @@
+*********************************
Welcome to keyring documentation!
-========================================
+*********************************
+
+.. include:: ../README.rst
.. toctree::
:maxdepth: 1
@@ -13,8 +16,9 @@ Welcome to keyring documentation!
:show-inheritance:
+******************
Indices and tables
-==================
+******************
* :ref:`genindex`
* :ref:`modindex`
diff --git a/hook-keyring.backend.py b/hook-keyring.backend.py
index 7e840f1..fe68ca0 100644
--- a/hook-keyring.backend.py
+++ b/hook-keyring.backend.py
@@ -1,8 +1,7 @@
# Used by pyinstaller to expose hidden imports
# TODO: can this be loaded from keyring.backend directly?
-_backend_mod_names = ('file', 'Gnome', 'Google', 'keyczar', 'kwallet', 'multi',
- 'OS_X', 'pyfs', 'SecretService', 'Windows')
+_backend_mod_names = 'kwallet', 'OS_X', 'SecretService', 'Windows'
hiddenimports = [
'keyring.backends.' + mod_name
diff --git a/keyring.egg-info/PKG-INFO b/keyring.egg-info/PKG-INFO
index 88ade69..402cad1 100644
--- a/keyring.egg-info/PKG-INFO
+++ b/keyring.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: keyring
-Version: 7.3
+Version: 8.3
Summary: Store and access your passwords safely.
Home-page: https://github.com/jaraco/keyring
Author: Jason R. Coombs
@@ -22,15 +22,19 @@ Description: =======================================
The keyring library is licensed under both the `MIT license
<http://opensource.org/licenses/MIT>`_ and the PSF license.
- These primary keyring services are supported by the Python keyring lib:
+ These recommended keyring backends are supported by the Python keyring lib:
- * Mac OS X Keychain
- * Linux Secret Service
- * Windows Credential Vault
+ * Mac OS X `Keychain
+ <https://en.wikipedia.org/wiki/Keychain_%28software%29>`_
+ * Linux Secret Service (requires `secretstorage
+ <https://pypi.python.org/pypi/secretstorage>`_)
+ * `KWallet <https://en.wikipedia.org/wiki/KWallet>`_
+ (requires `dbus <https://pypi.python.org/pypi/dbus-python>`_)
+ * `Windows Credential Vault
+ <http://windows.microsoft.com/en-us/windows7/what-is-credential-manager>`_
- Other keyring implementations are provided as well. For more detail, `browse
- the source
- <https://github.com/jaraco/keyring/tree/master/keyring/backends>`_.
+ Other keyring implementations are provided in the `keyrings.alt
+ package <https://pypi.python.org/pypi/keyrings.alt>`_.
-------------------------
Installation Instructions
@@ -183,6 +187,29 @@ Description: =======================================
print("failed to store password")
print("password", keyring.get_password("demo-service", "tarek"))
+ Using Keyring on headless Linux systems
+ =======================================
+
+ It is possible to use the SecretService backend on Linux systems without
+ X11 server available (only D-Bus is required). To do that, you need the
+ following:
+
+ * Install the `GNOME Keyring`_ daemon.
+ * Start a D-Bus session, e.g. run ``dbus-run-session -- sh`` and run
+ the following commands inside that shell.
+ * Run ``gnome-keyring-daemon`` with ``--unlock`` option. The description of
+ that option says:
+
+ Read a password from stdin, and use it to unlock the login keyring
+ or create it if the login keyring does not exist.
+
+ When that command is started, enter your password into stdin and
+ press Ctrl+D (end of data). After that the daemon will fork into
+ background (use ``--foreground`` option to prevent that).
+ * Now you can use the SecretService backend of Keyring. Remember to
+ run your application in the same D-Bus session as the daemon.
+
+ .. _GNOME Keyring: https://wiki.gnome.org/Projects/GnomeKeyring
-----------------------------------------------
Integrate the keyring lib with your application
@@ -269,9 +296,9 @@ Description: =======================================
python setup.py develop
- You then need to install the test requirements with something like:
+ You then need to install the test requirements with something like::
- pip install `python -c "import setup, subprocess; print(subprocess.list2cmdline(setup.test_requirements))"`
+ pip install $( python -c "import setup, subprocess; print(subprocess.list2cmdline(setup.test_requirements))" )
Then, invoke your favorite test runner, e.g.::
diff --git a/keyring.egg-info/SOURCES.txt b/keyring.egg-info/SOURCES.txt
index 2159d08..b0874c4 100644
--- a/keyring.egg-info/SOURCES.txt
+++ b/keyring.egg-info/SOURCES.txt
@@ -29,38 +29,20 @@ keyring.egg-info/dependency_links.txt
keyring.egg-info/entry_points.txt
keyring.egg-info/requires.txt
keyring.egg-info/top_level.txt
-keyring/backends/Gnome.py
-keyring/backends/Google.py
keyring/backends/OS_X.py
keyring/backends/SecretService.py
keyring/backends/Windows.py
keyring/backends/__init__.py
-keyring/backends/_win_crypto.py
keyring/backends/fail.py
-keyring/backends/file.py
-keyring/backends/keyczar.py
keyring/backends/kwallet.py
-keyring/backends/multi.py
-keyring/backends/pyfs.py
keyring/tests/__init__.py
-keyring/tests/mocks.py
keyring/tests/test_backend.py
-keyring/tests/test_cli.py
-keyring/tests/test_core.py
-keyring/tests/test_util.py
keyring/tests/util.py
keyring/tests/backends/__init__.py
-keyring/tests/backends/test_Gnome.py
-keyring/tests/backends/test_Google.py
keyring/tests/backends/test_OS_X.py
keyring/tests/backends/test_SecretService.py
keyring/tests/backends/test_Windows.py
-keyring/tests/backends/test_crypto.py
-keyring/tests/backends/test_file.py
-keyring/tests/backends/test_keyczar.py
keyring/tests/backends/test_kwallet.py
-keyring/tests/backends/test_multi.py
-keyring/tests/backends/test_pyfs.py
keyring/util/__init__.py
keyring/util/escape.py
keyring/util/platform_.py
diff --git a/keyring.egg-info/requires.txt b/keyring.egg-info/requires.txt
index 0129470..68e187a 100644
--- a/keyring.egg-info/requires.txt
+++ b/keyring.egg-info/requires.txt
@@ -1,6 +1,6 @@
+[:sys_platform=="win32"]
+win32ctypes
+
[test]
pytest>=2.8
-fs>=0.5
-mock
-pycrypto
diff --git a/keyring/__init__.py b/keyring/__init__.py
index bbf968f..2289cee 100644
--- a/keyring/__init__.py
+++ b/keyring/__init__.py
@@ -1,9 +1,3 @@
-"""
-__init__.py
-
-Created by Kang Zhang on 2009-07-09
-"""
-
from __future__ import absolute_import
import logging
@@ -12,3 +6,9 @@ logger = logging.getLogger('keyring')
from .core import (set_keyring, get_keyring, set_password, get_password,
delete_password)
from .getpassbackend import get_password as get_pass_get_password
+
+try:
+ import pkg_resources
+ __version__ = pkg_resources.require('keyring')[0].version
+except Exception:
+ __version__ = 'unknown'
diff --git a/keyring/backend.py b/keyring/backend.py
index 3ea7462..496173a 100644
--- a/keyring/backend.py
+++ b/keyring/backend.py
@@ -122,9 +122,8 @@ def _load_backend(name):
mod.__name__
def _load_backends():
- "ensure that all keyring backends are loaded"
- backends = ('file', 'Gnome', 'Google', 'keyczar', 'kwallet', 'multi',
- 'OS_X', 'pyfs', 'SecretService', 'Windows')
+ "ensure that native keyring backends are loaded"
+ backends = 'kwallet', 'OS_X', 'SecretService', 'Windows'
list(map(_load_backend, backends))
_load_plugins()
diff --git a/keyring/backends/Gnome.py b/keyring/backends/Gnome.py
deleted file mode 100644
index fd85dce..0000000
--- a/keyring/backends/Gnome.py
+++ /dev/null
@@ -1,108 +0,0 @@
-try:
- import gi
- gi.require_version('GnomeKeyring', '1.0')
- from gi.repository import GnomeKeyring
-except (ImportError, ValueError):
- pass
-
-from ..backend import KeyringBackend
-from ..errors import PasswordSetError, PasswordDeleteError
-from ..util import properties
-from ..py27compat import unicode_str
-
-
-class Keyring(KeyringBackend):
- """Gnome Keyring"""
-
- KEYRING_NAME = None
- """
- Name of the keyring in which to store the passwords.
- Use None for the default keyring.
- """
-
- @properties.ClassProperty
- @classmethod
- def priority(cls):
- if 'GnomeKeyring' not in globals():
- raise RuntimeError("GnomeKeyring module required")
- result = GnomeKeyring.get_default_keyring_sync()[0]
- if result != GnomeKeyring.Result.OK:
- raise RuntimeError(result.value_name)
- return 1
-
- @property
- def keyring_name(self):
- system_default = GnomeKeyring.get_default_keyring_sync()[1]
- return self.KEYRING_NAME or system_default
-
- def _find_passwords(self, service, username, deleting=False):
- """Get password of the username for the service
- """
- passwords = []
-
- service = self._safe_string(service)
- username = self._safe_string(username)
- for attrs_tuple in (('username', 'service'), ('user', 'domain')):
- attrs = GnomeKeyring.Attribute.list_new()
- GnomeKeyring.Attribute.list_append_string(attrs, attrs_tuple[0], username)
- GnomeKeyring.Attribute.list_append_string(attrs, attrs_tuple[1], service)
- result, items = GnomeKeyring.find_items_sync(
- GnomeKeyring.ItemType.NETWORK_PASSWORD, attrs)
- if result == GnomeKeyring.Result.OK:
- passwords += items
- elif deleting:
- if result == GnomeKeyring.Result.CANCELLED:
- raise PasswordDeleteError("Cancelled by user")
- elif result != GnomeKeyring.Result.NO_MATCH:
- raise PasswordDeleteError(result.value_name)
- return passwords
-
- def get_password(self, service, username):
- """Get password of the username for the service
- """
- items = self._find_passwords(service, username)
- if not items:
- return None
-
- secret = items[0].secret
- return secret if isinstance(secret, unicode_str) else secret.decode('utf-8')
-
- def set_password(self, service, username, password):
- """Set password for the username of the service
- """
- service = self._safe_string(service)
- username = self._safe_string(username)
- password = self._safe_string(password)
- attrs = GnomeKeyring.Attribute.list_new()
- GnomeKeyring.Attribute.list_append_string(attrs, 'username', username)
- GnomeKeyring.Attribute.list_append_string(attrs, 'service', service)
- GnomeKeyring.Attribute.list_append_string(attrs, 'application', 'python-keyring')
- result = GnomeKeyring.item_create_sync(
- self.keyring_name, GnomeKeyring.ItemType.NETWORK_PASSWORD,
- "Password for '%s' on '%s'" % (username, service),
- attrs, password, True)[0]
- if result == GnomeKeyring.Result.CANCELLED:
- # The user pressed "Cancel" when prompted to unlock their keyring.
- raise PasswordSetError("Cancelled by user")
- elif result != GnomeKeyring.Result.OK:
- raise PasswordSetError(result.value_name)
-
- def delete_password(self, service, username):
- """Delete the password for the username of the service.
- """
- items = self._find_passwords(service, username, deleting=True)
- if not items:
- raise PasswordDeleteError("Password not found")
- for current in items:
- result = GnomeKeyring.item_delete_sync(current.keyring,
- current.item_id)
- if result == GnomeKeyring.Result.CANCELLED:
- raise PasswordDeleteError("Cancelled by user")
- elif result != GnomeKeyring.Result.OK:
- raise PasswordDeleteError(result.value_name)
-
- def _safe_string(self, source, encoding='utf-8'):
- """Convert unicode to string as gnomekeyring barfs on unicode"""
- if not isinstance(source, str):
- return source.encode(encoding)
- return str(source)
diff --git a/keyring/backends/Google.py b/keyring/backends/Google.py
deleted file mode 100644
index 48fd478..0000000
--- a/keyring/backends/Google.py
+++ /dev/null
@@ -1,321 +0,0 @@
-from __future__ import absolute_import
-
-import os
-import sys
-import copy
-import codecs
-import base64
-import io
-
-try:
- import gdata.docs.service
-except ImportError:
- pass
-
-from . import keyczar
-from .. import errors
-from .. import credentials
-from ..py27compat import input, pickle
-from ..backend import KeyringBackend
-from ..util import properties
-from ..errors import ExceptionRaisedContext
-
-class EnvironCredential(credentials.EnvironCredential):
- """Retrieve credentials from specifically named environment variables
- """
-
- def __init__(self):
- super(EnvironCredential, self).__init__('GOOGLE_KEYRING_USER',
- 'GOOGLE_KEYRING_PASSWORD')
-
-class DocsKeyring(KeyringBackend):
- """Backend that stores keyring on Google Docs.
- Note that login and any other initialisation is deferred until it is
- actually required to allow this keyring class to be added to the
- global _all_keyring list.
- """
-
- keyring_title = 'GoogleKeyring'
- # status enums
- OK = 1
- FAIL = 0
- CONFLICT = -1
-
- def __init__(self, credential, source, crypter,
- collection=None, client=None,
- can_create=True, input_getter=input
- ):
- self.credential = credential
- self.crypter = crypter
- self.source = source
- self._collection = collection
- self.can_create = can_create
- self.input_getter = input_getter
- self._keyring_dict = None
-
- if not client:
- self._client = gdata.docs.service.DocsService()
- else:
- self._client = client
-
- self._client.source = source
- self._client.ssl = True
- self._login_reqd = True
-
- @properties.ClassProperty
- @classmethod
- def priority(cls):
- if not cls._has_gdata():
- raise RuntimeError("Requires gdata")
- if not keyczar.has_keyczar():
- raise RuntimeError("Requires keyczar")
- return 3
-
- @classmethod
- def _has_gdata(cls):
- with ExceptionRaisedContext() as exc:
- gdata.__name__
- return not bool(exc)
-
- def get_password(self, service, username):
- """Get password of the username for the service
- """
- result = self._get_entry(self._keyring, service, username)
- if result:
- result = self._decrypt(result)
- return result
-
- def set_password(self, service, username, password):
- """Set password for the username of the service
- """
- password = self._encrypt(password or '')
- keyring_working_copy = copy.deepcopy(self._keyring)
- service_entries = keyring_working_copy.get(service)
- if not service_entries:
- service_entries = {}
- keyring_working_copy[service] = service_entries
- service_entries[username] = password
- save_result = self._save_keyring(keyring_working_copy)
- if save_result == self.OK:
- self._keyring_dict = keyring_working_copy
- return
- elif save_result == self.CONFLICT:
- # check if we can avoid updating
- self.docs_entry, keyring_dict = self._read()
- existing_pwd = self._get_entry(self._keyring, service, username)
- conflicting_pwd = self._get_entry(keyring_dict, service, username)
- if conflicting_pwd == password:
- # if someone else updated it to the same value then we are done
- self._keyring_dict = keyring_working_copy
- return
- elif conflicting_pwd is None or conflicting_pwd == existing_pwd:
- # if doesn't already exist or is unchanged then update it
- new_service_entries = keyring_dict.get(service, {})
- new_service_entries[username] = password
- keyring_dict[service] = new_service_entries
- save_result = self._save_keyring(keyring_dict)
- if save_result == self.OK:
- self._keyring_dict = keyring_dict
- return
- else:
- raise errors.PasswordSetError(
- 'Failed write after conflict detected')
- else:
- raise errors.PasswordSetError(
- 'Conflict detected, service:%s and username:%s was '\
- 'set to a different value by someone else' %(service,
- username))
-
- raise errors.PasswordSetError('Could not save keyring')
-
- def delete_password(self, service, username):
- return self._del_entry(self._keyring, service, username)
-
- @property
- def client(self):
- if not self._client.GetClientLoginToken():
- try:
- self._client.ClientLogin(self.credential.username,
- self.credential.password,
- self._client.source)
- except gdata.service.CaptchaRequired:
- sys.stdout.write('Please visit ' + self._client.captcha_url)
- answer = self.input_getter('Answer to the challenge? ')
- self._client.email = self.credential.username
- self._client.password = self.credential.password
- self._client.ClientLogin(
- self.credential.username,
- self.credential.password,
- self._client.source,
- captcha_token=self._client.captcha_token,
- captcha_response=answer)
- except gdata.service.BadAuthentication:
- raise errors.InitError('Users credential were unrecognized')
- except gdata.service.Error:
- raise errors.InitError('Login Error')
-
- return self._client
-
- @property
- def collection(self):
- return self._collection or self.credential.username.split('@')[0]
-
- @property
- def _keyring(self):
- if self._keyring_dict is None:
- self.docs_entry, self._keyring_dict = self._read()
- return self._keyring_dict
-
- def _get_entry(self, keyring_dict, service, username):
- result = None
- service_entries = keyring_dict.get(service)
- if service_entries:
- result = service_entries.get(username)
- return result
-
- def _del_entry(self, keyring_dict, service, username):
- service_entries = keyring_dict.get(service)
- if not service_entries:
- raise errors.PasswordDeleteError("No matching service")
- try:
- del service_entries[username]
- except KeyError:
- raise errors.PasswordDeleteError("Not found")
- if not service_entries:
- del keyring_dict[service]
-
- def _decrypt(self, value):
- if not value:
- return ''
- return self.crypter.decrypt(value)
-
- def _encrypt(self, value):
- if not value:
- return ''
- return self.crypter.encrypt(value)
-
- def _get_doc_title(self):
- return '%s' %self.keyring_title
-
- def _read(self):
- from gdata.docs.service import DocumentQuery
- title_query = DocumentQuery(categories=[self.collection])
- title_query['title'] = self._get_doc_title()
- title_query['title-exact'] = 'true'
- docs = self.client.QueryDocumentListFeed(title_query.ToUri())
-
- if not docs.entry:
- if self.can_create:
- docs_entry = None
- keyring_dict = {}
- else:
- raise errors.InitError(
- '%s not found in %s and create not permitted'
- %(self._get_doc_title(), self.collection))
- else:
- docs_entry = docs.entry[0]
- file_contents = ''
- try:
- url = docs_entry.content.src
- url += '&exportFormat=txt'
- server_response = self.client.request('GET', url)
- if server_response.status != 200:
- raise errors.InitError(
- 'Could not read existing Google Docs keyring')
- file_contents = server_response.read()
- if file_contents.startswith(codecs.BOM_UTF8):
- file_contents = file_contents[len(codecs.BOM_UTF8):]
- keyring_dict = pickle.loads(base64.urlsafe_b64decode(
- file_contents.decode('string-escape')))
- except pickle.UnpicklingError as ex:
- raise errors.InitError(
- 'Could not unpickle existing Google Docs keyring', ex)
- except TypeError as ex:
- raise errors.InitError(
- 'Could not decode existing Google Docs keyring', ex)
-
- return docs_entry, keyring_dict
-
- def _save_keyring(self, keyring_dict):
- """Helper to actually write the keyring to Google"""
- import gdata
- result = self.OK
- file_contents = base64.urlsafe_b64encode(pickle.dumps(keyring_dict))
- try:
- if self.docs_entry:
- extra_headers = {'Content-Type': 'text/plain',
- 'Content-Length': len(file_contents)}
- self.docs_entry = self.client.Put(
- file_contents,
- self.docs_entry.GetEditMediaLink().href,
- extra_headers=extra_headers
- )
- else:
- from gdata.docs.service import DocumentQuery
- # check for existence of folder, create if required
- folder_query = DocumentQuery(categories=['folder'])
- folder_query['title'] = self.collection
- folder_query['title-exact'] = 'true'
- docs = self.client.QueryDocumentListFeed(folder_query.ToUri())
- if docs.entry:
- folder_entry = docs.entry[0]
- else:
- folder_entry = self.client.CreateFolder(self.collection)
- file_handle = io.BytesIO(file_contents)
- media_source = gdata.MediaSource(
- file_handle=file_handle,
- content_type='text/plain',
- content_length=len(file_contents),
- file_name='temp')
- self.docs_entry = self.client.Upload(
- media_source,
- self._get_doc_title(),
- folder_or_uri=folder_entry
- )
- except gdata.service.RequestError as ex:
- try:
- if ex.message['reason'].lower().find('conflict') != -1:
- result = self.CONFLICT
- else:
- # Google docs has a bug when updating a shared document
- # using PUT from any account other that the owner.
- # It returns an error 400 "Sorry, there was an error saving the file. Please try again"
- # *despite* actually updating the document!
- # Workaround by re-reading to see if it actually updated
- if ex.message['body'].find(
- 'Sorry, there was an error saving the file') != -1:
- new_docs_entry, new_keyring_dict = self._read()
- if new_keyring_dict == keyring_dict:
- result = self.OK
- else:
- result = self.FAIL
- else:
- result = self.FAIL
- except:
- result = self.FAIL
-
- return result
-
-class KeyczarDocsKeyring(DocsKeyring):
- """Google Docs keyring using keyczar initialized from environment
- variables
- """
-
- def __init__(self):
- crypter = keyczar.EnvironCrypter()
- credential = EnvironCredential()
- source = os.environ.get('GOOGLE_KEYRING_SOURCE')
- super(KeyczarDocsKeyring, self).__init__(
- credential, source, crypter)
-
- def supported(self):
- """Return if this keyring supports current environment:
- -1: not applicable
- 0: suitable
- 1: recommended
- """
- try:
- from keyczar import keyczar
- return super(KeyczarDocsKeyring, self).supported()
- except ImportError:
- return -1
diff --git a/keyring/backends/Windows.py b/keyring/backends/Windows.py
index d2c74ff..02df353 100644
--- a/keyring/backends/Windows.py
+++ b/keyring/backends/Windows.py
@@ -1,13 +1,9 @@
-import sys
-import base64
-import platform
import functools
from ..py27compat import unicode_str
from ..util import escape, properties
from ..backend import KeyringBackend
from ..errors import PasswordDeleteError, ExceptionRaisedContext
-from . import file
try:
# prefer pywin32-ctypes
@@ -23,20 +19,6 @@ except ImportError:
except ImportError:
pass
-try:
- import winreg
-except ImportError:
- try:
- # Python 2 compatibility
- import _winreg as winreg
- except ImportError:
- pass
-
-try:
- from . import _win_crypto
-except ImportError:
- pass
-
def has_pywin32():
"""
Does this environment have pywin32?
@@ -47,44 +29,6 @@ def has_pywin32():
win32cred.__name__
return not bool(exc)
-def has_wincrypto():
... 2674 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-keyring.git
More information about the Python-modules-commits
mailing list