[Python-modules-commits] [python-keyring] 01/03: Import python-keyring_7.3.orig.tar.gz

Dmitry Shachnev mitya57 at moszumanska.debian.org
Fri Jan 22 14:53:33 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 68f259230a721263f384fff1ffc42dbd08a8890f
Author: Dmitry Shachnev <mitya57 at gmail.com>
Date:   Fri Jan 22 17:50:50 2016 +0300

    Import python-keyring_7.3.orig.tar.gz
---
 .gitignore                                   | 59 ++++++++++++++++++++++++
 .hgtags                                      |  9 ++++
 CHANGES.rst                                  | 69 ++++++++++++++++++++++++++++
 PKG-INFO                                     |  2 +-
 conftest.py                                  |  4 +-
 keyring.egg-info/PKG-INFO                    |  2 +-
 keyring.egg-info/SOURCES.txt                 |  6 +--
 keyring/backends/Gnome.py                    | 25 ++--------
 keyring/backends/OS_X.py                     |  5 ++
 keyring/backends/SecretService.py            |  2 -
 keyring/backends/__init__.py                 |  1 -
 keyring/backends/fail.py                     | 20 ++++++++
 keyring/backends/kwallet.py                  | 13 ++++--
 keyring/core.py                              | 65 ++++++++++++++++++--------
 keyring/py27compat.py                        |  5 ++
 keyring/py33compat.py                        | 31 +++++++++++++
 keyring/tests/backends/test_Gnome.py         | 24 ++--------
 keyring/tests/backends/test_Google.py        |  2 +-
 keyring/tests/backends/test_OS_X.py          |  2 +-
 keyring/tests/backends/test_SecretService.py |  3 +-
 keyring/tests/backends/test_Windows.py       |  3 +-
 keyring/tests/backends/test_crypto.py        |  2 +-
 keyring/tests/backends/test_file.py          |  3 +-
 keyring/tests/backends/test_keyczar.py       |  3 +-
 keyring/tests/backends/test_kwallet.py       |  2 +-
 keyring/tests/backends/test_multi.py         |  2 +-
 keyring/tests/backends/test_pyfs.py          |  3 +-
 keyring/tests/py30compat.py                  | 10 ----
 keyring/tests/test_XDG.py                    | 16 -------
 keyring/tests/test_cli.py                    |  3 +-
 keyring/tests/test_util.py                   |  3 +-
 keyring/util/XDG.py                          | 25 ----------
 keyring/util/platform_.py                    | 60 ++++++++++++++++--------
 33 files changed, 321 insertions(+), 163 deletions(-)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c241564
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,59 @@
+# Created by https://www.gitignore.io
+
+### Python ###
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.cache
+nosetests.xml
+coverage.xml
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
diff --git a/.hgtags b/.hgtags
index 180577f..c04f181 100644
--- a/.hgtags
+++ b/.hgtags
@@ -87,3 +87,12 @@ dc1cf8a793120e51c2d4b8f5a210048cb354f7f0 6.0
 dc1cf8a793120e51c2d4b8f5a210048cb354f7f0 6.0
 4f626f3936d782caba0cd63bd31df278a3528e49 6.0
 4da739a49d9e72e901111e2e4a86964a17fbf47d 6.1
+902ca64b5639519f6d0aecd786949a83944291ca 6.1.1
+63e5de418ff70bba19d758a146cf8bdf642d6e36 7.0
+8c7a0fb016a87931292c2f7ab1b735a97768759f 7.0.1
+1eed5d66e94b78aebb97d75d95559ed2e27c5447 7.0.2
+b49aea662a2ba2e30fb5288a5bfbd834be674505 7.1
+89f927d763931b78263022cca25ec85b47b6f27e 7.1.1
+8009ebf8badd5fc409a7f393209038b0057fb23e 7.1.2
+510a876a75acdb3dbd7c7db44a12004b34c8ee90 7.2
+ce25102896cdb5aeff5937bce37097b6bd960f67 7.3
diff --git a/CHANGES.rst b/CHANGES.rst
index 89d0a8f..2c15a3b 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -3,6 +3,75 @@ CHANGES
 =======
 
 ---
