###--------------------------------------------------------------------------
### Password storage.
-class PWIter (object):
- """
- I am an iterator over items in a password database.
-
- I implement the usual Python iteration protocol.
- """
-
- def __init__(me, pw):
- """
- Initialize a PWIter object, to fetch items from PW.
- """
- me.pw = pw
- me.k = me.pw.db.firstkey()
-
- def next(me):
- """
- Return the next tag from the database.
-
- Raises StopIteration if there are no more tags.
- """
- k = me.k
- while True:
- if k is None:
- raise StopIteration
- if k[0] == '$':
- break
- k = me.pw.db.nextkey(k)
- me.k = me.pw.db.nextkey(k)
- return me.pw.unpack(me.pw.db[k])[0]
-
class PW (object):
"""
I represent a secure (ish) password store.
"""
Iterate over the known password tags.
"""
- return PWIter(me)
+ k = me.db.firstkey()
+ while k is not None:
+ if k[0] == '$': yield me.unpack(me.db[k])[0]
+ k = me.db.nextkey(k)
###----- That's all, folks --------------------------------------------------