From e63f59f50c0efbee5ea84a05d5b370de5c20e16a Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 12 Oct 2009 22:21:54 -0700 Subject: [PATCH] test/common.py: update FakeMutableFileNode to new contents= callable scheme --- src/allmydata/test/common.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/allmydata/test/common.py b/src/allmydata/test/common.py index 2be08878..5bc2f141 100644 --- a/src/allmydata/test/common.py +++ b/src/allmydata/test/common.py @@ -157,13 +157,22 @@ class FakeMutableFileNode: def __init__(self, storage_broker, secret_holder, default_encoding_parameters, history): self.init_from_uri(make_mutable_file_uri()) - def create(self, initial_contents, key_generator=None, keysize=None): + def create(self, contents, key_generator=None, keysize=None): + initial_contents = self._get_initial_contents(contents) if len(initial_contents) > self.MUTABLE_SIZELIMIT: raise FileTooLargeError("SDMF is limited to one segment, and " "%d > %d" % (len(initial_contents), self.MUTABLE_SIZELIMIT)) self.all_contents[self.storage_index] = initial_contents return defer.succeed(self) + def _get_initial_contents(self, contents): + if isinstance(contents, str): + return contents + if contents is None: + return "" + assert callable(contents), "%s should be callable, not %s" % \ + (contents, type(contents)) + return contents(self) def init_from_uri(self, filecap): assert isinstance(filecap, str) if filecap.startswith("URI:SSK:"): -- 2.45.2