+7.3
+---
+
+* Issue #117: Added support for filtering which
+  backends are acceptable. To limit to only loading recommended
+  keyrings (those with priority >= 1), call::
+
+    keyring.core.init_backend(limit=keyring.core.recommended)
+
+---
+7.2
+---
+
+* Pull Request #190: OS X backend now exposes a ``keychain``
+  attribute, which if set will be used by ``get_password`` when
+  retrieving passwords. Useful in environments such as when
+  running under cron where the default keychain is not the same
+  as the default keychain in a login session. Example usage::
+
+    keyring.get_keyring().keychain = '/path/to/login.keychain'
+    pw = keyring.get_password(...)
+
+---
+7.1
+---
+
+* Issue #186: Removed preference for keyrings based on
+  ``XDG_CURRENT_DESKTOP`` as these values are to varied
+  to be a reliable indicator of which keyring implementation
+  might be preferable.
+
+-----
+7.0.2
+-----
+
+* Issue #187: Restore ``Keyring`` name in ``kwallet`` backend.
+  Users of keyring 6.1 or later should prefer an explicit reference
+  to DBusKeyring or QtKeyring instead.
+
+-----
+7.0.1
+-----
+
+* Issue #183 and Issue #185: Gnome keyring no longer relies
+  on environment variables, but instead relies on the GnomeKeyring
+  library to determine viability.
+
+---
+7.0
+---
+
+* Issue #99: Keyring now expects the config file to be located
+  in the XDG_CONFIG_HOME rather than XDG_DATA_HOME and will
+  fail to start if the config is found in the old location but not
+  the new. On systems where the two locations are distinct,
+  simply copy or symlink the config to remain compatible with
+  older versions or move the file to work only with 7.0 and later.
+
+* Replaced Pull Request #182 with a conditional SessionBus
+  construction, based on subsequent discussion.
+
+-----
+6.1.1
+-----
+
+* Pull Request #182: Prevent DBus from indicating as a viable
+  backend when no viable X DISPLAY variable is present.
+
+---
 6.1
 ---
 
diff --git a/PKG-INFO b/PKG-INFO
index 24a0c8a..88ade69 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: keyring
-Version: 6.1
+Version: 7.3
 Summary: Store and access your passwords safely.
 Home-page: https://github.com/jaraco/keyring
 Author: Jason R. Coombs
diff --git a/conftest.py b/conftest.py
index de96864..073f7f0 100644
--- a/conftest.py
+++ b/conftest.py
@@ -1,8 +1,8 @@
 import platform
 
 collect_ignore = [
-	"hook-keyring.backend.py",
+    "hook-keyring.backend.py",
 ]
 
 if platform.system() != 'Windows':
-	collect_ignore.append('keyring/backends/_win_crypto.py')
+    collect_ignore.append('keyring/backends/_win_crypto.py')
diff --git a/keyring.egg-info/PKG-INFO b/keyring.egg-info/PKG-INFO
index 24a0c8a..88ade69 100644
--- a/keyring.egg-info/PKG-INFO
+++ b/keyring.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: keyring
-Version: 6.1
+Version: 7.3
 Summary: Store and access your passwords safely.
 Home-page: https://github.com/jaraco/keyring
 Author: Jason R. Coombs
diff --git a/keyring.egg-info/SOURCES.txt b/keyring.egg-info/SOURCES.txt
index c768d20..2159d08 100644
--- a/keyring.egg-info/SOURCES.txt
+++ b/keyring.egg-info/SOURCES.txt
@@ -1,3 +1,4 @@
+.gitignore
 .hgignore
 .hgtags
 .travis.yml
@@ -21,6 +22,7 @@ keyring/errors.py
 keyring/getpassbackend.py
 keyring/http.py
 keyring/py27compat.py
+keyring/py33compat.py
 keyring.egg-info/PKG-INFO
 keyring.egg-info/SOURCES.txt
 keyring.egg-info/dependency_links.txt
@@ -34,6 +36,7 @@ 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
@@ -41,8 +44,6 @@ keyring/backends/multi.py
 keyring/backends/pyfs.py
 keyring/tests/__init__.py
 keyring/tests/mocks.py
