From d84a7a61f30e181d83a00665ea32c9f498525b1a Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 14 Sep 2020 14:46:08 -0400 Subject: [PATCH] Port to Python 3. --- src/allmydata/storage/server.py | 17 ++++++++++++++--- src/allmydata/util/_python3.py | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/allmydata/storage/server.py b/src/allmydata/storage/server.py index c044a9fb0..2ba02aa9a 100644 --- a/src/allmydata/storage/server.py +++ b/src/allmydata/storage/server.py @@ -1,4 +1,15 @@ -from future.utils import bytes_to_native_str +from __future__ import division +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals + +from past.utils import old_div +from future.utils import bytes_to_native_str, PY2 +if PY2: + # Omit open() to get native behavior where open("w") always accepts native strings. + from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 + + import os, re, struct, time import weakref import six @@ -146,7 +157,7 @@ class StorageServer(service.MultiService, Referenceable): stats["samplesize"] = count samples.sort() if count > 1: - stats["mean"] = sum(samples) / count + stats["mean"] = old_div(sum(samples), count) else: stats["mean"] = None @@ -671,7 +682,7 @@ class StorageServer(service.MultiService, Referenceable): filename = os.path.join(bucketdir, sharenum_s) msf = MutableShareFile(filename, self) datavs[sharenum] = msf.readv(readv) - log.msg("returning shares %s" % (datavs.keys(),), + log.msg("returning shares %s" % (list(datavs.keys()),), facility="tahoe.storage", level=log.NOISY, parent=lp) self.add_latency("readv", time.time() - start) return datavs diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index afdbea1f0..c707356a1 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.server", "allmydata.test.common_py3", "allmydata.uri", "allmydata.util._python3",