From: Brian Warner Date: Wed, 21 May 2008 16:43:49 +0000 (-0700) Subject: util.dictutil: move DictOfSets out to a separate utility module X-Git-Tag: allmydata-tahoe-1.1.0~89 X-Git-Url: https://git.rkrishnan.org/simplejson/...?a=commitdiff_plain;h=fe44b8fb4b73bfcca7ab9be16fe7e871a0402c40;p=tahoe-lafs%2Ftahoe-lafs.git util.dictutil: move DictOfSets out to a separate utility module --- diff --git a/src/allmydata/mutable/common.py b/src/allmydata/mutable/common.py index 6aed45d1..6504909b 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 00000000..45234eea --- /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] +