-keyring/tests/py30compat.py
-keyring/tests/test_XDG.py
 keyring/tests/test_backend.py
 keyring/tests/test_cli.py
 keyring/tests/test_core.py
@@ -60,7 +61,6 @@ 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/XDG.py
 keyring/util/__init__.py
 keyring/util/escape.py
 keyring/util/platform_.py
diff --git a/keyring/backends/Gnome.py b/keyring/backends/Gnome.py
index 49f3f81..fd85dce 100644
--- a/keyring/backends/Gnome.py
+++ b/keyring/backends/Gnome.py
@@ -1,5 +1,3 @@
-import os
-
 try:
     import gi
     gi.require_version('GnomeKeyring', '1.0')
@@ -10,9 +8,9 @@ except (ImportError, ValueError):
 from ..backend import KeyringBackend
 from ..errors import PasswordSetError, PasswordDeleteError
 from ..util import properties
-from ..util import XDG
 from ..py27compat import unicode_str
 
+
 class Keyring(KeyringBackend):
     """Gnome Keyring"""
 
@@ -22,34 +20,21 @@ class Keyring(KeyringBackend):
     Use None for the default keyring.
     """
 
-    requisite_vars = [
-        'DISPLAY',
-        'DBUS_SESSION_BUS_ADDRESS',
-    ]
-
     @properties.ClassProperty
     @classmethod
-    @XDG.Preference('Gnome')
     def priority(cls):
         if 'GnomeKeyring' not in globals():
             raise RuntimeError("GnomeKeyring module required")
-        if not cls.has_requisite_vars():
-            raise RuntimeError("Requisite environment vars are not present")
-        return int(cls.has_requisite_vars())
+        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
 
-    @classmethod
-    def has_requisite_vars(cls):
-        """
-        Return True if the requisite environment vars are present in the
-        environment.
-        """
-        return set(cls.requisite_vars).issubset(os.environ)
-
     def _find_passwords(self, service, username, deleting=False):
         """Get password of the username for the service
         """
diff --git a/keyring/backends/OS_X.py b/keyring/backends/OS_X.py
index f4f7472..d1814ef 100644
--- a/keyring/backends/OS_X.py
+++ b/keyring/backends/OS_X.py
@@ -29,6 +29,9 @@ class Keyring(KeyringBackend):
                                 """(?:"(?P<pw>.*)")?""")
     store = 'generic'
 
+    keychain = None
+    "Pathname to keychain filename, overriding default keychain."
+
     @properties.ClassProperty
     @classmethod
     def priority(cls):
@@ -111,6 +114,8 @@ class Keyring(KeyringBackend):
                 '-a', username,
                 '-s', service,
             ]
+            if self.keychain:
+                cmd.append(self.keychain)
             call = subprocess.Popen(
                 cmd,
                 stderr=subprocess.PIPE,
diff --git a/keyring/backends/SecretService.py b/keyring/backends/SecretService.py
index 7b77f0c..4d0328b 100644
--- a/keyring/backends/SecretService.py
+++ b/keyring/backends/SecretService.py
@@ -1,7 +1,6 @@
 import logging
 
 from ..util import properties
-from ..util import XDG
 from ..backend import KeyringBackend
 from ..errors import (InitError, PasswordDeleteError,
     ExceptionRaisedContext)
@@ -19,7 +18,6 @@ class Keyring(KeyringBackend):
 
     @properties.ClassProperty
     @classmethod
-    @XDG.Preference('Gnome')
     def priority(cls):
         with ExceptionRaisedContext() as exc:
             secretstorage.__name__
diff --git a/keyring/backends/__init__.py b/keyring/backends/__init__.py
index 792d600..e69de29 100644
--- a/keyring/backends/__init__.py
+++ b/keyring/backends/__init__.py
@@ -1 +0,0 @@
-#
diff --git a/keyring/backends/fail.py b/keyring/backends/fail.py
new file mode 100644
index 0000000..58fef6a
--- /dev/null
+++ b/keyring/backends/fail.py
@@ -0,0 +1,20 @@
+from ..backend import KeyringBackend
+
+
+class Keyring(KeyringBackend):
+    """
+    Keyring that raises error on every operation.
+
+    >>> kr = Keyring()
+    >>> kr.get_password('svc', 'user')
+    Traceback (most recent call last):
+    ...
+    RuntimeError: ...
+    """
+
+    priority = 0
+
+    def get_password(self, service, username, password=None):
+        raise RuntimeError("No recommended password was available")
+
+    set_password = delete_pasword = get_password
diff --git a/keyring/backends/kwallet.py b/keyring/backends/kwallet.py
index c32cf52..94f7924 100644
--- a/keyring/backends/kwallet.py
+++ b/keyring/backends/kwallet.py
@@ -8,7 +8,6 @@ from ..backend import KeyringBackend
 from ..errors import PasswordDeleteError
 from ..errors import PasswordSetError, ExceptionRaisedContext
 from ..util import properties
-from ..util import XDG
 
 # mixing Qt4 & Qt5 causes errors and may segfault
 if 'PyQt5' not in sys.modules:
@@ -64,7 +63,6 @@ class QtKeyring(KeyringBackend):
 
     @properties.ClassProperty
     @classmethod
-    @XDG.Preference('KDE')
     def priority(cls):
         with ExceptionRaisedContext() as exc:
             KWallet.__name__
@@ -126,12 +124,13 @@ class DBusKeyring(KeyringBackend):
 
     @properties.ClassProperty
     @classmethod
-    @XDG.Preference('KDE')
     def priority(cls):
         if 'dbus' not in globals():
             raise RuntimeError('python-dbus not installed')
-        # make sure kwalletd is accessible
-        bus = dbus.SessionBus()
+        try:
+            bus = dbus.SessionBus()
+        except dbus.DBusException as exc:
+            raise RuntimeError(exc.get_dbus_message())
         try:
             bus.get_object('org.kde.kwalletd', '/modules/kwalletd')
         except dbus.DBusException:
@@ -194,3 +193,7 @@ class DBusKeyring(KeyringBackend):
         if not self.iface.hasEntry(self.handle, self.folder, key, self.appid):
             raise PasswordDeleteError("Password not found")
         self.iface.removeEntry(self.handle, self.folder, key, self.appid)
+
+
+# for backward compatibility
+Keyring = QtKeyring
diff --git a/keyring/core.py b/keyring/core.py
index 6d193c9..8faeebc 100644
--- a/keyring/core.py
+++ b/keyring/core.py
@@ -1,17 +1,21 @@
 """
