Skip to content

Commit

Permalink
Merge pull request #1361 from a-detiste/remove-future
Browse files Browse the repository at this point in the history
Remove most of the usage of future

Fixes ticket:4093
  • Loading branch information
itamarst committed Mar 1, 2024
2 parents dcf8570 + 0985468 commit 432e041
Show file tree
Hide file tree
Showing 58 changed files with 148 additions and 687 deletions.
2 changes: 1 addition & 1 deletion misc/coding_tools/graph-deps.py
Expand Up @@ -24,7 +24,7 @@
import os, sys, subprocess, json, tempfile, zipfile, re, itertools
import email.parser
from pprint import pprint
from six.moves import StringIO
from io import StringIO
import click

all_packages = {} # name -> version
Expand Down
Empty file added newsfragments/4093.minor
Empty file.
8 changes: 0 additions & 8 deletions src/allmydata/_monkeypatch.py
Expand Up @@ -4,13 +4,5 @@
Ported to Python 3.
"""

from future.utils import PY2



def patch():
"""Path third-party libraries to make Tahoe-LAFS work."""

if not PY2:
# Python 3 doesn't need to monkey patch Foolscap
return
6 changes: 2 additions & 4 deletions src/allmydata/check_results.py
@@ -1,8 +1,6 @@
"""Ported to Python 3.
"""

from past.builtins import unicode

from zope.interface import implementer
from allmydata.interfaces import ICheckResults, ICheckAndRepairResults, \
IDeepCheckResults, IDeepCheckAndRepairResults, IURI, IDisplayableServer
Expand Down Expand Up @@ -63,8 +61,8 @@ def __init__(self, uri, storage_index,
# On Python 2, we can mix bytes and Unicode. On Python 3, we want
# unicode.
if isinstance(summary, bytes):
summary = unicode(summary, "utf-8")
assert isinstance(summary, unicode) # should be a single string
summary = str(summary, "utf-8")
assert isinstance(summary, str) # should be a single string
self._summary = summary
assert not isinstance(report, str) # should be list of strings
self._report = report
Expand Down
10 changes: 4 additions & 6 deletions src/allmydata/crypto/aes.py
Expand Up @@ -10,8 +10,6 @@
Ported to Python 3.
"""

