From 6ffda25d6b1cfd54a269070a360c0dc48cd28ee4 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Fri, 11 Sep 2020 15:04:52 -0400 Subject: [PATCH 1/6] News fragment. --- newsfragments/3411.minor | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 newsfragments/3411.minor diff --git a/newsfragments/3411.minor b/newsfragments/3411.minor new file mode 100644 index 000000000..e69de29bb From 4590c1d1f5b66167efbae307c59a147e0d8648a8 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 14 Sep 2020 13:56:45 -0400 Subject: [PATCH 2/6] Port to Python 3. --- src/allmydata/storage/mutable.py | 13 +++++++++++++ src/allmydata/util/_python3.py | 1 + 2 files changed, 14 insertions(+) diff --git a/src/allmydata/storage/mutable.py b/src/allmydata/storage/mutable.py index a1eddf6cc..a44a2e18d 100644 --- a/src/allmydata/storage/mutable.py +++ b/src/allmydata/storage/mutable.py @@ -1,3 +1,16 @@ +""" +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 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 + import os, stat, struct from allmydata.interfaces import BadWriteEnablerError diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index afdbea1f0..f612d35df 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -37,6 +37,7 @@ PORTED_MODULES = [ "allmydata.monitor", "allmydata.storage.crawler", "allmydata.storage.expirer", + "allmydata.storage.mutable", "allmydata.test.common_py3", "allmydata.uri", "allmydata.util._python3", From 6983c79b26ecc83cc47821575927c7159b025630 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 14 Sep 2020 14:03:02 -0400 Subject: [PATCH 3/6] Tests for allmydata.storage.common. --- src/allmydata/test/test_storage.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 4bbbcda30..de2b04dd7 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -32,7 +32,8 @@ from allmydata.storage.server import StorageServer from allmydata.storage.mutable import MutableShareFile from allmydata.storage.immutable import BucketWriter, BucketReader from allmydata.storage.common import DataTooLargeError, storage_index_to_dir, \ - UnknownMutableContainerVersionError, UnknownImmutableContainerVersionError + UnknownMutableContainerVersionError, UnknownImmutableContainerVersionError, \ + si_b2a, si_a2b from allmydata.storage.lease import LeaseInfo from allmydata.immutable.layout import WriteBucketProxy, WriteBucketProxy_v2, \ ReadBucketProxy @@ -52,6 +53,26 @@ from allmydata.storage_client import ( from .common_py3 import FakeCanary, LoggingServiceParent, ShouldFailMixin +class UtilTests(unittest.TestCase): + """Tests for allmydata.storage.common.""" + + def test_encoding(self): + """b2a/a2b are the same as base32.""" + s = b"\xFF HELLO \xF3" + result = si_b2a(s) + self.assertEqual(base32.b2a(s), result) + self.assertEqual(si_a2b(result), s) + + def test_storage_index_to_dir(self): + """storage_index_to_dir creates a native string path.""" + s = b"\xFF HELLO \xF3" + path = storage_index_to_dir(s) + parts = os.path.split(path) + self.assertEqual(parts[0], parts[1][:2]) + self.assertIsInstance(path, native_str) + + + class FakeStatsProvider(object): def count(self, name, delta=1): pass From aef293fbca51e55f7dd53d4c6ba28daa46273248 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 14 Sep 2020 14:03:48 -0400 Subject: [PATCH 4/6] Port to Python 3. --- src/allmydata/storage/common.py | 12 +++++++++++- src/allmydata/util/_python3.py | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/allmydata/storage/common.py b/src/allmydata/storage/common.py index 55036eea7..cb6116e5b 100644 --- a/src/allmydata/storage/common.py +++ b/src/allmydata/storage/common.py @@ -1,4 +1,14 @@ -from future.utils import PY3 +""" +Ported to Python 3. +""" +from __future__ import unicode_literals +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +from future.utils import PY2, PY3 +if PY2: + 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 import os.path from allmydata.util import base32 diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index f612d35df..51cf8018e 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -35,6 +35,7 @@ PORTED_MODULES = [ "allmydata.immutable.happiness_upload", "allmydata.interfaces", "allmydata.monitor", + "allmydata.storage.common", "allmydata.storage.crawler", "allmydata.storage.expirer", "allmydata.storage.mutable", From 6196a1c6505ec409c6447a1df526a54cfe278a03 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 14 Sep 2020 14:06:27 -0400 Subject: [PATCH 5/6] Port to Python 3. --- src/allmydata/storage/lease.py | 13 +++++++++++++ src/allmydata/util/_python3.py | 1 + 2 files changed, 14 insertions(+) diff --git a/src/allmydata/storage/lease.py b/src/allmydata/storage/lease.py index 4d2dce8c4..187f32406 100644 --- a/src/allmydata/storage/lease.py +++ b/src/allmydata/storage/lease.py @@ -1,3 +1,16 @@ +""" +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 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 + import struct, time class LeaseInfo(object): diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index 51cf8018e..10cc69431 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -38,6 +38,7 @@ PORTED_MODULES = [ "allmydata.storage.common", "allmydata.storage.crawler", "allmydata.storage.expirer", + "allmydata.storage.lease", "allmydata.storage.mutable", "allmydata.test.common_py3", "allmydata.uri", From 1d508c74e885ecae62f279008b59c1f84b82e064 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 14 Sep 2020 14:13:07 -0400 Subject: [PATCH 6/6] Port to Python 3. --- src/allmydata/storage/shares.py | 13 ++++++++++++- src/allmydata/test/test_storage.py | 21 +++++++++++++++++++-- src/allmydata/util/_python3.py | 1 + 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/allmydata/storage/shares.py b/src/allmydata/storage/shares.py index bd94c0f3f..ec6c0a501 100644 --- a/src/allmydata/storage/shares.py +++ b/src/allmydata/storage/shares.py @@ -1,4 +1,15 @@ -#! /usr/bin/python +""" +Ported to Python 3. +""" + +from __future__ import unicode_literals +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +from future.utils import PY2 +if PY2: + 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 from allmydata.storage.mutable import MutableShareFile from allmydata.storage.immutable import ShareFile diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index de2b04dd7..8956fbf52 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -29,8 +29,9 @@ import itertools from allmydata import interfaces from allmydata.util import fileutil, hashutil, base32 from allmydata.storage.server import StorageServer +from allmydata.storage.shares import get_share_file from allmydata.storage.mutable import MutableShareFile -from allmydata.storage.immutable import BucketWriter, BucketReader +from allmydata.storage.immutable import BucketWriter, BucketReader, ShareFile from allmydata.storage.common import DataTooLargeError, storage_index_to_dir, \ UnknownMutableContainerVersionError, UnknownImmutableContainerVersionError, \ si_b2a, si_a2b @@ -54,7 +55,7 @@ from .common_py3 import FakeCanary, LoggingServiceParent, ShouldFailMixin class UtilTests(unittest.TestCase): - """Tests for allmydata.storage.common.""" + """Tests for allmydata.storage.common and .shares.""" def test_encoding(self): """b2a/a2b are the same as base32.""" @@ -71,6 +72,22 @@ class UtilTests(unittest.TestCase): self.assertEqual(parts[0], parts[1][:2]) self.assertIsInstance(path, native_str) + def test_get_share_file_mutable(self): + """A mutable share is identified by get_share_file().""" + path = self.mktemp() + msf = MutableShareFile(path) + msf.create(b"12", b"abc") # arbitrary values + loaded = get_share_file(path) + self.assertIsInstance(loaded, MutableShareFile) + self.assertEqual(loaded.home, path) + + def test_get_share_file_immutable(self): + """An immutable share is identified by get_share_file().""" + path = self.mktemp() + _ = ShareFile(path, max_size=1000, create=True) + loaded = get_share_file(path) + self.assertIsInstance(loaded, ShareFile) + self.assertEqual(loaded.home, path) class FakeStatsProvider(object): diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index 10cc69431..2b10854a9 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -40,6 +40,7 @@ PORTED_MODULES = [ "allmydata.storage.expirer", "allmydata.storage.lease", "allmydata.storage.mutable", + "allmydata.storage.shares", "allmydata.test.common_py3", "allmydata.uri", "allmydata.util._python3",