-core.py
-
-Created by Kang Zhang on 2009-07-09
+Core API functions and initialization routines.
 """
+
 import os
 import sys
 import logging
+import operator
 
-from .py27compat import configparser
+from .py27compat import configparser, filter
+from .py33compat import max
 
 from . import logger
 from . import backend
 from .util import platform_ as platform
+from .util import once
+from .backends import fail
+
 
 log = logging.getLogger(__name__)
 
@@ -50,24 +54,51 @@ def delete_password(service_name, username):
     _keyring_backend.delete_password(service_name, username)
 
 
-def init_backend():
+recommended = lambda backend: backend.priority >= 1
+by_priority = operator.attrgetter('priority')
+
+
+def init_backend(limit=None):
     """
     Load a keyring specified in the config file or infer the best available.
     """
     _load_library_extensions()
-    set_keyring(load_config() or _get_best_keyring())
+    keyrings = filter(limit, backend.get_all_keyring())
+
+    set_keyring(
+        load_config()
+        or max(keyrings, default=fail.Keyring, key=by_priority)
+    )
 
 
-def _get_best_keyring():
+def _load_keyring_class(keyring_name):
     """
-    Return the best keyring backend for the given environment based on
-    priority.
+    Load the keyring class indicated by name.
+
+    These popular names are tested to ensure their presence.
+
+    >>> popular_names = [
+    ...      'keyring.backends.Windows.WinVaultKeyring',
+    ...      'keyring.backends.OS_X.Keyring',
+    ...      'keyring.backends.kwallet.DBusKeyring',
+    ...      'keyring.backends.SecretService.Keyring',
+    ...      'keyring.backends.Gnome.Keyring',
+    ...  ]
+    >>> list(map(_load_keyring_class, popular_names))
+    [...]
+
+    These legacy names are retained for compatibility.
+
+    >>> legacy_names = [
+    ...      'keyring.backends.kwallet.Keyring',
+    ...  ]
+    >>> list(map(_load_keyring_class, legacy_names))
+    [...]
     """
-    keyrings = backend.get_all_keyring()
-    # rank by priority
-    keyrings.sort(key = lambda x: -x.priority)
-    # get the most recommended one
-    return keyrings[0]
+    module_name, sep, class_name = keyring_name.rpartition('.')
+    __import__(module_name)
+    module = sys.modules[module_name]
+    return getattr(module, class_name)
 
 
 def load_keyring(keyring_name):
@@ -75,10 +106,7 @@ def load_keyring(keyring_name):
     Load the specified keyring by name (a fully-qualified name to the
     keyring, such as 'keyring.backends.file.PlaintextKeyring')
     """
