Ancora sulla libreria keyring di python
Posted: maggio 7th, 2011 | Author: Francesco Apollonio | Filed under: Programmazione | Tags: bug, code tips, kde, keyring, linux, patch, plugin, python, utility, varie | No Comments »
Mi serviva utilizzare la libreria in oggetto tramite una connessione ssh, questo crea non pochi problemi dato che, per come è realizzata ora la libreria, cerca di avviare KDEWallet anche se, tramite il file di configurazione keyringrc.cfg, è stato impostato come default-keyring CryptedFileKeyring o qualcos’altro.
Ora o ci si connette via ssh con -X ma ovviamente è tremendamente lento e soprattutto carica molti componenti kde, o si cerca di risolvere il problema in altro modo (ovviamente la seconda soluzione è la migliore).
Questa è l’altro modo (premere sul link per scaricare il file contenente le modifiche):
diff -r 261dcb3cf624 keyring/backend.py
--- a/keyring/backend.py Thu Apr 21 14:14:55 2011 +0200
+++ b/keyring/backend.py Wed May 04 16:45:01 2011 +0200
@@ -190,14 +190,19 @@
except ImportError:
kwallet = None
else:
- kwallet = open_kwallet()
+ kwallet = True
class KDEKWallet(KeyringBackend):
"""KDE KWallet"""
+ def __init__(self):
+ self.kwallet=None
+ if kwallet:
+ self.kwallet=open_kwallet()
+
def supported(self):
- if kwallet is None:
+ if self.kwallet is None:
return -1
else:
return 1
@@ -207,7 +212,7 @@
"""
key = username + '@' + service
network = KWallet.Wallet.NetworkWallet()
- if kwallet.keyDoesNotExist(network, 'Python', key):
+ if self.kwallet.keyDoesNotExist(network, 'Python', key):
return None
result = kwallet.readPassword(key)[1]
@@ -218,7 +223,7 @@
def set_password(self, service, username, password):
"""Set password for the username of the service
"""
- kwallet.writePassword(username+'@'+service, password)
+ self.kwallet.writePassword(username+'@'+service, password)
class BasicFileKeyring(KeyringBackend):
"""BasicFileKeyring is a filebased implementation of keyring.
@@ -481,7 +486,7 @@
self.pywintypes = pywintypes
except ImportError:
self.win32cred = None
-
+
def supported(self):
'''Default Windows backend, when it is available
'''
@@ -492,19 +497,19 @@
return 1
else:
return 0
-
+
def get_password(self, service, username):
try:
- blob = self.win32cred.CredRead(Type=self.win32cred.CRED_TYPE_GENERIC,
+ blob = self.win32cred.CredRead(Type=self.win32cred.CRED_TYPE_GENERIC,
TargetName=service)['CredentialBlob']
except self.pywintypes.error, e:
if e[:2] == (1168, 'CredRead'):
return None
raise
return blob.decode("utf16")
-
+
def set_password(self, service, username, password):
- credential = dict(Type=self.win32cred.CRED_TYPE_GENERIC,
+ credential = dict(Type=self.win32cred.CRED_TYPE_GENERIC,
TargetName=service,
UserName=username,
CredentialBlob=unicode(password),
Questa è la patch da applicare dopo aver scaricato tramite:
hg clone https://bitbucket.org/kang/python-keyring-libÈ stata inviata una segnalazione agli sviluppatori, attendiamo che venga inserita nei sorgenti ufficiali.








Leave a Reply