From f34597ac61726d167aa22187e073464127e6195c Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 4 Nov 2020 13:09:55 -0500 Subject: [PATCH] All tests pass on Python 3. --- src/allmydata/storage_client.py | 28 ++++++++++++++-------------- src/allmydata/util/dictutil.py | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/allmydata/storage_client.py b/src/allmydata/storage_client.py index 58aa749de..5834ae66f 100644 --- a/src/allmydata/storage_client.py +++ b/src/allmydata/storage_client.py @@ -65,7 +65,7 @@ from allmydata.util.assertutil import precondition from allmydata.util.observer import ObserverList from allmydata.util.rrefutil import add_version_to_remote_reference from allmydata.util.hashutil import permute_server_hash -from allmydata.util.dictutil import BytesKeyDict +from allmydata.util.dictutil import BytesKeyDict, UnicodeKeyDict # who is responsible for de-duplication? @@ -684,16 +684,16 @@ class NativeStorageServer(service.MultiService): @ivar remote_host: the IAddress, if connected, otherwise None """ - VERSION_DEFAULTS = { - b"http://allmydata.org/tahoe/protocols/storage/v1" : - { b"maximum-immutable-share-size": 2**32 - 1, - b"maximum-mutable-share-size": 2*1000*1000*1000, # maximum prior to v1.9.2 - b"tolerates-immutable-read-overrun": False, - b"delete-mutable-shares-with-zero-length-writev": False, - b"available-space": None, - }, - b"application-version": "unknown: no get_version()", - } + VERSION_DEFAULTS = UnicodeKeyDict({ + "http://allmydata.org/tahoe/protocols/storage/v1" : + UnicodeKeyDict({ "maximum-immutable-share-size": 2**32 - 1, + "maximum-mutable-share-size": 2*1000*1000*1000, # maximum prior to v1.9.2 + "tolerates-immutable-read-overrun": False, + "delete-mutable-shares-with-zero-length-writev": False, + "available-space": None, + }), + "application-version": "unknown: no get_version()", + }) def __init__(self, server_id, ann, tub_maker, handler_overrides, node_config, config=StorageClientConfig()): service.MultiService.__init__(self) @@ -833,10 +833,10 @@ class NativeStorageServer(service.MultiService): version = self.get_version() if version is None: return None - protocol_v1_version = version.get(b'http://allmydata.org/tahoe/protocols/storage/v1', {}) - available_space = protocol_v1_version.get('available-space') + protocol_v1_version = version.get('http://allmydata.org/tahoe/protocols/storage/v1', UnicodeKeyDict()) + available_space = protocol_v1_version.get(u'available-space') if available_space is None: - available_space = protocol_v1_version.get('maximum-immutable-share-size', None) + available_space = protocol_v1_version.get(u'maximum-immutable-share-size', None) return available_space def start_connecting(self, trigger_cb): diff --git a/src/allmydata/util/dictutil.py b/src/allmydata/util/dictutil.py index 5fc85fbd1..ed66a0e52 100644 --- a/src/allmydata/util/dictutil.py +++ b/src/allmydata/util/dictutil.py @@ -104,7 +104,18 @@ for _method_name in ["__setitem__", "__getitem__", "setdefault", "get", del _method_name -class BytesKeyDict(_TypedKeyDict): - """Keys should be bytes.""" +if PY2: + # No need for enforcement, can use either bytes or unicode as keys and it's + # fine. + BytesKeyDict = UnicodeKeyDict = dict +else: + class BytesKeyDict(_TypedKeyDict): + """Keys should be bytes.""" - KEY_TYPE = bytes + KEY_TYPE = bytes + + + class UnicodeKeyDict(_TypedKeyDict): + """Keys should be unicode strings.""" + + KEY_TYPE = str