From: Brian Warner Date: Wed, 28 Mar 2007 05:17:31 +0000 (-0700) Subject: update ReplicatingEncoder and decoder to match the current ICodecEncoder/decoder... X-Git-Url: https://git.rkrishnan.org/?a=commitdiff_plain;h=0ee2f0f3bf3cb615e54aaf1adfb7b573650a7ed0;p=tahoe-lafs%2Ftahoe-lafs.git update ReplicatingEncoder and decoder to match the current ICodecEncoder/decoder interface --- diff --git a/src/allmydata/codec.py b/src/allmydata/codec.py index 0fbbf612..0d875ebd 100644 --- a/src/allmydata/codec.py +++ b/src/allmydata/codec.py @@ -28,6 +28,8 @@ class ReplicatingEncoder(object): ENCODER_TYPE = "rep" def set_params(self, data_size, required_shares, max_shares): + assert required_shares % data_size == 0 + assert required_shares <= max_shares self.data_size = data_size self.required_shares = required_shares self.max_shares = max_shares @@ -41,7 +43,12 @@ class ReplicatingEncoder(object): def get_share_size(self): return self.data_size - def encode(self, data, desired_shareids=None): + def encode(self, inshares, desired_shareids=None): + assert isinstance(data, list) + for inshare in inshares: + assert isinstance(inshare, str) + assert self.required_shares * len(inshare) == self.data_size + data = "".join(inshares) if desired_shareids is None: desired_shareids = range(self.max_shares) shares = [data for i in desired_shareids] @@ -59,7 +66,7 @@ class ReplicatingDecoder(object): def decode(self, some_shares, their_shareids): assert len(some_shares) == self.required_shares assert len(some_shares) == len(their_shareids) - return defer.succeed(some_shares[0]) + return defer.succeed([some_shares[0]]) class Encoder(object):