Merge pull request #994 from tahoe-lafs/3624.web-python-3-part-5

Finish porting allmydata.web to Python 3

Fixes ticket:3624
This commit is contained in:
Itamar Turner-Trauring 2021-03-05 10:18:55 -05:00 committed by GitHub
commit a4a8a22f8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 71 additions and 28 deletions

0
newsfragments/3624.minor Normal file
View File

View File

@ -236,11 +236,11 @@ class StorageFarmBroker(service.MultiService):
for plugin for plugin
in getPlugins(IFoolscapStoragePlugin) in getPlugins(IFoolscapStoragePlugin)
} }
return { return UnicodeKeyDict({
name: plugins[name].get_client_resource(node_config) name: plugins[name].get_client_resource(node_config)
for (name, config) for (name, config)
in self.storage_client_config.storage_plugins.items() in self.storage_client_config.storage_plugins.items()
} })
@log_call( @log_call(
action_type=u"storage-client:broker:make-storage-server", action_type=u"storage-client:broker:make-storage-server",

View File

@ -128,6 +128,10 @@ PORTED_MODULES = [
"allmydata.web.operations", "allmydata.web.operations",
"allmydata.web.private", "allmydata.web.private",
"allmydata.web.root", "allmydata.web.root",
"allmydata.web.status",
"allmydata.web.storage",
"allmydata.web.storage_plugins",
"allmydata.web.unlinked",
"allmydata.webish", "allmydata.webish",
] ]

View File

@ -1,4 +1,16 @@
from past.builtins import long, unicode """
Ported to Python 3.
"""
from __future__ import division
from __future__ import absolute_import
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
from past.builtins import long
import itertools import itertools
import hashlib import hashlib
@ -60,7 +72,7 @@ class UploadResultsRendererMixin(Element):
return "None" return "None"
ul = tags.ul() ul = tags.ul()
for shnum, servers in sorted(sharemap.items()): for shnum, servers in sorted(sharemap.items()):
server_names = ', '.join([unicode(s.get_name(), "utf-8") for s in servers]) server_names = ', '.join([str(s.get_name(), "utf-8") for s in servers])
ul(tags.li("%d -> placed on [%s]" % (shnum, server_names))) ul(tags.li("%d -> placed on [%s]" % (shnum, server_names)))
return ul return ul
d.addCallback(_render) d.addCallback(_render)
@ -76,7 +88,7 @@ class UploadResultsRendererMixin(Element):
ul = tags.ul() ul = tags.ul()
for server, shnums in sorted(servermap.items(), key=id): for server, shnums in sorted(servermap.items(), key=id):
shares_s = ",".join(["#%d" % shnum for shnum in shnums]) shares_s = ",".join(["#%d" % shnum for shnum in shnums])
ul(tags.li("[%s] got share%s: %s" % (unicode(server.get_name(), "utf-8"), ul(tags.li("[%s] got share%s: %s" % (str(server.get_name(), "utf-8"),
plural(shnums), shares_s))) plural(shnums), shares_s)))
return ul return ul
d.addCallback(_render) d.addCallback(_render)
@ -231,7 +243,7 @@ class UploadStatusElement(UploadResultsRendererMixin):
if si_s is None: if si_s is None:
si_s = "(None)" si_s = "(None)"
else: else:
si_s = unicode(si_s, "utf-8") si_s = str(si_s, "utf-8")
return tag(si_s) return tag(si_s)
@renderer @renderer
@ -467,10 +479,10 @@ class DownloadStatusElement(Element):
return "" return ""
return "+%.6fs" % t return "+%.6fs" % t
def _rate_and_time(self, bytes, seconds): def _rate_and_time(self, bytes_count, seconds):
time_s = abbreviate_time(seconds) time_s = abbreviate_time(seconds)
if seconds != 0: if seconds != 0:
rate = abbreviate_rate(1.0 * bytes / seconds) rate = abbreviate_rate(bytes_count / seconds)
return tags.span(time_s, title=rate) return tags.span(time_s, title=rate)
return tags.span(time_s) return tags.span(time_s)
@ -535,14 +547,14 @@ class DownloadStatusElement(Element):
for r_ev in self._download_status.read_events: for r_ev in self._download_status.read_events:
start = r_ev["start"] start = r_ev["start"]
length = r_ev["length"] length = r_ev["length"]
bytes = r_ev["bytes_returned"] bytes_returned = r_ev["bytes_returned"]
decrypt_time = "" decrypt_time = ""
if bytes: if bytes:
decrypt_time = self._rate_and_time(bytes, r_ev["decrypt_time"]) decrypt_time = self._rate_and_time(bytes_returned, r_ev["decrypt_time"])
speed, rtt = "","" speed, rtt = "",""
if r_ev["finish_time"] is not None: if r_ev["finish_time"] is not None:
rtt = r_ev["finish_time"] - r_ev["start_time"] - r_ev["paused_time"] rtt = r_ev["finish_time"] - r_ev["start_time"] - r_ev["paused_time"]
speed = abbreviate_rate(compute_rate(bytes, rtt)) speed = abbreviate_rate(compute_rate(bytes_returned, rtt))
rtt = abbreviate_time(rtt) rtt = abbreviate_time(rtt)
paused = abbreviate_time(r_ev["paused_time"]) paused = abbreviate_time(r_ev["paused_time"])
@ -550,7 +562,7 @@ class DownloadStatusElement(Element):
tags.td("[%d:+%d]" % (start, length)), tags.td("[%d:+%d]" % (start, length)),
tags.td(srt(r_ev["start_time"])), tags.td(srt(r_ev["start_time"])),
tags.td(srt(r_ev["finish_time"])), tags.td(srt(r_ev["finish_time"])),
tags.td(str(bytes)), tags.td(str(bytes_returned)),
tags.td(rtt), tags.td(rtt),
tags.td(decrypt_time), tags.td(decrypt_time),
tags.td(paused), tags.td(paused),
@ -919,10 +931,10 @@ class RetrieveStatusElement(Element):
if not per_server: if not per_server:
return tag("") return tag("")
l = tags.ul() l = tags.ul()
for server in sorted(per_server.keys(), key=lambda s: s.get_name()): for server in sorted(list(per_server.keys()), key=lambda s: s.get_name()):
times_s = ", ".join([abbreviate_time(t) times_s = ", ".join([abbreviate_time(t)
for t in per_server[server]]) for t in per_server[server]])
l(tags.li("[%s]: %s" % (unicode(server.get_name(), "utf-8"), times_s))) l(tags.li("[%s]: %s" % (str(server.get_name(), "utf-8"), times_s)))
return tags.li("Per-Server Fetch Response Times: ", l) return tags.li("Per-Server Fetch Response Times: ", l)
@ -961,7 +973,7 @@ class PublishStatusElement(Element):
if si_s is None: if si_s is None:
si_s = "(None)" si_s = "(None)"
else: else:
si_s = unicode(si_s, "utf-8") si_s = str(si_s, "utf-8")
return tag(si_s) return tag(si_s)
@renderer @renderer
@ -1000,7 +1012,7 @@ class PublishStatusElement(Element):
sharemap = servermap.make_sharemap() sharemap = servermap.make_sharemap()
for shnum in sorted(sharemap.keys()): for shnum in sorted(sharemap.keys()):
l(tags.li("%d -> Placed on " % shnum, l(tags.li("%d -> Placed on " % shnum,
", ".join(["[%s]" % unicode(server.get_name(), "utf-8") ", ".join(["[%s]" % str(server.get_name(), "utf-8")
for server in sharemap[shnum]]))) for server in sharemap[shnum]])))
return tag("Sharemap:", l) return tag("Sharemap:", l)
@ -1079,10 +1091,10 @@ class PublishStatusElement(Element):
if not per_server: if not per_server:
return tag() return tag()
l = tags.ul() l = tags.ul()
for server in sorted(per_server.keys(), key=lambda s: s.get_name()): for server in sorted(list(per_server.keys()), key=lambda s: s.get_name()):
times_s = ", ".join([abbreviate_time(t) times_s = ", ".join([abbreviate_time(t)
for t in per_server[server]]) for t in per_server[server]])
l(tags.li("[%s]: %s" % (unicode(server.get_name(), "utf-8"), times_s))) l(tags.li("[%s]: %s" % (str(server.get_name(), "utf-8"), times_s)))
return tags.li("Per-Server Response Times: ", l) return tags.li("Per-Server Response Times: ", l)
@ -1208,7 +1220,7 @@ class MapupdateStatusElement(Element):
else: else:
times.append("privkey(" + abbreviate_time(t) + ")") times.append("privkey(" + abbreviate_time(t) + ")")
times_s = ", ".join(times) times_s = ", ".join(times)
l(tags.li("[%s]: %s" % (unicode(server.get_name(), "utf-8"), times_s))) l(tags.li("[%s]: %s" % (str(server.get_name(), "utf-8"), times_s)))
return tags.li("Per-Server Response Times: ", l) return tags.li("Per-Server Response Times: ", l)
@ -1298,9 +1310,9 @@ class Status(MultiFormatResource):
try: try:
stype, count_s = path.split(b"-") stype, count_s = path.split(b"-")
except ValueError: except ValueError:
raise WebError("no '-' in '{}'".format(unicode(path, "utf-8"))) raise WebError("no '-' in '{}'".format(str(path, "utf-8")))
count = int(count_s) count = int(count_s)
stype = unicode(stype, "ascii") stype = str(stype, "ascii")
if stype == "up": if stype == "up":
for s in itertools.chain(h.list_all_upload_statuses(), for s in itertools.chain(h.list_all_upload_statuses(),
h.list_all_helper_statuses()): h.list_all_helper_statuses()):

View File

@ -1,4 +1,14 @@
"""
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 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 time import time
from twisted.python.filepath import FilePath from twisted.python.filepath import FilePath
@ -318,7 +328,4 @@ class StorageStatus(MultiFormatResource):
"lease-checker": self._storage.lease_checker.get_state(), "lease-checker": self._storage.lease_checker.get_state(),
"lease-checker-progress": self._storage.lease_checker.get_progress(), "lease-checker-progress": self._storage.lease_checker.get_progress(),
} }
result = json.dumps(d, indent=1) + "\n" return json.dumps(d, indent=1) + "\n"
if PY2:
result = result.decode("utf-8")
return result.encode("utf-8")

View File

@ -1,7 +1,17 @@
""" """
This module implements a resource which has as children the web resources This module implements a resource which has as children the web resources
of all enabled storage client plugins. of all enabled storage client plugins.
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
from twisted.web.resource import ( from twisted.web.resource import (
Resource, Resource,

View File

@ -1,4 +1,14 @@
from past.builtins import unicode """
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
from urllib.parse import quote as urlquote from urllib.parse import quote as urlquote
@ -119,8 +129,8 @@ class UploadResultsElement(status.UploadResultsRendererMixin):
def download_link(self, req, tag): def download_link(self, req, tag):
d = self.upload_results() d = self.upload_results()
d.addCallback(lambda res: d.addCallback(lambda res:
tags.a("/uri/" + unicode(res.get_uri(), "utf-8"), tags.a("/uri/" + str(res.get_uri(), "utf-8"),
href="/uri/" + urlquote(unicode(res.get_uri(), "utf-8")))) href="/uri/" + urlquote(str(res.get_uri(), "utf-8"))))
return d return d