Пример #1
0
def _file_json_metadata(req, filenode, edge_metadata):
    rw_uri = filenode.get_write_uri()
    ro_uri = filenode.get_readonly_uri()
    data = ("filenode", get_filenode_metadata(filenode))
    if ro_uri:
        data[1]['ro_uri'] = ro_uri
    if rw_uri:
        data[1]['rw_uri'] = rw_uri
    verifycap = filenode.get_verify_cap()
    if verifycap:
        data[1]['verify_uri'] = verifycap.to_string()
    if edge_metadata is not None:
        data[1]['metadata'] = edge_metadata

    return text_plain(json.dumps(data, indent=1) + "\n", req)
Пример #2
0
def FileJSONMetadata(ctx, filenode, edge_metadata):
    rw_uri = filenode.get_write_uri()
    ro_uri = filenode.get_readonly_uri()
    data = ("filenode", get_filenode_metadata(filenode))
    if ro_uri:
        data[1]['ro_uri'] = ro_uri
    if rw_uri:
        data[1]['rw_uri'] = rw_uri
    verifycap = filenode.get_verify_cap()
    if verifycap:
        data[1]['verify_uri'] = verifycap.to_string()
    if edge_metadata is not None:
        data[1]['metadata'] = edge_metadata

    return text_plain(json.dumps(data, indent=1) + "\n", ctx)
Пример #3
0
    def _got(children):
        kids = {}
        for name, (childnode, metadata) in children.iteritems():
            assert IFilesystemNode.providedBy(childnode), childnode
            rw_uri = childnode.get_write_uri()
            ro_uri = childnode.get_readonly_uri()
            if IFileNode.providedBy(childnode):
                kiddata = ("filenode", get_filenode_metadata(childnode))
            elif IDirectoryNode.providedBy(childnode):
                kiddata = ("dirnode", {'mutable': childnode.is_mutable()})
            else:
                kiddata = ("unknown", {})

            kiddata[1]["metadata"] = metadata
            if rw_uri:
                kiddata[1]["rw_uri"] = rw_uri
            if ro_uri:
                kiddata[1]["ro_uri"] = ro_uri
            verifycap = childnode.get_verify_cap()
            if verifycap:
                kiddata[1]['verify_uri'] = verifycap.to_string()

            kids[name] = kiddata

        drw_uri = dirnode.get_write_uri()
        dro_uri = dirnode.get_readonly_uri()
        contents = { 'children': kids }
        if dro_uri:
            contents['ro_uri'] = dro_uri
        if drw_uri:
            contents['rw_uri'] = drw_uri
        verifycap = dirnode.get_verify_cap()
        if verifycap:
            contents['verify_uri'] = verifycap.to_string()
        contents['mutable'] = dirnode.is_mutable()
        data = ("dirnode", contents)
        json = simplejson.dumps(data, indent=1) + "\n"
        return json
Пример #4
0
    def _got(children):
        kids = {}
        for name, (childnode, metadata) in children.iteritems():
            assert IFilesystemNode.providedBy(childnode), childnode
            rw_uri = childnode.get_write_uri()
            ro_uri = childnode.get_readonly_uri()
            if IFileNode.providedBy(childnode):
                kiddata = ("filenode", get_filenode_metadata(childnode))
            elif IDirectoryNode.providedBy(childnode):
                kiddata = ("dirnode", {'mutable': childnode.is_mutable()})
            else:
                kiddata = ("unknown", {})

            kiddata[1]["metadata"] = metadata
            if rw_uri:
                kiddata[1]["rw_uri"] = rw_uri
            if ro_uri:
                kiddata[1]["ro_uri"] = ro_uri
            verifycap = childnode.get_verify_cap()
            if verifycap:
                kiddata[1]['verify_uri'] = verifycap.to_string()

            kids[name] = kiddata

        drw_uri = dirnode.get_write_uri()
        dro_uri = dirnode.get_readonly_uri()
        contents = { 'children': kids }
        if dro_uri:
            contents['ro_uri'] = dro_uri
        if drw_uri:
            contents['rw_uri'] = drw_uri
        verifycap = dirnode.get_verify_cap()
        if verifycap:
            contents['verify_uri'] = verifycap.to_string()
        contents['mutable'] = dirnode.is_mutable()
        data = ("dirnode", contents)
        json = simplejson.dumps(data, indent=1) + "\n"
        return json
 def test_size_is_None(self):
     """If get_size returns None the returned metadata must not contain "size"."""
     mockfilenode = MockFileNode(None, mutable_version=self.mutable_version)
     metadata = get_filenode_metadata(mockfilenode)
     self.failIfIn('size', metadata)
 def test_size_is_1000(self):
     """1000 is sufficiently large to guarantee the cap is not a literal."""
     mockfilenode = MockFileNode(1000, mutable_version=self.mutable_version)
     metadata = get_filenode_metadata(mockfilenode)
     self.failUnlessEqual(metadata['size'], 1000)
 def test_size_is_0(self):
     """If get_size doesn't return None the returned metadata must contain "size"."""
     mockfilenode = MockFileNode(0, mutable_version=self.mutable_version)
     metadata = get_filenode_metadata(mockfilenode)
     self.failUnlessEqual(metadata['size'], 0)
Пример #8
0
 def test_size_is_None(self):
     """If get_size returns None the returned metadata must not contain "size"."""
     self.mockfilenode.get_size.return_value = None
     metadata = get_filenode_metadata(self.mockfilenode)
     self.failIfIn('size', metadata)
Пример #9
0
 def test_size_is_1000(self):
     """1000 is sufficiently large to guarantee the cap is not a literal."""
     self.mockfilenode.get_size.return_value = 1000
     metadata = get_filenode_metadata(self.mockfilenode)
     self.failUnlessIn('size', metadata)
Пример #10
0
 def test_size_is_0(self):
     """If get_size doesn't return None the returned metadata must contain "size"."""
     self.mockfilenode.get_size.return_value = 0
     metadata = get_filenode_metadata(self.mockfilenode)
     self.failUnlessIn('size', metadata)