mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-19 11:16:24 +00:00
Port to Python 3.
This commit is contained in:
parent
7516a5526e
commit
5384768f76
@ -1,4 +1,17 @@
|
||||
# -*- test-case-name: allmydata.test.test_encode_share -*-
|
||||
"""
|
||||
CRS encoding and decoding.
|
||||
|
||||
Ported to Python 3.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||
from future.utils import native_str
|
||||
|
||||
from zope.interface import implementer
|
||||
from twisted.internet import defer
|
||||
@ -27,8 +40,8 @@ class CRSEncoder(object):
|
||||
return (self.data_size, self.required_shares, self.max_shares)
|
||||
|
||||
def get_serialized_params(self):
|
||||
return "%d-%d-%d" % (self.data_size, self.required_shares,
|
||||
self.max_shares)
|
||||
return native_str("%d-%d-%d" % (self.data_size, self.required_shares,
|
||||
self.max_shares))
|
||||
|
||||
def get_block_size(self):
|
||||
return self.share_size
|
||||
@ -37,7 +50,7 @@ class CRSEncoder(object):
|
||||
precondition(desired_share_ids is None or len(desired_share_ids) <= self.max_shares, desired_share_ids, self.max_shares)
|
||||
|
||||
if desired_share_ids is None:
|
||||
desired_share_ids = range(self.max_shares)
|
||||
desired_share_ids = list(range(self.max_shares))
|
||||
|
||||
for inshare in inshares:
|
||||
assert len(inshare) == self.share_size, (len(inshare), self.share_size, self.data_size, self.required_shares)
|
||||
|
@ -1,3 +1,16 @@
|
||||
"""
|
||||
Tests for allmydata.codec.
|
||||
|
||||
Ported to Python 3.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
import os
|
||||
from twisted.trial import unittest
|
||||
@ -23,7 +36,7 @@ class T(unittest.TestCase):
|
||||
d.addCallback(_done_encoding_all)
|
||||
if fewer_shares is not None:
|
||||
# also validate that the desired_shareids= parameter works
|
||||
desired_shareids = random.sample(range(max_shares), fewer_shares)
|
||||
desired_shareids = random.sample(list(range(max_shares)), fewer_shares)
|
||||
d.addCallback(lambda res: enc.encode(data0s, desired_shareids))
|
||||
def _check_fewer_shares(some_shares_and_their_shareids):
|
||||
(some_shares, their_shareids) = some_shares_and_their_shareids
|
||||
@ -38,11 +51,11 @@ class T(unittest.TestCase):
|
||||
return d1
|
||||
|
||||
def _check_data(decoded_shares):
|
||||
self.failUnlessEqual(len(''.join(decoded_shares)), len(''.join(data0s)))
|
||||
self.failUnlessEqual(len(b''.join(decoded_shares)), len(b''.join(data0s)))
|
||||
self.failUnlessEqual(len(decoded_shares), len(data0s))
|
||||
for (i, (x, y)) in enumerate(zip(data0s, decoded_shares)):
|
||||
self.failUnlessEqual(x, y, "%s: %r != %r.... first share was %r" % (str(i), x, y, data0s[0],))
|
||||
self.failUnless(''.join(decoded_shares) == ''.join(data0s), "%s" % ("???",))
|
||||
self.failUnless(b''.join(decoded_shares) == b''.join(data0s), "%s" % ("???",))
|
||||
# 0data0sclipped = tuple(data0s)
|
||||
# data0sclipped[-1] =
|
||||
# self.failUnless(tuple(decoded_shares) == tuple(data0s))
|
||||
@ -59,7 +72,7 @@ class T(unittest.TestCase):
|
||||
def _decode_some_random(res):
|
||||
log.msg("_decode_some_random")
|
||||
# use a randomly-selected minimal subset
|
||||
l = random.sample(zip(self.shares, self.shareids), required_shares)
|
||||
l = random.sample(list(zip(self.shares, self.shareids)), required_shares)
|
||||
some_shares = [ x[0] for x in l ]
|
||||
some_shareids = [ x[1] for x in l ]
|
||||
return _decode((some_shares, some_shareids))
|
||||
@ -70,10 +83,10 @@ class T(unittest.TestCase):
|
||||
log.msg("_decode_multiple")
|
||||
# make sure we can re-use the decoder object
|
||||
shares1 = random.sample(self.shares, required_shares)
|
||||
sharesl1 = random.sample(zip(self.shares, self.shareids), required_shares)
|
||||
sharesl1 = random.sample(list(zip(self.shares, self.shareids)), required_shares)
|
||||
shares1 = [ x[0] for x in sharesl1 ]
|
||||
shareids1 = [ x[1] for x in sharesl1 ]
|
||||
sharesl2 = random.sample(zip(self.shares, self.shareids), required_shares)
|
||||
sharesl2 = random.sample(list(zip(self.shares, self.shareids)), required_shares)
|
||||
shares2 = [ x[0] for x in sharesl2 ]
|
||||
shareids2 = [ x[1] for x in sharesl2 ]
|
||||
dec = CRSDecoder()
|
||||
|
@ -15,6 +15,7 @@ if PY2:
|
||||
|
||||
# Keep these sorted alphabetically, to reduce merge conflicts:
|
||||
PORTED_MODULES = [
|
||||
"allmydata.codec",
|
||||
"allmydata.crypto",
|
||||
"allmydata.crypto.aes",
|
||||
"allmydata.crypto.ed25519",
|
||||
@ -51,6 +52,7 @@ PORTED_TEST_MODULES = [
|
||||
"allmydata.test.test_abbreviate",
|
||||
"allmydata.test.test_base32",
|
||||
"allmydata.test.test_base62",
|
||||
"allmydata.test.test_codec",
|
||||
"allmydata.test.test_crypto",
|
||||
"allmydata.test.test_deferredutil",
|
||||
"allmydata.test.test_dictutil",
|
||||
|
Loading…
Reference in New Issue
Block a user