Changeset 5384768 in trunk


Ignore:
Timestamp:
2020-08-07T17:08:53Z (5 years ago)
Author:
Itamar Turner-Trauring <itamar@…>
Branches:
master
Children:
43e36eb
Parents:
7516a55
Message:

Port to Python 3.

Location:
src/allmydata
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/codec.py

    r7516a55 r5384768  
    1 # -*- test-case-name: allmydata.test.test_encode_share -*-
     1"""
     2CRS encoding and decoding.
     3
     4Ported to Python 3.
     5"""
     6from __future__ import absolute_import
     7from __future__ import division
     8from __future__ import print_function
     9from __future__ import unicode_literals
     10
     11from future.utils import PY2
     12if PY2:
     13    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
     14from future.utils import native_str
    215
    316from zope.interface import implementer
     
    2841
    2942    def get_serialized_params(self):
    30         return "%d-%d-%d" % (self.data_size, self.required_shares,
    31                              self.max_shares)
     43        return native_str("%d-%d-%d" % (self.data_size, self.required_shares,
     44                                        self.max_shares))
    3245
    3346    def get_block_size(self):
     
    3851
    3952        if desired_share_ids is None:
    40             desired_share_ids = range(self.max_shares)
     53            desired_share_ids = list(range(self.max_shares))
    4154
    4255        for inshare in inshares:
  • TabularUnified src/allmydata/test/test_codec.py

    r7516a55 r5384768  
     1"""
     2Tests for allmydata.codec.
     3
     4Ported to Python 3.
     5"""
     6from __future__ import absolute_import
     7from __future__ import division
     8from __future__ import print_function
     9from __future__ import unicode_literals
     10
     11from future.utils import PY2
     12if PY2:
     13    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
    114
    215import os
     
    2437        if fewer_shares is not None:
    2538            # also validate that the desired_shareids= parameter works
    26             desired_shareids = random.sample(range(max_shares), fewer_shares)
     39            desired_shareids = random.sample(list(range(max_shares)), fewer_shares)
    2740            d.addCallback(lambda res: enc.encode(data0s, desired_shareids))
    2841            def _check_fewer_shares(some_shares_and_their_shareids):
     
    3952
    4053        def _check_data(decoded_shares):
    41             self.failUnlessEqual(len(''.join(decoded_shares)), len(''.join(data0s)))
     54            self.failUnlessEqual(len(b''.join(decoded_shares)), len(b''.join(data0s)))
    4255            self.failUnlessEqual(len(decoded_shares), len(data0s))
    4356            for (i, (x, y)) in enumerate(zip(data0s, decoded_shares)):
    4457                self.failUnlessEqual(x, y, "%s: %r != %r....  first share was %r" % (str(i), x, y, data0s[0],))
    45             self.failUnless(''.join(decoded_shares) == ''.join(data0s), "%s" % ("???",))
     58            self.failUnless(b''.join(decoded_shares) == b''.join(data0s), "%s" % ("???",))
    4659            # 0data0sclipped = tuple(data0s)
    4760            # data0sclipped[-1] =
     
    6073            log.msg("_decode_some_random")
    6174            # use a randomly-selected minimal subset
    62             l = random.sample(zip(self.shares, self.shareids), required_shares)
     75            l = random.sample(list(zip(self.shares, self.shareids)), required_shares)
    6376            some_shares = [ x[0] for x in l ]
    6477            some_shareids = [ x[1] for x in l ]
     
    7184            # make sure we can re-use the decoder object
    7285            shares1 = random.sample(self.shares, required_shares)
    73             sharesl1 = random.sample(zip(self.shares, self.shareids), required_shares)
     86            sharesl1 = random.sample(list(zip(self.shares, self.shareids)), required_shares)
    7487            shares1 = [ x[0] for x in sharesl1 ]
    7588            shareids1 = [ x[1] for x in sharesl1 ]
    76             sharesl2 = random.sample(zip(self.shares, self.shareids), required_shares)
     89            sharesl2 = random.sample(list(zip(self.shares, self.shareids)), required_shares)
    7790            shares2 = [ x[0] for x in sharesl2 ]
    7891            shareids2 = [ x[1] for x in sharesl2 ]
  • TabularUnified src/allmydata/util/_python3.py

    r7516a55 r5384768  
    1616# Keep these sorted alphabetically, to reduce merge conflicts:
    1717PORTED_MODULES = [
     18    "allmydata.codec",
    1819    "allmydata.crypto",
    1920    "allmydata.crypto.aes",
     
    5253    "allmydata.test.test_base32",
    5354    "allmydata.test.test_base62",
     55    "allmydata.test.test_codec",
    5456    "allmydata.test.test_crypto",
    5557    "allmydata.test.test_deferredutil",
Note: See TracChangeset for help on using the changeset viewer.