# this takes URIs
a = Adder(self, overwrite=overwrite)
node_entries = []
- for e in entries:
- if len(e) == 3:
- name, writecap, readcap = e
+ for (name, e) in entries.iteritems():
+ assert isinstance(name, unicode)
+ if len(e) == 2:
+ writecap, readcap = e
metadata = None
else:
- assert len(e) == 4
- name, writecap, readcap, metadata = e
- assert isinstance(name, unicode)
+ assert len(e) == 3
+ writecap, readcap, metadata = e
precondition(isinstance(writecap, (str,type(None))), writecap)
precondition(isinstance(readcap, (str,type(None))), readcap)
child_node = self._create_node(writecap, readcap)
NotMutableError."""
def set_children(entries, overwrite=True):
- """Add multiple (name, writecap, readcap) triples (or (name,
- writecap, readcap, metadata) 4-tuples) to a directory node. Returns a
- Deferred that fires (with None) when the operation finishes. This is
- equivalent to calling set_uri() multiple times, but is much more
+ """Add multiple children (by writecap+readcap) to a directory node.
+ Takes a dictionary, with childname as keys and (writecap, readcap)
+ tuples (or (writecap, readcap, metadata) triples) as values. Returns
+ a Deferred that fires (with None) when the operation finishes. This
+ is equivalent to calling set_uri() multiple times, but is much more
efficient. All child names must be unicode strings.
"""
d.addCallback(lambda root: root.create_empty_directory(u"subdir"))
def _add_children(subdir_node):
self.subdir_node = subdir_node
- kids = []
+ kids = {}
for i in range(1, COUNT):
litcap = LiteralFileURI("%03d-data" % i).to_string()
- kids.append( (u"%03d-small" % i, litcap, litcap) )
+ kids[u"%03d-small" % i] = (litcap, litcap)
return subdir_node.set_children(kids)
d.addCallback(_add_children)
up = upload.Data("large enough for CHK" * 100, "")
# metadata through set_children()
d.addCallback(lambda res:
- n.set_children([
- (u"e1", fake_file_uri, fake_file_uri),
- (u"e2", fake_file_uri, fake_file_uri, {}),
- (u"e3", fake_file_uri, fake_file_uri,
- {"key": "value"}),
- ]))
+ n.set_children({
+ u"e1": (fake_file_uri, fake_file_uri),
+ u"e2": (fake_file_uri, fake_file_uri, {}),
+ u"e3": (fake_file_uri, fake_file_uri,
+ {"key": "value"}),
+ }))
d.addCallback(lambda res:
self.shouldFail(ExistingChildError, "set_children-no",
"child 'e1' already exists",
n.set_children,
- [ (u"e1", other_file_uri, other_file_uri),
- (u"new", other_file_uri, other_file_uri), ],
+ { u"e1": (other_file_uri,
+ other_file_uri),
+ u"new": (other_file_uri,
+ other_file_uri),
+ },
overwrite=False))
# and 'new' should not have been created
d.addCallback(lambda res: n.list())
le.args = tuple(le.args + (body,))
# TODO test handling of bad JSON
raise
- cs = []
+ cs = {}
for name, (file_or_dir, mddict) in children.iteritems():
name = unicode(name) # simplejson-2.0.1 returns str *or* unicode
writecap = mddict.get('rw_uri')
readcap = mddict.get('ro_uri')
if readcap is not None:
readcap = str(readcap)
- cs.append((name, writecap, readcap, mddict.get('metadata')))
+ cs[name] = (writecap, readcap, mddict.get('metadata'))
d = self.node.set_children(cs, replace)
d.addCallback(lambda res: "Okay so I did it.")
# TODO: results