From 2abe74251ed389f76cd990de4b05658857ea30af Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sun, 24 May 2015 18:06:03 +0100 Subject: [PATCH] catacomb/pwsafe.py: Abolish the `PWIter' class. There's no identifiable advantage to writing all of that out longhand over a simple generator. So do that instead. --- catacomb/pwsafe.py | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/catacomb/pwsafe.py b/catacomb/pwsafe.py index 3af69d4..65aec71 100644 --- a/catacomb/pwsafe.py +++ b/catacomb/pwsafe.py @@ -126,36 +126,6 @@ class PPK (Crypto): ###-------------------------------------------------------------------------- ### 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. @@ -324,6 +294,9 @@ class PW (object): """ 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 -------------------------------------------------- -- 2.11.0