mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 13:07:56 +00:00
Merge pull request #810 from tahoe-lafs/3411.storage-mutable-python-3
Port a variety of allmydata.storage modules to Python 3 Fixes ticket:3411
This commit is contained in:
commit
73967aa5b0
0
newsfragments/3411.minor
Normal file
0
newsfragments/3411.minor
Normal file
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -29,10 +29,12 @@ 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
|
||||
UnknownMutableContainerVersionError, UnknownImmutableContainerVersionError, \
|
||||
si_b2a, si_a2b
|
||||
from allmydata.storage.lease import LeaseInfo
|
||||
from allmydata.immutable.layout import WriteBucketProxy, WriteBucketProxy_v2, \
|
||||
ReadBucketProxy
|
||||
@ -52,6 +54,42 @@ from allmydata.storage_client import (
|
||||
from .common_py3 import FakeCanary, LoggingServiceParent, ShouldFailMixin
|
||||
|
||||
|
||||
class UtilTests(unittest.TestCase):
|
||||
"""Tests for allmydata.storage.common and .shares."""
|
||||
|
||||
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)
|
||||
|
||||
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):
|
||||
def count(self, name, delta=1):
|
||||
pass
|
||||
|
@ -35,8 +35,12 @@ PORTED_MODULES = [
|
||||
"allmydata.immutable.happiness_upload",
|
||||
"allmydata.interfaces",
|
||||
"allmydata.monitor",
|
||||
"allmydata.storage.common",
|
||||
"allmydata.storage.crawler",
|
||||
"allmydata.storage.expirer",
|
||||
"allmydata.storage.lease",
|
||||
"allmydata.storage.mutable",
|
||||
"allmydata.storage.shares",
|
||||
"allmydata.test.common_py3",
|
||||
"allmydata.uri",
|
||||
"allmydata.util._python3",
|
||||
|
Loading…
Reference in New Issue
Block a user