-    module_name, sep, class_name = keyring_name.rpartition('.')
-    __import__(module_name)
-    module = sys.modules[module_name]
-    class_ = getattr(module, class_name)
+    class_ = _load_keyring_class(keyring_name)
     # invoke the priority to ensure it is viable, or raise a RuntimeError
     class_.priority
     return class_()
@@ -120,6 +148,7 @@ def _load_keyring_path(config):
     except (configparser.NoOptionError, configparser.NoSectionError):
         pass
 
+ at once
 def _load_library_extensions():
     """
     Locate all setuptools entry points by the name 'keyring backends'
diff --git a/keyring/py27compat.py b/keyring/py27compat.py
index dc868a7..fffcfb7 100644
--- a/keyring/py27compat.py
+++ b/keyring/py27compat.py
@@ -38,3 +38,8 @@ def add_metaclass(metaclass):
             orig_vars.pop(slots_var)
         return metaclass(cls.__name__, cls.__bases__, orig_vars)
     return wrapper
+
+try:
+    import builtins
+except ImportError:
+    import __builtin__ as builtins
diff --git a/keyring/py33compat.py b/keyring/py33compat.py
new file mode 100644
index 0000000..57d5b57
--- /dev/null
+++ b/keyring/py33compat.py
@@ -0,0 +1,31 @@
+"""
+Compatibility support for Python 3.3. Remove when Python 3.3 support is
+no longer required.
+"""
+
+from .py27compat import builtins
+
+
+def max(*args, **kwargs):
+    """
+    Add support for 'default' kwarg.
+
+    >>> max([], default='res')
+    'res'
+
+    >>> max(default='res')
+    Traceback (most recent call last):
+    ...
+    TypeError: ...
+
+    >>> max('a', 'b', default='other')
+    'b'
+    """
+    missing = object()
+    default = kwargs.pop('default', missing)
+    try:
+        return builtins.max(*args, **kwargs)
+    except ValueError as exc:
+        if 'empty sequence' in str(exc) and default is not missing:
+            return default
+        raise
diff --git a/keyring/tests/backends/test_Gnome.py b/keyring/tests/backends/test_Gnome.py
index e5a187d..1cbeb12 100644
--- a/keyring/tests/backends/test_Gnome.py
+++ b/keyring/tests/backends/test_Gnome.py
@@ -1,9 +1,9 @@
 import types
 import sys
+import unittest
 
-from ..py30compat import unittest
 from ..test_backend import BackendBasicTests
-from ..util import Environ, NoNoneDictMutator
+from ..util import NoNoneDictMutator
 from keyring.backends import Gnome
 
 
@@ -17,10 +17,6 @@ def ImportBlesser(*names, **changes):
 @unittest.skipUnless(Gnome.Keyring.viable, "Need GnomeKeyring")
 class GnomeKeyringTestCase(BackendBasicTests, unittest.TestCase):
 
-    def environ(self):
-        return dict(DISPLAY='1',
-                    DBUS_SESSION_BUS_ADDRESS='1')
-
     def init_keyring(self):
         k = Gnome.Keyring()
 
@@ -32,22 +28,8 @@ class GnomeKeyringTestCase(BackendBasicTests, unittest.TestCase):
 
     def test_supported(self):
         with ImportBlesser('gi.repository'):
-            with Environ(**self.environ()):
-                self.assertTrue(Gnome.Keyring.viable)
+            self.assertTrue(Gnome.Keyring.viable)
 
     def test_supported_no_module(self):
         with NoNoneDictMutator(Gnome.__dict__, GnomeKeyring=None):
-            with Environ(**self.environ()):
-                self.assertFalse(Gnome.Keyring.viable)
-
-    def test_supported_no_display(self):
-        environ = self.environ()
-        environ['DISPLAY'] = None
-        with Environ(**environ):
-            self.assertFalse(Gnome.Keyring.viable)
-
-    def test_supported_no_session(self):
-        environ = self.environ()
-        environ['DBUS_SESSION_BUS_ADDRESS'] = None
-        with Environ(**environ):
             self.assertFalse(Gnome.Keyring.viable)
diff --git a/keyring/tests/backends/test_Google.py b/keyring/tests/backends/test_Google.py
index 955a181..035083d 100644
--- a/keyring/tests/backends/test_Google.py
+++ b/keyring/tests/backends/test_Google.py
@@ -1,7 +1,7 @@
 import codecs
 import base64
+import unittest
 
-from ..py30compat import unittest
 from ..test_backend import BackendBasicTests
 from keyring.backends import Google
 from keyring.credentials import SimpleCredential
diff --git a/keyring/tests/backends/test_OS_X.py b/keyring/tests/backends/test_OS_X.py
index e054b74..6ac411d 100644
--- a/keyring/tests/backends/test_OS_X.py
+++ b/keyring/tests/backends/test_OS_X.py
@@ -1,7 +1,7 @@
 import sys
+import unittest
 
 from ..test_backend import BackendBasicTests
-from ..py30compat import unittest
 from keyring.backends import OS_X
 
 def is_osx_keychain_supported():
diff --git a/keyring/tests/backends/test_SecretService.py b/keyring/tests/backends/test_SecretService.py
index c4ae738..202b014 100644
--- a/keyring/tests/backends/test_SecretService.py
+++ b/keyring/tests/backends/test_SecretService.py
@@ -1,4 +1,5 @@
-from ..py30compat import unittest
+import unittest
+
 from ..test_backend import BackendBasicTests
 from keyring.backends import SecretService
 from .. import util
diff --git a/keyring/tests/backends/test_Windows.py b/keyring/tests/backends/test_Windows.py
index e2eec3a..5fc8029 100644
--- a/keyring/tests/backends/test_Windows.py
+++ b/keyring/tests/backends/test_Windows.py
@@ -1,8 +1,7 @@
 from __future__ import print_function
 
 import sys
-
-from ..py30compat import unittest
+import unittest
 
 import keyring.backends.Windows
 from ..test_backend import BackendBasicTests
diff --git a/keyring/tests/backends/test_crypto.py b/keyring/tests/backends/test_crypto.py
index ae7b581..490cdbf 100644
--- a/keyring/tests/backends/test_crypto.py
+++ b/keyring/tests/backends/test_crypto.py
@@ -1,6 +1,6 @@
+import unittest
 import mock
 
-from ..py30compat import unittest
 from .test_file import FileKeyringTests
 
 from keyring.backends import file
diff --git a/keyring/tests/backends/test_file.py b/keyring/tests/backends/test_file.py
index e27db94..936678c 100644
--- a/keyring/tests/backends/test_file.py
+++ b/keyring/tests/backends/test_file.py
@@ -2,8 +2,7 @@ import os
 import tempfile
 import sys
 import errno
-
-from ..py30compat import unittest
+import unittest
 
 from ..test_backend import BackendBasicTests
 from ..util import random_string
diff --git a/keyring/tests/backends/test_keyczar.py b/keyring/tests/backends/test_keyczar.py
index d83f20c..67af26b 100644
--- a/keyring/tests/backends/test_keyczar.py
+++ b/keyring/tests/backends/test_keyczar.py
@@ -1,6 +1,5 @@
 import os
-
-from ..py30compat import unittest
+import unittest
 
 from keyring.backends import keyczar
 from .. import mocks
diff --git a/keyring/tests/backends/test_kwallet.py b/keyring/tests/backends/test_kwallet.py
index 2df8b1c..e784e80 100644
--- a/keyring/tests/backends/test_kwallet.py
+++ b/keyring/tests/backends/test_kwallet.py
@@ -1,4 +1,4 @@
-from ..py30compat import unittest
+import unittest
 
 from keyring.backends import kwallet
 from ..test_backend import BackendBasicTests
diff --git a/keyring/tests/backends/test_multi.py b/keyring/tests/backends/test_multi.py
index 080a366..3460451 100644
--- a/keyring/tests/backends/test_multi.py
+++ b/keyring/tests/backends/test_multi.py
@@ -1,4 +1,4 @@
-from ..py30compat import unittest
+import unittest
 
 from keyring.backend import KeyringBackend
 from keyring.backends import multi
diff --git a/keyring/tests/backends/test_pyfs.py b/keyring/tests/backends/test_pyfs.py
index c01aac4..d3b6877 100644
--- a/keyring/tests/backends/test_pyfs.py
+++ b/keyring/tests/backends/test_pyfs.py
@@ -3,8 +3,7 @@ from __future__ import unicode_literals
 import os
 import tempfile
 import textwrap
-
-from ..py30compat import unittest
+import unittest
 
 import keyring.backend
 from keyring.backends import pyfs
diff --git a/keyring/tests/py30compat.py b/keyring/tests/py30compat.py
deleted file mode 100644
index 4b24c7f..0000000
--- a/keyring/tests/py30compat.py
+++ /dev/null
@@ -1,10 +0,0 @@
-"""
-Compatibility support for Python 3.0. Remove when Python 3.0 support is
-no longer required.
-"""
-import sys
-
-if sys.version_info < (2,7) or sys.version_info[:2] == (3,0):
-	import unittest2 as unittest
-else:
-	import unittest
diff --git a/keyring/tests/test_XDG.py b/keyring/tests/test_XDG.py
deleted file mode 100644
index 2a8ae5f..0000000
--- a/keyring/tests/test_XDG.py
+++ /dev/null
@@ -1,16 +0,0 @@
-from mock import patch
-
-from keyring.util import XDG
-
-class TestPreference:
-	@XDG.Preference('Unity')
-	def one(self):
-		return 1
-
-	@patch.dict('os.environ', XDG_CURRENT_DESKTOP='KDE')
-	def test_mismatch(self):
-		assert self.one() == 1
-
-	@patch.dict('os.environ', XDG_CURRENT_DESKTOP='Unity')
-	def test_match(self):
-		assert self.one() == 1.5
diff --git a/keyring/tests/test_cli.py b/keyring/tests/test_cli.py
index 74f035d..bacc397 100644
--- a/keyring/tests/test_cli.py
+++ b/keyring/tests/test_cli.py
@@ -3,8 +3,7 @@ Test case to access the keyring from the command line
 """
 
 import os.path
