From: Brian Warner Date: Wed, 5 Dec 2007 07:20:34 +0000 (-0700) Subject: storage.py: factor out a common compare() routine X-Git-Url: https://git.rkrishnan.org/configuration.txt?a=commitdiff_plain;h=841c1a8509951f39ffbf4ccfe785e57a47dd1ece;p=tahoe-lafs%2Ftahoe-lafs.git storage.py: factor out a common compare() routine --- diff --git a/src/allmydata/storage.py b/src/allmydata/storage.py index 1e99fcef..24e584d1 100644 --- a/src/allmydata/storage.py +++ b/src/allmydata/storage.py @@ -572,7 +572,7 @@ class MutableShareFile: f = open(self.home, 'rb+') for (offset, length, operator, specimen) in testv: data = self._read_share_data(f, offset, length) - if not self.compare(data, operator, specimen): + if not testv_compare(data, operator, specimen): test_good = False break f.close() @@ -588,21 +588,21 @@ class MutableShareFile: f.write(struct.pack(">Q", new_length)) f.close() - def compare(self, a, op, b): - assert op in ("lt", "le", "eq", "ne", "ge", "gt") - if op == "lt": - return a < b - if op == "le": - return a <= b - if op == "eq": - return a == b - if op == "ne": - return a != b - if op == "ge": - return a >= b - if op == "gt": - return a > b - # never reached +def testv_compare(a, op, b): + assert op in ("lt", "le", "eq", "ne", "ge", "gt") + if op == "lt": + return a < b + if op == "le": + return a <= b + if op == "eq": + return a == b + if op == "ne": + return a != b + if op == "ge": + return a >= b + if op == "gt": + return a > b + # never reached class EmptyShare: @@ -610,27 +610,11 @@ class EmptyShare: test_good = True for (offset, length, operator, specimen) in testv: data = "" - if not self.compare(data, operator, specimen): + if not testv_compare(data, operator, specimen): test_good = False break return test_good - def compare(self, a, op, b): - assert op in ("lt", "le", "eq", "ne", "ge", "gt") - if op == "lt": - return a < b - if op == "le": - return a <= b - if op == "eq": - return a == b - if op == "ne": - return a != b - if op == "ge": - return a >= b - if op == "gt": - return a > b - # never reached - def create_mutable_sharefile(filename, my_nodeid, write_enabler): ms = MutableShareFile(filename) ms.create(my_nodeid, write_enabler)