diff --git a/src/allmydata/client.py b/src/allmydata/client.py index f731c3163..845290ac0 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -2,7 +2,10 @@ import os, stat, time, weakref from base64 import urlsafe_b64encode from functools import partial from errno import ENOENT, EPERM -from ConfigParser import NoSectionError +try: + from ConfigParser import NoSectionError +except ImportError: + from configparser import NoSectionError from foolscap.furl import ( decode_furl, diff --git a/src/allmydata/immutable/upload.py b/src/allmydata/immutable/upload.py index fe77fdf69..58cbea2ef 100644 --- a/src/allmydata/immutable/upload.py +++ b/src/allmydata/immutable/upload.py @@ -1,3 +1,5 @@ +from past.builtins import long + import os, time, weakref, itertools from zope.interface import implementer from twisted.python import failure @@ -26,7 +28,7 @@ from allmydata.interfaces import IUploadable, IUploader, IUploadResults, \ from allmydata.immutable import layout from six.moves import cStringIO as StringIO -from happiness_upload import share_placement, calculate_happiness +from .happiness_upload import share_placement, calculate_happiness from ..util.eliotutil import ( log_call_deferred, diff --git a/src/allmydata/node.py b/src/allmydata/node.py index 6b3911d95..95033d36c 100644 --- a/src/allmydata/node.py +++ b/src/allmydata/node.py @@ -7,7 +7,10 @@ import os.path import re import types import errno -import ConfigParser +try: + import ConfigParser +except ImportError: + import configparser as ConfigParser import tempfile from io import BytesIO from base64 import b32decode, b32encode diff --git a/src/allmydata/storage_client.py b/src/allmydata/storage_client.py index 2f1823058..cfc3bc83f 100644 --- a/src/allmydata/storage_client.py +++ b/src/allmydata/storage_client.py @@ -30,9 +30,12 @@ the foolscap-based server implemented in src/allmydata/storage/*.py . import re, time, hashlib -from ConfigParser import ( - NoSectionError, -) +try: + from ConfigParser import ( + NoSectionError, + ) +except ImportError: + from configparser import NoSectionError import attr from zope.interface import ( Attribute, @@ -534,11 +537,11 @@ class _NullStorage(object): which we can't communicate. """ nickname = "" - permutation_seed = hashlib.sha256("").digest() - tubid = hashlib.sha256("").digest() + permutation_seed = hashlib.sha256(b"").digest() + tubid = hashlib.sha256(b"").digest() storage_server = None - lease_seed = hashlib.sha256("").digest() + lease_seed = hashlib.sha256(b"").digest() name = "" longname = "" diff --git a/src/allmydata/test/common.py b/src/allmydata/test/common.py index a2af857b9..dbd93df67 100644 --- a/src/allmydata/test/common.py +++ b/src/allmydata/test/common.py @@ -88,6 +88,8 @@ from ..crypto import ( from .eliotutil import ( EliotLoggedRunTest, ) +# Backwards compatibility imports: +from .common_py3 import LoggingServiceParent, ShouldFailMixin # noqa: F401 TEST_RSA_KEY_SIZE = 522 @@ -780,53 +782,8 @@ def create_mutable_filenode(contents, mdmf=False, all_contents=None): return filenode -class LoggingServiceParent(service.MultiService): - def log(self, *args, **kwargs): - return log.msg(*args, **kwargs) - - TEST_DATA="\x02"*(Uploader.URI_LIT_SIZE_THRESHOLD+1) -class ShouldFailMixin(object): - def shouldFail(self, expected_failure, which, substring, - callable, *args, **kwargs): - """Assert that a function call raises some exception. This is a - Deferred-friendly version of TestCase.assertRaises() . - - Suppose you want to verify the following function: - - def broken(a, b, c): - if a < 0: - raise TypeError('a must not be negative') - return defer.succeed(b+c) - - You can use: - d = self.shouldFail(TypeError, 'test name', - 'a must not be negative', - broken, -4, 5, c=12) - in your test method. The 'test name' string will be included in the - error message, if any, because Deferred chains frequently make it - difficult to tell which assertion was tripped. - - The substring= argument, if not None, must appear in the 'repr' - of the message wrapped by this Failure, or the test will fail. - """ - - assert substring is None or isinstance(substring, str) - d = defer.maybeDeferred(callable, *args, **kwargs) - def done(res): - if isinstance(res, failure.Failure): - res.trap(expected_failure) - if substring: - message = repr(res.value.args[0]) - self.failUnless(substring in message, - "%s: substring '%s' not in '%s'" - % (which, substring, message)) - else: - self.fail("%s was supposed to raise %s, not get '%s'" % - (which, expected_failure, res)) - d.addBoth(done) - return d class WebErrorMixin(object): def explain_web_error(self, f): diff --git a/src/allmydata/test/common_py3.py b/src/allmydata/test/common_py3.py index 0daf66e62..36738d559 100644 --- a/src/allmydata/test/common_py3.py +++ b/src/allmydata/test/common_py3.py @@ -19,11 +19,13 @@ import time import signal from twisted.internet import defer, reactor +from twisted.application import service from twisted.python import failure from twisted.trial import unittest from ..util.assertutil import precondition from ..util.encodingutil import unicode_platform, get_filesystem_encoding +from ..util import log class TimezoneMixin(object): @@ -135,3 +137,50 @@ class FakeCanary(object): if self.ignore: return del self.disconnectors[marker] + + +class LoggingServiceParent(service.MultiService): + def log(self, *args, **kwargs): + return log.msg(*args, **kwargs) + + +class ShouldFailMixin(object): + def shouldFail(self, expected_failure, which, substring, + callable, *args, **kwargs): + """Assert that a function call raises some exception. This is a + Deferred-friendly version of TestCase.assertRaises() . + + Suppose you want to verify the following function: + + def broken(a, b, c): + if a < 0: + raise TypeError('a must not be negative') + return defer.succeed(b+c) + + You can use: + d = self.shouldFail(TypeError, 'test name', + 'a must not be negative', + broken, -4, 5, c=12) + in your test method. The 'test name' string will be included in the + error message, if any, because Deferred chains frequently make it + difficult to tell which assertion was tripped. + + The substring= argument, if not None, must appear in the 'repr' + of the message wrapped by this Failure, or the test will fail. + """ + + assert substring is None or isinstance(substring, str) + d = defer.maybeDeferred(callable, *args, **kwargs) + def done(res): + if isinstance(res, failure.Failure): + res.trap(expected_failure) + if substring: + message = repr(res.value.args[0]) + self.failUnless(substring in message, + "%s: substring '%s' not in '%s'" + % (which, substring, message)) + else: + self.fail("%s was supposed to raise %s, not get '%s'" % + (which, expected_failure, res)) + d.addBoth(done) + return d diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 14c342c41..d04e6b83d 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -30,12 +30,11 @@ from allmydata.mutable.layout import MDMFSlotWriteProxy, MDMFSlotReadProxy, \ VERIFICATION_KEY_SIZE, \ SHARE_HASH_CHAIN_SIZE from allmydata.interfaces import BadWriteEnablerError -from allmydata.test.common import LoggingServiceParent, ShouldFailMixin from allmydata.test.no_network import NoNetworkServer from allmydata.storage_client import ( _StorageServer, ) -from .common_py3 import FakeCanary +from .common_py3 import FakeCanary, LoggingServiceParent, ShouldFailMixin class FakeStatsProvider(object):