From: Brian Warner Date: Thu, 23 Aug 2007 20:00:39 +0000 (-0700) Subject: webish: modify JSON to match zooko's proposed API changes in #118 X-Git-Url: https://git.rkrishnan.org/listings/index.php?a=commitdiff_plain;h=3e1c417f81077c2999e91b11652fd8ce3915df40;p=tahoe-lafs%2Ftahoe-lafs.git webish: modify JSON to match zooko's proposed API changes in #118 --- diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 6587d74a..e2356a49 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -268,17 +268,18 @@ class WebMixin(object): self.failUnless(isinstance(data, list)) self.failUnlessEqual(data[0], "filenode") self.failUnless(isinstance(data[1], dict)) - self.failUnlessEqual(data[1]["mutable"], False) + self.failIf("rw_uri" in data[1]) # immutable + self.failUnlessEqual(data[1]["ro_uri"], self._bar_txt_uri) self.failUnlessEqual(data[1]["size"], 123) - self.failUnlessEqual(data[1]["uri"], self._bar_txt_uri) def failUnlessIsFooJSON(self, res): data = self.worlds_cheapest_json_decoder(res) self.failUnless(isinstance(data, list)) self.failUnlessEqual(data[0], "dirnode") self.failUnless(isinstance(data[1], dict)) - self.failUnlessEqual(data[1]["mutable"], True) - self.failUnlessEqual(data[1]["uri"], self._foo_uri) + self.failUnless("rw_uri" in data[1]) # mutable + self.failUnlessEqual(data[1]["rw_uri"], self._foo_uri) + self.failUnlessEqual(data[1]["ro_uri"], self._foo_readonly_uri) kidnames = sorted(data[1]["children"].keys()) self.failUnlessEqual(kidnames, ["bar.txt", "blockingfile", "empty", "sub"]) @@ -286,7 +287,7 @@ class WebMixin(object): self.failUnlessEqual(kids["sub"][0], "dirnode") self.failUnlessEqual(kids["bar.txt"][0], "filenode") self.failUnlessEqual(kids["bar.txt"][1]["size"], 123) - self.failUnlessEqual(kids["bar.txt"][1]["uri"], self._bar_txt_uri) + self.failUnlessEqual(kids["bar.txt"][1]["ro_uri"], self._bar_txt_uri) def GET(self, urlpath, followRedirect=False): url = self.webish_url + urlpath diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index 52c5ffe3..7f030e81 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -398,8 +398,7 @@ class FileJSONMetadata(rend.Page): def renderNode(self, filenode): file_uri = filenode.get_uri() data = ("filenode", - {'mutable': False, - 'uri': file_uri, + {'ro_uri': file_uri, 'size': filenode.get_size(), }) return simplejson.dumps(data, indent=1) @@ -488,22 +487,22 @@ class DirectoryJSONMetadata(rend.Page): if IFileNode.providedBy(childnode): kiduri = childnode.get_uri() kiddata = ("filenode", - {'mutable': False, - 'uri': kiduri, + {'ro_uri': kiduri, 'size': childnode.get_size(), }) else: assert IDirectoryNode.providedBy(childnode) - kiduri = childnode.get_uri() kiddata = ("dirnode", - {'mutable': childnode.is_mutable(), - 'uri': kiduri, + {'ro_uri': childnode.get_immutable_uri(), }) + if childnode.is_mutable(): + kiddata[1]['rw_uri'] = childnode.get_uri() kids[name] = kiddata contents = { 'children': kids, - 'mutable': node.is_mutable(), - 'uri': node.get_uri(), + 'ro_uri': node.get_immutable_uri(), } + if node.is_mutable(): + contents['rw_uri'] = node.get_uri() data = ("dirnode", contents) return simplejson.dumps(data, indent=1) d.addCallback(_got)