All tests pass on Python 3.

This commit is contained in:
Itamar Turner-Trauring 2020-11-04 13:09:55 -05:00
parent d30014f8f5
commit f34597ac61
2 changed files with 28 additions and 17 deletions

View File

@ -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):

View File

@ -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