-
-from keyring.tests.py30compat import unittest
+import unittest
 
 import keyring.backend
 from keyring import cli
diff --git a/keyring/tests/test_util.py b/keyring/tests/test_util.py
index f433ad2..2be54e4 100644
--- a/keyring/tests/test_util.py
+++ b/keyring/tests/test_util.py
@@ -4,8 +4,7 @@
 Test for simple escape/unescape routine
 """
 
-
-from .py30compat import unittest
+import unittest
 
 from keyring.util import escape
 
diff --git a/keyring/util/XDG.py b/keyring/util/XDG.py
deleted file mode 100644
index 6830417..0000000
--- a/keyring/util/XDG.py
+++ /dev/null
@@ -1,25 +0,0 @@
-import os
-import functools
-
-class Preference:
-	"""
-	A decorator wrapping a 'priority' classmethod
-	"""
-	def __init__(self, name):
-		"""
-		Create a decorator giving preference to XDG_CURRENT_DESKTOP of 'name'
-		"""
-		self.name = name
-
-	def decorate(self, func):
-		self.func = func
-		@functools.wraps(func)
-		def wrapper(*args, **kwargs):
-			return func(*args, **kwargs) * self.multiplier
-		return wrapper
-	__call__ = decorate
-
-	@property
-	def multiplier(self):
-		matches = os.environ.get('XDG_CURRENT_DESKTOP') == self.name
-		return 1.5 if matches else 1
diff --git a/keyring/util/platform_.py b/keyring/util/platform_.py
index dcdffea..b564b2e 100644
--- a/keyring/util/platform_.py
+++ b/keyring/util/platform_.py
@@ -3,37 +3,57 @@ from __future__ import absolute_import
 import os
 import platform
 
+
 def _settings_root_XP():
-	return os.path.join(os.environ['USERPROFILE'], 'Local Settings')
+    return os.path.join(os.environ['USERPROFILE'], 'Local Settings')
 
 def _settings_root_Vista():
-	return os.environ.get('LOCALAPPDATA', os.environ.get('ProgramData', '.'))
+    return os.environ.get('LOCALAPPDATA', os.environ.get('ProgramData', '.'))
 
 def _data_root_Windows():
-	release, version, csd, ptype = platform.win32_ver()
-	root = _settings_root_XP() if release == 'XP' else _settings_root_Vista()
-	return os.path.join(root, 'Python Keyring')
+    release, version, csd, ptype = platform.win32_ver()
+    root = _settings_root_XP() if release == 'XP' else _settings_root_Vista()
+    return os.path.join(root, 'Python Keyring')
 
 def _data_root_Linux():
-	"""
-	Use freedesktop.org Base Dir Specfication to determine storage
-	location.
-	"""
-	fallback = os.path.expanduser('~/.local/share')
-	root = os.environ.get('XDG_DATA_HOME', None) or fallback
-	return os.path.join(root, 'python_keyring')
+    """
+    Use freedesktop.org Base Dir Specfication to determine storage
+    location.
+    """
+    fallback = os.path.expanduser('~/.local/share')
+    root = os.environ.get('XDG_DATA_HOME', None) or fallback
+    return os.path.join(root, 'python_keyring')
 
 _config_root_Windows = _data_root_Windows
 
+def _check_old_config_root():
+    """
+    Prior versions of keyring would search for the config
+    in XDG_DATA_HOME, but should probably have been
+    searching for config in XDG_CONFIG_HOME. If the
+    config exists in the former but not in the latter,
+    raise a RuntimeError to force the change.
+    """
+    # disable the check - once is enough and avoids infinite loop
+    globals()['_check_old_config_root'] = lambda: None
+    config_file_new = os.path.join(_config_root_Linux(), 'keyringrc.cfg')
+    config_file_old = os.path.join(_data_root_Linux(), 'keyringrc.cfg')
+    if os.path.isfile(config_file_old) and not os.path.isfile(config_file_new):
+        msg = ("Keyring config exists only in the old location "
+            "{config_file_old} and should be moved to {config_file_new} "
+            "to work with this version of keyring.")
+        raise RuntimeError(msg.format(**locals()))
+
 def _config_root_Linux():
-	"""
-	Use freedesktop.org Base Dir Specfication to determine config
-	location.
-	"""
-	fallback = os.path.expanduser('~/.local/share')
-	key = 'XDG_DATA_HOME' # TODO: use XDG_CONFIG_HOME, ref #99.
-	root = os.environ.get(key, None) or fallback
-	return os.path.join(root, 'python_keyring')
+    """
+    Use freedesktop.org Base Dir Specfication to determine config
+    location.
+    """
+    _check_old_config_root()
+    fallback = os.path.expanduser('~/.local/share')
+    key = 'XDG_CONFIG_HOME'
+    root = os.environ.get(key, None) or fallback
+    return os.path.join(root, 'python_keyring')
 
 # by default, use Unix convention
 data_root = globals().get('_data_root_' + platform.system(), _data_root_Linux)

-- 
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