From dc818757b65ca1711320b4f415e7dc74fd9eb923 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 4 Nov 2020 13:22:34 -0500 Subject: [PATCH] Port to Python 3. --- src/allmydata/storage_client.py | 23 ++++++++++++++++------- src/allmydata/util/_python3.py | 1 + 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/allmydata/storage_client.py b/src/allmydata/storage_client.py index 5834ae66f..9b7422443 100644 --- a/src/allmydata/storage_client.py +++ b/src/allmydata/storage_client.py @@ -2,7 +2,13 @@ """ I contain the client-side code which speaks to storage servers, in particular the foolscap-based server implemented in src/allmydata/storage/*.py . + +Ported to Python 3. """ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals # roadmap: # @@ -28,7 +34,10 @@ the foolscap-based server implemented in src/allmydata/storage/*.py . # # 6: implement other sorts of IStorageClient classes: S3, etc -from past.builtins import unicode +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 re, time, hashlib @@ -202,7 +211,7 @@ class StorageFarmBroker(service.MultiService): # information. raise else: - if isinstance(server_id, unicode): + if isinstance(server_id, str): server_id = server_id.encode("utf-8") self._static_server_ids.add(server_id) self.servers[server_id] = storage_server @@ -403,7 +412,7 @@ class StorageFarmBroker(service.MultiService): # connections to only a subset of the servers, which would increase # the chances that we'll put shares in weird places (and not update # existing shares of mutable files). See #374 for more details. - for dsc in self.servers.values(): + for dsc in list(self.servers.values()): dsc.try_to_connect() def get_servers_for_psi(self, peer_selection_index): @@ -443,7 +452,7 @@ class StorageFarmBroker(service.MultiService): # Upload Results web page). If the Helper is running 1.12 or newer, # it will send pubkeys, but if it's still running 1.11, it will send # tubids. This clause maps the old tubids to our existing servers. - for s in self.servers.values(): + for s in list(self.servers.values()): if isinstance(s, NativeStorageServer): if serverid == s.get_tubid(): return s @@ -556,7 +565,7 @@ class _FoolscapStorage(object): tubid = base32.a2b(tubid_s) if "permutation-seed-base32" in ann: seed = ann["permutation-seed-base32"] - if isinstance(seed, unicode): + if isinstance(seed, str): seed = seed.encode("utf-8") ps = base32.a2b(seed) elif re.search(br'^v0-[0-9a-zA-Z]{52}$', server_id): @@ -651,7 +660,7 @@ def _storage_from_foolscap_plugin(node_config, config, announcement, get_rref): in getPlugins(IFoolscapStoragePlugin) } storage_options = announcement.get(u"storage-options", []) - for plugin_name, plugin_config in config.storage_plugins.items(): + for plugin_name, plugin_config in list(config.storage_plugins.items()): try: plugin = plugins[plugin_name] except KeyError: @@ -758,7 +767,7 @@ class NativeStorageServer(service.MultiService): # Nope pass else: - if isinstance(furl, unicode): + if isinstance(furl, str): furl = furl.encode("utf-8") # See comment above for the _storage_from_foolscap_plugin case # about passing in get_rref. diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index 9218f7407..1d0517213 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -52,6 +52,7 @@ PORTED_MODULES = [ "allmydata.introducer.interfaces", "allmydata.monitor", "allmydata.node", + "allmydata.storage_client", "allmydata.storage.common", "allmydata.storage.crawler", "allmydata.storage.expirer",