Changeset 5e6201ae in trunk


Ignore:
Timestamp:
2020-09-28T15:35:15Z (5 years ago)
Author:
GitHub <noreply@…>
Branches:
master
Children:
587d9ef, cc7a3bc
Parents:
4e7e847 (diff), d7b5230f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Itamar Turner-Trauring <itamar@…> (2020-09-28 15:35:15)
git-committer:
GitHub <noreply@…> (2020-09-28 15:35:15)
Message:

Merge pull request #833 from tahoe-lafs/3446.test-helper-python-3

Port test_helper.py to Python 3

Fixes ticket:3446

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/immutable/offloaded.py

    r4e7e847 r5e6201ae  
    204204        assert interfaces.IUploadResults.providedBy(ur), ur
    205205        vcapstr = ur.get_verifycapstr()
    206         precondition(isinstance(vcapstr, str), vcapstr)
     206        precondition(isinstance(vcapstr, bytes), vcapstr)
    207207        v = uri.from_string(vcapstr)
    208208        f_times = self._fetcher.get_times()
     
    493493
    494494    name = "helper"
    495     VERSION = { "http://allmydata.org/tahoe/protocols/helper/v1" :
     495    VERSION = { b"http://allmydata.org/tahoe/protocols/helper/v1" :
    496496                 { },
    497                 "application-version": str(allmydata.__full_version__),
     497                b"application-version": allmydata.__full_version__.encode("utf-8"),
    498498                }
    499499    MAX_UPLOAD_STATUSES = 10
  • TabularUnified src/allmydata/immutable/upload.py

    r4e7e847 r5e6201ae  
    18171817    def _got_helper(self, helper):
    18181818        self.log("got helper connection, getting versions")
    1819         default = { "http://allmydata.org/tahoe/protocols/helper/v1" :
     1819        default = { b"http://allmydata.org/tahoe/protocols/helper/v1" :
    18201820                    { },
    1821                     "application-version": b"unknown: no get_version()",
     1821                    b"application-version": b"unknown: no get_version()",
    18221822                    }
    18231823        d = add_version_to_remote_reference(helper, default)
     
    18251825
    18261826    def _got_versioned_helper(self, helper):
    1827         needed = "http://allmydata.org/tahoe/protocols/helper/v1"
     1827        needed = b"http://allmydata.org/tahoe/protocols/helper/v1"
    18281828        if needed not in helper.version:
    18291829            raise InsufficientVersionError(needed, helper.version)
  • TabularUnified src/allmydata/interfaces.py

    r4e7e847 r5e6201ae  
    33
    44Ported to Python 3.
     5
     6Note that for RemoteInterfaces, the __remote_name__ needs to be a native string because of https://github.com/warner/foolscap/blob/43f4485a42c9c28e2c79d655b3a9e24d4e6360ca/src/foolscap/remoteinterface.py#L67
    57"""
    68from __future__ import absolute_import
     
    911from __future__ import unicode_literals
    1012
    11 from future.utils import PY2
     13from future.utils import PY2, native_str
    1214if PY2:
    1315    # Don't import object/str/dict/etc. types, so we don't break any
     
    106108
    107109class RIStorageServer(RemoteInterface):
    108     __remote_name__ = b"RIStorageServer.tahoe.allmydata.com"
     110    __remote_name__ = native_str("RIStorageServer.tahoe.allmydata.com")
    109111
    110112    def get_version():
     
    28372839    # debug stuff
    28382840
    2839     def upload_random_data_from_file(size=int, convergence=str):
     2841    def upload_random_data_from_file(size=int, convergence=bytes):
    28402842        return str
    28412843
    2842     def download_to_tempfile_and_delete(uri=str):
     2844    def download_to_tempfile_and_delete(uri=bytes):
    28432845        return None
    28442846
     
    28472849        keys are 'VmPeak', 'VmSize', and 'VmData'. The values are integers,
    28482850        measuring memory consupmtion in bytes."""
    2849         return DictOf(str, int)
     2851        return DictOf(bytes, int)
    28502852
    28512853    def speed_test(count=int, size=int, mutable=Any()):
     
    28722874
    28732875
    2874 UploadResults = Any() #DictOf(str, str)
     2876UploadResults = Any() #DictOf(bytes, bytes)
    28752877
    28762878
    28772879class RIEncryptedUploadable(RemoteInterface):
    2878     __remote_name__ = b"RIEncryptedUploadable.tahoe.allmydata.com"
     2880    __remote_name__ = native_str("RIEncryptedUploadable.tahoe.allmydata.com")
    28792881
    28802882    def get_size():
     
    28852887
    28862888    def read_encrypted(offset=Offset, length=ReadSize):
    2887         return ListOf(str)
     2889        return ListOf(bytes)
    28882890
    28892891    def close():
     
    28922894
    28932895class RICHKUploadHelper(RemoteInterface):
    2894     __remote_name__ = b"RIUploadHelper.tahoe.allmydata.com"
     2896    __remote_name__ = native_str("RIUploadHelper.tahoe.allmydata.com")
    28952897
    28962898    def get_version():
     
    28982900        Return a dictionary of version information.
    28992901        """
    2900         return DictOf(str, Any())
     2902        return DictOf(bytes, Any())
    29012903
    29022904    def upload(reader=RIEncryptedUploadable):
     
    29052907
    29062908class RIHelper(RemoteInterface):
    2907     __remote_name__ = b"RIHelper.tahoe.allmydata.com"
     2909    __remote_name__ = native_str("RIHelper.tahoe.allmydata.com")
    29082910
    29092911    def get_version():
     
    29112913        Return a dictionary of version information.
    29122914        """
    2913         return DictOf(str, Any())
     2915        return DictOf(bytes, Any())
    29142916
    29152917    def upload_chk(si=StorageIndex):
     
    29322934
    29332935class RIStatsProvider(RemoteInterface):
    2934     __remote_name__ = b"RIStatsProvider.tahoe.allmydata.com"
     2936    __remote_name__ = native_str("RIStatsProvider.tahoe.allmydata.com")
    29352937    """
    29362938    Provides access to statistics and monitoring information.
     
    29452947        internally)
    29462948        """
    2947         return DictOf(str, DictOf(str, ChoiceOf(float, int, long, None)))
     2949        return DictOf(bytes, DictOf(bytes, ChoiceOf(float, int, long, None)))
    29482950
    29492951
    29502952class RIStatsGatherer(RemoteInterface):
    2951     __remote_name__ = b"RIStatsGatherer.tahoe.allmydata.com"
     2953    __remote_name__ = native_str("RIStatsGatherer.tahoe.allmydata.com")
    29522954    """
    29532955    Provides a monitoring service for centralised collection of stats
    29542956    """
    29552957
    2956     def provide(provider=RIStatsProvider, nickname=str):
     2958    def provide(provider=RIStatsProvider, nickname=bytes):
    29572959        """
    29582960        @param provider: a stats collector instance that should be polled
     
    29662968    def get_stats():
    29672969        """
    2968         returns a dictionary, with str keys representing the names of stats
     2970        returns a dictionary, with bytes keys representing the names of stats
    29692971        to be monitored, and numeric values.
    29702972        """
  • TabularUnified src/allmydata/test/test_helper.py

    r4e7e847 r5e6201ae  
     1from __future__ import absolute_import
     2from __future__ import division
     3from __future__ import print_function
     4from __future__ import unicode_literals
     5
     6from future.utils import PY2
     7if PY2:
     8    from future.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
     9
    110import os
    211from twisted.internet import defer
     
    1928MiB = 1024*1024
    2029
    21 DATA = "I need help\n" * 1000
     30DATA = b"I need help\n" * 1000
    2231
    2332class CHKUploadHelper_fake(offloaded.CHKUploadHelper):
     
    3443                            "size": size,
    3544                            }
    36                 ueb_hash = "fake"
    37                 v = uri.CHKFileVerifierURI(self._storage_index, "x"*32,
     45                ueb_hash = b"fake"
     46                v = uri.CHKFileVerifierURI(self._storage_index, b"x"*32,
    3847                                           needed_shares, total_shares, size)
    3948                _UR = upload.UploadResults
     
    5766class Helper_fake_upload(offloaded.Helper):
    5867    def _make_chk_upload_helper(self, storage_index, lp):
    59         si_s = si_b2a(storage_index)
     68        si_s = str(si_b2a(storage_index), "utf-8")
    6069        incoming_file = os.path.join(self._chk_incoming, si_s)
    6170        encoding_file = os.path.join(self._chk_encoding, si_s)
     
    7079    def _check_chk(self, storage_index, lp):
    7180        res = upload.HelperUploadResults()
    72         res.uri_extension_hash = hashutil.uri_extension_hash("")
     81        res.uri_extension_hash = hashutil.uri_extension_hash(b"")
    7382
    7483        # we're pretending that the file they're trying to upload was already
     
    128137            EMPTY_CLIENT_CONFIG,
    129138        )
    130         self.s.secret_holder = client.SecretHolder("lease secret", "converge")
     139        self.s.secret_holder = client.SecretHolder(b"lease secret", b"converge")
    131140        self.s.startService()
    132141
     
    135144        # we never actually use this for network traffic, so it can use a
    136145        # bogus host/port
    137         t.setLocation("bogus:1234")
     146        t.setLocation(b"bogus:1234")
    138147
    139148    def setUpHelper(self, basedir, helper_class=Helper_fake_upload):
     
    163172            assert u._helper
    164173
    165             return upload_data(u, DATA, convergence="some convergence string")
     174            return upload_data(u, DATA, convergence=b"some convergence string")
    166175        d.addCallback(_ready)
    167176        def _uploaded(results):
    168177            the_uri = results.get_uri()
    169             assert "CHK" in the_uri
     178            assert b"CHK" in the_uri
    170179        d.addCallback(_uploaded)
    171180
     
    196205        segsize = mathutil.next_multiple(segsize, k)
    197206
    198         key = hashutil.convergence_hash(k, n, segsize, DATA, "test convergence string")
     207        key = hashutil.convergence_hash(k, n, segsize, DATA, b"test convergence string")
    199208        assert len(key) == 16
    200209        encryptor = aes.create_encryptor(key)
    201210        SI = hashutil.storage_index_hash(key)
    202         SI_s = si_b2a(SI)
     211        SI_s = str(si_b2a(SI), "utf-8")
    203212        encfile = os.path.join(self.basedir, "CHK_encoding", SI_s)
    204213        f = open(encfile, "wb")
     
    213222        def _ready(res):
    214223            assert u._helper
    215             return upload_data(u, DATA, convergence="test convergence string")
     224            return upload_data(u, DATA, convergence=b"test convergence string")
    216225        d.addCallback(_ready)
    217226        def _uploaded(results):
    218227            the_uri = results.get_uri()
    219             assert "CHK" in the_uri
     228            assert b"CHK" in the_uri
    220229        d.addCallback(_uploaded)
    221230
     
    240249            assert u._helper
    241250
    242             return upload_data(u, DATA, convergence="some convergence string")
     251            return upload_data(u, DATA, convergence=b"some convergence string")
    243252        d.addCallback(_ready)
    244253        def _uploaded(results):
    245254            the_uri = results.get_uri()
    246             assert "CHK" in the_uri
     255            assert b"CHK" in the_uri
    247256        d.addCallback(_uploaded)
    248257
  • TabularUnified src/allmydata/util/_python3.py

    r4e7e847 r5e6201ae  
    9494    "allmydata.test.test_hashtree",
    9595    "allmydata.test.test_hashutil",
     96    "allmydata.test.test_helper",
    9697    "allmydata.test.test_humanreadable",
    9798    "allmydata.test.test_immutable",
Note: See TracChangeset for help on using the changeset viewer.