import six

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import (
Cipher,
Expand Down Expand Up @@ -79,7 +77,7 @@ def encrypt_data(encryptor, plaintext):
"""

_validate_cryptor(encryptor, encrypt=True)
if not isinstance(plaintext, six.binary_type):
if not isinstance(plaintext, bytes):
raise ValueError('Plaintext must be bytes')

return encryptor.update(plaintext)
Expand Down Expand Up @@ -118,7 +116,7 @@ def decrypt_data(decryptor, plaintext):
"""

_validate_cryptor(decryptor, encrypt=False)
if not isinstance(plaintext, six.binary_type):
if not isinstance(plaintext, bytes):
raise ValueError('Plaintext must be bytes')

return decryptor.update(plaintext)
Expand Down Expand Up @@ -160,7 +158,7 @@ def _validate_key(key):
"""
confirm `key` is suitable for AES encryption, or raise ValueError
"""
if not isinstance(key, six.binary_type):
if not isinstance(key, bytes):
raise TypeError('Key must be bytes')
if len(key) not in (16, 32):
raise ValueError('Key must be 16 or 32 bytes long')
Expand All @@ -175,7 +173,7 @@ def _validate_iv(iv):
"""
if iv is None:
return DEFAULT_IV
if not isinstance(iv, six.binary_type):
if not isinstance(iv, bytes):
raise TypeError('IV must be bytes')
if len(iv) != 16:
raise ValueError('IV must be 16 bytes long')
Expand Down
3 changes: 0 additions & 3 deletions src/allmydata/frontends/sftpd.py
Expand Up @@ -45,9 +45,6 @@
from allmydata.util.log import NOISY, OPERATIONAL, WEIRD, \
msg as logmsg, PrefixingLogMixin

if six.PY3:
long = int


def createSFTPError(errorCode, errorMessage):
"""
Expand Down
14 changes: 6 additions & 8 deletions src/allmydata/immutable/upload.py
Expand Up @@ -4,8 +4,6 @@

from __future__ import annotations

from future.utils import native_str
from past.builtins import long, unicode
from six import ensure_str

import os, time, weakref, itertools
Expand Down Expand Up @@ -57,7 +55,7 @@

_TOTAL_SHARES = Field.for_types(
u"total_shares",
[int, long],
[int],
u"The total number of shares desired.",
)

Expand Down Expand Up @@ -104,7 +102,7 @@ def _serialize_happiness_mappings(happiness_mappings):

_HAPPINESS = Field.for_types(
u"happiness",
[int, long],
[int],
u"The computed happiness of a certain placement.",
)

Expand Down Expand Up @@ -142,7 +140,7 @@ def _serialize_happiness_mappings(happiness_mappings):

_EFFECTIVE_HAPPINESS = Field.for_types(
u"effective_happiness",
[int, long],
[int],
u"The computed happiness value of a share placement map.",
)

Expand All @@ -166,7 +164,7 @@ class HelperUploadResults(Copyable, RemoteCopy):
# package/module/class name
#
# Needs to be native string to make Foolscap happy.
typeToCopy = native_str("allmydata.upload.UploadResults.tahoe.allmydata.com")
typeToCopy = "allmydata.upload.UploadResults.tahoe.allmydata.com"
copytype = typeToCopy

# also, think twice about changing the shape of any existing attribute,
Expand Down Expand Up @@ -1622,7 +1620,7 @@ def _convert_old_upload_results(self, upload_results):
# abbreviated), so if we detect old results, just clobber them.

sharemap = upload_results.sharemap
if any(isinstance(v, (bytes, unicode)) for v in sharemap.values()):
if any(isinstance(v, (bytes, str)) for v in sharemap.values()):
upload_results.sharemap = None

def _build_verifycap(self, helper_upload_results):
Expand Down Expand Up @@ -1701,7 +1699,7 @@ def set_upload_status(self, upload_status):
def set_default_encoding_parameters(self, default_params):
assert isinstance(default_params, dict)
for k,v in default_params.items():
precondition(isinstance(k, (bytes, unicode)), k, v)
precondition(isinstance(k, (bytes, str)), k, v)
precondition(isinstance(v, int), k, v)
if "k" in default_params:
self.default_encoding_param_k = default_params["k"]
Expand Down
13 changes: 5 additions & 8 deletions src/allmydata/interfaces.py
Expand Up @@ -6,9 +6,6 @@
Note that for RemoteInterfaces, the __remote_name__ needs to be a native string because of https://github.com/warner/foolscap/blob/43f4485a42c9c28e2c79d655b3a9e24d4e6360ca/src/foolscap/remoteinterface.py#L67
"""

from future.utils import native_str

from past.builtins import long
from typing import Dict

from zope.interface import Interface, Attribute
Expand Down Expand Up @@ -112,7 +109,7 @@ def advise_corrupt_share(reason=bytes):


class RIStorageServer(RemoteInterface):
__remote_name__ = native_str("RIStorageServer.tahoe.allmydata.com")
__remote_name__ = "RIStorageServer.tahoe.allmydata.com"

def get_version():
"""
Expand Down Expand Up @@ -2768,13 +2765,13 @@ def measure_peer_response_time():


class RIEncryptedUploadable(RemoteInterface):
__remote_name__ = native_str("RIEncryptedUploadable.tahoe.allmydata.com")
__remote_name__ = "RIEncryptedUploadable.tahoe.allmydata.com"

def get_size():
return Offset

def get_all_encoding_parameters():
return (int, int, int, long)
return (int, int, int, int)

def read_encrypted(offset=Offset, length=ReadSize):
return ListOf(bytes)
Expand All @@ -2784,7 +2781,7 @@ def close():


class RICHKUploadHelper(RemoteInterface):
__remote_name__ = native_str("RIUploadHelper.tahoe.allmydata.com")
__remote_name__ = "RIUploadHelper.tahoe.allmydata.com"

def get_version():
"""
Expand All @@ -2797,7 +2794,7 @@ def upload(reader=RIEncryptedUploadable):


class RIHelper(RemoteInterface):
__remote_name__ = native_str("RIHelper.tahoe.allmydata.com")
__remote_name__ = "RIHelper.tahoe.allmydata.com"

def get_version():
"""
Expand Down
4 changes: 1 addition & 3 deletions src/allmydata/introducer/client.py
Expand Up @@ -2,8 +2,6 @@
Ported to Python 3.
"""

from past.builtins import long

from six import ensure_text, ensure_str

import time
Expand Down Expand Up @@ -304,7 +302,7 @@ def _process_announcement(self, ann, key_s):
if "seqnum" in old:
# must beat previous sequence number to replace
if ("seqnum" not in ann
or not isinstance(ann["seqnum"], (int,long))):
or not isinstance(ann["seqnum"], int)):
self.log("not replacing old announcement, no valid seqnum: %s"
% (ann,),
parent=lp2, level=log.NOISY, umid="zFGH3Q")
Expand Down
10 changes: 5 additions & 5 deletions src/allmydata/introducer/interfaces.py
Expand Up @@ -2,9 +2,6 @@
Ported to Python 3.
"""


from future.utils import native_str

from zope.interface import Interface
from foolscap.api import StringConstraint, SetOf, DictOf, Any, \
RemoteInterface, Referenceable
Expand Down Expand Up @@ -34,7 +31,7 @@
Announcement_v2 = Any()

class RIIntroducerSubscriberClient_v2(RemoteInterface):
__remote_name__ = native_str("RIIntroducerSubscriberClient_v2.tahoe.allmydata.com")
__remote_name__ = "RIIntroducerSubscriberClient_v2.tahoe.allmydata.com"

def announce_v2(announcements=SetOf(Announcement_v2)):
"""I accept announcements from the publisher."""
Expand All @@ -47,11 +44,14 @@ class RIIntroducerPublisherAndSubscriberService_v2(RemoteInterface):
announcement message. I will deliver a copy to all connected subscribers.
To hear about services, connect to me and subscribe to a specific
service_name."""
__remote_name__ = native_str("RIIntroducerPublisherAndSubscriberService_v2.tahoe.allmydata.com")
__remote_name__ = "RIIntroducerPublisherAndSubscriberService_v2.tahoe.allmydata.com"

def get_version():
return DictOf(bytes, Any())

def publish_v2(announcement=Announcement_v2, canary=Referenceable):
return None

def subscribe_v2(subscriber=RIIntroducerSubscriberClient_v2,
service_name=bytes, subscriber_info=SubscriberInfo):
"""Give me a subscriber reference, and I will call its announce_v2()
Expand Down
3 changes: 1 addition & 2 deletions src/allmydata/introducer/server.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import annotations

from past.builtins import long
from six import ensure_text

import time, os.path, textwrap
Expand Down Expand Up @@ -262,7 +261,7 @@ def _publish(self, ann_t, canary, lp):
if "seqnum" in old_ann:
# must beat previous sequence number to replace
if ("seqnum" not in ann
or not isinstance(ann["seqnum"], (int,long))):
or not isinstance(ann["seqnum"], int)):
self.log("not replacing old ann, no valid seqnum",
level=log.NOISY, umid="ySbaVw")
self._debug_counts["inbound_no_seqnum"] += 1
Expand Down
4 changes: 2 additions & 2 deletions src/allmydata/node.py
Expand Up @@ -112,8 +112,8 @@ def formatTimeTahoeStyle(self, when):
"""
d = datetime.datetime.utcfromtimestamp(when)
if d.microsecond:
return d.isoformat(ensure_str(" "))[:-3]+"Z"
return d.isoformat(ensure_str(" ")) + ".000Z"
return d.isoformat(" ")[:-3]+"Z"
return d.isoformat(" ") + ".000Z"

PRIV_README = """
This directory contains files which contain private data for the Tahoe node,
Expand Down
7 changes: 3 additions & 4 deletions src/allmydata/scripts/default_nodedir.py
Expand Up @@ -3,7 +3,6 @@
"""

import sys
import six
from allmydata.util.assertutil import precondition
from allmydata.util.fileutil import abspath_expanduser_unicode

Expand All @@ -13,10 +12,10 @@
from allmydata.windows import registry
path = registry.get_base_dir_path()
if path:
precondition(isinstance(path, six.text_type), path)
precondition(isinstance(path, str), path)
_default_nodedir = abspath_expanduser_unicode(path)

if _default_nodedir is None:
path = abspath_expanduser_unicode(u"~/.tahoe")
precondition(isinstance(path, six.text_type), path)
path = abspath_expanduser_unicode("~/.tahoe")
precondition(isinstance(path, str), path)
_default_nodedir = path
6 changes: 3 additions & 3 deletions src/allmydata/scripts/runner.py
Expand Up @@ -65,8 +65,8 @@ class Options(usage.Options):
]
optParameters = [
["node-directory", "d", None, NODEDIR_HELP],
["wormhole-server", None, u"ws://wormhole.tahoe-lafs.org:4000/v1", "The magic wormhole server to use.", six.text_type],
["wormhole-invite-appid", None, u"tahoe-lafs.org/invite", "The appid to use on the wormhole server.", six.text_type],
["wormhole-server", None, u"ws://wormhole.tahoe-lafs.org:4000/v1", "The magic wormhole server to use.", str],
["wormhole-invite-appid", None, u"tahoe-lafs.org/invite", "The appid to use on the wormhole server.", str],
]

def opt_version(self):
Expand Down Expand Up @@ -262,7 +262,7 @@ def _setup_coverage(reactor, argv):
# can we put this _setup_coverage call after we hit
# argument-parsing?
# ensure_str() only necessary on Python 2.
if six.ensure_str('--coverage') not in sys.argv:
if '--coverage' not in sys.argv:
return
argv.remove('--coverage')

Expand Down
6 changes: 1 addition & 5 deletions src/allmydata/scripts/slow_operation.py
Expand Up @@ -2,8 +2,6 @@
Ported to Python 3.
"""

