From: david-sarah Date: Fri, 29 Jan 2010 03:52:10 +0000 (-0800) Subject: Eliminate 'foo if test else bar' syntax that isn't supported by Python 2.4 X-Git-Url: https://git.rkrishnan.org/simplejson/%22news.html/configuration.txt?a=commitdiff_plain;h=14280b009c9fcf0ca4ba93c6ee5166949fecffe5;p=tahoe-lafs%2Ftahoe-lafs.git Eliminate 'foo if test else bar' syntax that isn't supported by Python 2.4 --- diff --git a/src/allmydata/nodemaker.py b/src/allmydata/nodemaker.py index 8cc5052c..a30efbff 100644 --- a/src/allmydata/nodemaker.py +++ b/src/allmydata/nodemaker.py @@ -58,7 +58,10 @@ class NodeMaker: # The name doesn't matter for caching since it's only used in the error # attribute of an UnknownNode, and we don't cache those. - memokey = ("I" if deep_immutable else "M") + bigcap + if deep_immutable: + memokey = "I" + bigcap + else: + memokey = "M" + bigcap if memokey in self._node_cache: return self._node_cache[memokey] cap = uri.from_string(bigcap, deep_immutable=deep_immutable, name=name) diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 6b363c57..6b2f9653 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -3265,7 +3265,10 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase, ShouldFailMixin): mo = re.search(r'More Info', res) info_url = mo.group(1) self.failUnlessEqual(info_url, "%s?t=info" % (str(name),)) - d.addCallback(_check_directory_html, "-IMM" if immutable else "") + if immutable: + d.addCallback(_check_directory_html, "-IMM") + else: + d.addCallback(_check_directory_html, "") d.addCallback(lambda ign: self.GET(self.rooturl+"?t=json")) def _check_directory_json(res, expect_rw_uri): @@ -3277,8 +3280,10 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase, ShouldFailMixin): self.failUnlessEqual(f[1]["rw_uri"], future_write_uri) else: self.failIfIn("rw_uri", f[1]) - self.failUnlessEqual(f[1]["ro_uri"], - ("imm." if immutable else "ro.") + future_read_uri) + if immutable: + self.failUnlessEqual(f[1]["ro_uri"], "imm." + future_read_uri) + else: + self.failUnlessEqual(f[1]["ro_uri"], "ro." + future_read_uri) self.failUnless("metadata" in f[1]) d.addCallback(_check_directory_json, expect_rw_uri=not immutable) @@ -3311,8 +3316,17 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase, ShouldFailMixin): self.failUnlessEqual(data[1]["rw_uri"], future_write_uri) else: self.failIfIn("rw_uri", data[1]) - self.failUnlessEqual(data[1]["ro_uri"], - ("imm." if immutable else "ro.") + future_read_uri) + + if immutable: + self.failUnlessEqual(data[1]["ro_uri"], "imm." + future_read_uri) + self.failUnlessEqual(data[1]["mutable"], False) + elif expect_rw_uri: + self.failUnlessEqual(data[1]["ro_uri"], "ro." + future_read_uri) + self.failUnlessEqual(data[1]["mutable"], True) + else: + self.failUnlessEqual(data[1]["ro_uri"], "ro." + future_read_uri) + self.failIf("mutable" in data[1], data[1]) + # TODO: check metadata contents self.failUnless("metadata" in data[1]) @@ -3323,7 +3337,11 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase, ShouldFailMixin): # rendered too. This version will not have future_write_uri, whether # or not future_node was immutable. d.addCallback(lambda ign: self.GET(self.rourl)) - d.addCallback(_check_directory_html, "-IMM" if immutable else "-RO") + if immutable: + d.addCallback(_check_directory_html, "-IMM") + else: + d.addCallback(_check_directory_html, "-RO") + d.addCallback(lambda ign: self.GET(self.rourl+"?t=json")) d.addCallback(_check_directory_json, expect_rw_uri=False)