Port to Python 3.

This commit is contained in:
Itamar Turner-Trauring 2020-10-29 14:09:18 -04:00
parent dce368016b
commit 468beb05f6
3 changed files with 20 additions and 13 deletions

View File

@ -2,7 +2,14 @@
This module contains classes and functions to implement and manage
a node for Tahoe-LAFS.
"""
from past.builtins import unicode
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 six import ensure_str
import datetime
@ -71,7 +78,7 @@ def _common_valid_config():
# Add our application versions to the data that Foolscap's LogPublisher
# reports.
for thing, things_version in get_package_versions().items():
for thing, things_version in list(get_package_versions().items()):
app_versions.add_version(thing, things_version)
# group 1 will be addr (dotted quad string), group 3 if any will be portnum (string)
@ -172,7 +179,7 @@ def read_config(basedir, portnumfile, generated_files=[], _valid_config=None):
:returns: :class:`allmydata.node._Config` instance
"""
basedir = abspath_expanduser_unicode(unicode(basedir))
basedir = abspath_expanduser_unicode(ensure_str(basedir))
if _valid_config is None:
_valid_config = _common_valid_config()
@ -274,11 +281,11 @@ class _Config(object):
configparser (might be 'fake' if using in-memory data)
"""
self.portnum_fname = portnum_fname
self._basedir = abspath_expanduser_unicode(unicode(basedir))
self._basedir = abspath_expanduser_unicode(ensure_str(basedir))
self._config_fname = config_fname
self.config = configparser
self.nickname = self.get_config("node", "nickname", u"<unspecified>")
assert isinstance(self.nickname, unicode)
assert isinstance(self.nickname, str)
def validate(self, valid_config_sections):
configutil.validate_config(self._config_fname, self.config, valid_config_sections)
@ -363,8 +370,8 @@ class _Config(object):
raise MissingConfigEntry("The required configuration file %s is missing."
% (quote_output(privname),))
if isinstance(default, bytes):
default = unicode(default, "utf-8")
if isinstance(default, unicode):
default = str(default, "utf-8")
if isinstance(default, str):
value = default
else:
value = default()
@ -376,7 +383,7 @@ class _Config(object):
config file that resides within the subdirectory named 'private'), and
return it.
"""
if isinstance(value, unicode):
if isinstance(value, str):
value = value.encode("utf-8")
privname = os.path.join(self._basedir, "private", name)
with open(privname, "wb") as f:
@ -423,7 +430,7 @@ class _Config(object):
characters = iter(item)
for c in characters:
if c == '\\':
characters.next()
next(characters)
elif c == '#':
return True
@ -531,12 +538,12 @@ def create_tub(tub_options, default_connection_handlers, foolscap_connection_han
the new Tub via `Tub.setOption`
"""
tub = Tub(**kwargs)
for (name, value) in tub_options.items():
for (name, value) in list(tub_options.items()):
tub.setOption(name, value)
handlers = default_connection_handlers.copy()
handlers.update(handler_overrides)
tub.removeAllConnectionHintHandlers()
for hint_type, handler_name in handlers.items():
for hint_type, handler_name in list(handlers.items()):
handler = foolscap_connection_handlers.get(handler_name)
if handler:
tub.addConnectionHintHandler(hint_type, handler)
@ -693,7 +700,7 @@ def create_main_tub(config, tub_options,
else:
port_or_endpoint = port
# Foolscap requires native strings:
if isinstance(port_or_endpoint, (bytes, unicode)):
if isinstance(port_or_endpoint, (bytes, str)):
port_or_endpoint = ensure_str(port_or_endpoint)
tub.listenOn(port_or_endpoint)
tub.setLocation(location)

View File

@ -40,7 +40,6 @@ from allmydata.node import (
_tub_portlocation,
formatTimeTahoeStyle,
UnescapedHashError,
PrivacyError,
)
from allmydata.introducer.server import create_introducer
from allmydata import client

View File

@ -51,6 +51,7 @@ PORTED_MODULES = [
"allmydata.interfaces",
"allmydata.introducer.interfaces",
"allmydata.monitor",
"allmydata.node",
"allmydata.storage.common",
"allmydata.storage.crawler",
"allmydata.storage.expirer",