From fe44b8fb4b73bfcca7ab9be16fe7e871a0402c40 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 21 May 2008 09:43:49 -0700 Subject: [PATCH] util.dictutil: move DictOfSets out to a separate utility module --- src/allmydata/mutable/common.py | 17 +---------------- src/allmydata/util/dictutil.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 src/allmydata/util/dictutil.py diff --git a/src/allmydata/mutable/common.py b/src/allmydata/mutable/common.py index 6aed45d11..6504909b9 100644 --- a/src/allmydata/mutable/common.py +++ b/src/allmydata/mutable/common.py @@ -1,5 +1,6 @@ from allmydata.util import idlib +from allmydata.util.dictutil import DictOfSets MODE_CHECK = "MODE_CHECK" # query all peers MODE_ANYTHING = "MODE_ANYTHING" # one recoverable version @@ -48,22 +49,6 @@ class CorruptShareError(Exception): - - -class DictOfSets(dict): - def add(self, key, value): - if key in self: - self[key].add(value) - else: - self[key] = set([value]) - - def discard(self, key, value): - if not key in self: - return - self[key].discard(value) - if not self[key]: - del self[key] - class ResponseCache: """I cache share data, to reduce the number of round trips used during mutable file operations. All of the data in my cache is for a single diff --git a/src/allmydata/util/dictutil.py b/src/allmydata/util/dictutil.py new file mode 100644 index 000000000..45234eeaf --- /dev/null +++ b/src/allmydata/util/dictutil.py @@ -0,0 +1,15 @@ + +class DictOfSets(dict): + def add(self, key, value): + if key in self: + self[key].add(value) + else: + self[key] = set([value]) + + def discard(self, key, value): + if not key in self: + return + self[key].discard(value) + if not self[key]: + del self[key] +