from future.utils import PY3

from six import ensure_str

import os, time
Expand Down Expand Up @@ -81,9 +79,7 @@ def poll(self):
if not data["finished"]:
return False
if self.options.get("raw"):
if PY3:
# need to write bytes!
stdout = stdout.buffer
stdout = stdout.buffer
if is_printable_ascii(jdata):
stdout.write(jdata)
stdout.write(b"\n")
Expand Down
12 changes: 5 additions & 7 deletions src/allmydata/scripts/tahoe_check.py
Expand Up @@ -2,7 +2,7 @@
Ported to Python 3.
"""

from six import ensure_str, ensure_text
from six import ensure_text

from urllib.parse import quote as url_quote
import json
Expand Down Expand Up @@ -168,7 +168,7 @@ def lineReceived(self, line):
# LIT files and directories do not have a "summary" field.
summary = cr.get("summary", "Healthy (LIT)")
# When Python 2 is dropped the ensure_text()/ensure_str() will be unnecessary.
print(ensure_text(ensure_str("%s: %s") % (quote_path(path), quote_output(summary, quotemarks=False)),
print(ensure_text("%s: %s" % (quote_path(path), quote_output(summary, quotemarks=False)),
encoding=get_io_encoding()), file=stdout)

# always print out corrupt shares
Expand Down Expand Up @@ -246,13 +246,11 @@ def lineReceived(self, line):
if not path:
path = ["<root>"]
# we don't seem to have a summary available, so build one
# When Python 2 is dropped the ensure_text/ensure_str crap can be
# dropped.
if was_healthy:
summary = ensure_str("healthy")
summary = "healthy"
else:
summary = ensure_str("not healthy")
print(ensure_text(ensure_str("%s: %s") % (quote_path(path), summary),
summary = "not healthy"
print(ensure_text("%s: %s" % (quote_path(path), summary),
encoding=get_io_encoding()), file=stdout)

# always print out corrupt shares
Expand Down

0 comments on commit 432e041

Please sign in to comment.