[Python-modules-commits] r25032 - in packages/python-keyring/trunk/debian (3 files)

mitya57-guest at users.alioth.debian.org mitya57-guest at users.alioth.debian.org
Sat Jun 29 08:44:30 UTC 2013


    Date: Saturday, June 29, 2013 @ 08:44:27
  Author: mitya57-guest
Revision: 25032

debian/patches/backend-compatibility.patch: make the GNOME Keyring
backend compatible with passwords stored using the SecretService
backend.

Added:
  packages/python-keyring/trunk/debian/patches/backend-compatibility.patch
Modified:
  packages/python-keyring/trunk/debian/changelog
  packages/python-keyring/trunk/debian/patches/series

Modified: packages/python-keyring/trunk/debian/changelog
===================================================================
--- packages/python-keyring/trunk/debian/changelog	2013-06-29 05:58:59 UTC (rev 25031)
+++ packages/python-keyring/trunk/debian/changelog	2013-06-29 08:44:27 UTC (rev 25032)
@@ -2,8 +2,11 @@
 
   * New upstream release.
   * Drop fix-importkiller.patch, applied upstream.
+  * debian/patches/backend-compatibility.patch: make the GNOME Keyring
+    backend compatible with passwords stored using the SecretService
+    backend.
 
- -- Dmitry Shachnev <mitya57 at gmail.com>  Sun, 23 Jun 2013 20:51:53 +0400
+ -- Dmitry Shachnev <mitya57 at gmail.com>  Sat, 29 Jun 2013 12:39:14 +0400
 
 python-keyring (1.4-1) unstable; urgency=low
 

Added: packages/python-keyring/trunk/debian/patches/backend-compatibility.patch
===================================================================
--- packages/python-keyring/trunk/debian/patches/backend-compatibility.patch	                        (rev 0)
+++ packages/python-keyring/trunk/debian/patches/backend-compatibility.patch	2013-06-29 08:44:27 UTC (rev 25032)
@@ -0,0 +1,105 @@
+Description: compatibility improvements for GNOME Keyring backend
+ - Use the same attributes (username / service) as the SecretService
+   backend uses, allow searching for old ones for compatibility.
+ - Also set application attribute.
+ - Correctly handle all types of errors, not only CANCELLED and NO_MATCH.
+Author: Dmitry Shachnev <mitya57 at gmail.com>
+Forwarded: yes, https://bitbucket.org/kang/python-keyring-lib/pull-request/33/
+Bug: https://bitbucket.org/kang/python-keyring-lib/issue/104/
+Last-Update: 2013-06-29
+
+--- a/keyring/backends/Gnome.py
++++ b/keyring/backends/Gnome.py
+@@ -23,27 +23,34 @@
+             else:
+                 return 0
+ 
++    def _find_passwords(self, service, username, deleting=False):
++        from gi.repository import GnomeKeyring
++        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
+         """
+-        from gi.repository import GnomeKeyring
+-
+-        service = self._safe_string(service)
+-        username = self._safe_string(username)
+-        attrs = GnomeKeyring.Attribute.list_new()
+-        GnomeKeyring.Attribute.list_append_string(attrs, 'user', username)
+-        GnomeKeyring.Attribute.list_append_string(attrs, 'domain', service)
+-        result, items = GnomeKeyring.find_items_sync(
+-            GnomeKeyring.ItemType.NETWORK_PASSWORD, attrs)
+-        if result == GnomeKeyring.Result.IO_ERROR:
+-            return None
+-        if result == GnomeKeyring.Result.NO_MATCH:
+-            return None
+-        if result == GnomeKeyring.Result.CANCELLED:
+-            # The user pressed "Cancel" when prompted to unlock their keyring.
++        items = self._find_passwords(service, username)
++        if not items:
+             return None
+ 
+-        assert len(items) == 1, 'no more than one entry should ever match'
+         secret = items[0].secret
+         return secret if isinstance(secret, unicode) else secret.decode('utf-8')
+ 
+@@ -56,8 +63,9 @@
+         username = self._safe_string(username)
+         password = self._safe_string(password)
+         attrs = GnomeKeyring.Attribute.list_new()
+-        GnomeKeyring.Attribute.list_append_string(attrs, 'user', username)
+-        GnomeKeyring.Attribute.list_append_string(attrs, 'domain', service)
++        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),
+@@ -65,23 +73,23 @@
+         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.
+         """
+         from gi.repository import GnomeKeyring
+-        attrs = GnomeKeyring.Attribute.list_new()
+-        GnomeKeyring.Attribute.list_append_string(attrs, 'user', username)
+-        GnomeKeyring.Attribute.list_append_string(attrs, 'domain', service)
+-        result, items = GnomeKeyring.find_items_sync(
+-            GnomeKeyring.ItemType.NETWORK_PASSWORD, attrs)
+-        if result == GnomeKeyring.Result.NO_MATCH:
++        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"""

Modified: packages/python-keyring/trunk/debian/patches/series
===================================================================
--- packages/python-keyring/trunk/debian/patches/series	2013-06-29 05:58:59 UTC (rev 25031)
+++ packages/python-keyring/trunk/debian/patches/series	2013-06-29 08:44:27 UTC (rev 25032)
@@ -1,2 +1,3 @@
 no-pytest-runner.patch
 catch-dbus-errors.patch
+backend-compatibility.patch




More information about the Python-modules-commits mailing list