From 168532de07b5142513310d9008023fb1bccbf9d4 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Sat, 21 Dec 2024 19:03:57 +0100 Subject: [PATCH 1/2] finish removing "future" --- newsfragments/4152.other | 2 +- pyinstaller.spec | 1 - pyproject.toml | 4 +--- src/allmydata/test/common.py | 5 +++-- src/allmydata/test/test_base62.py | 5 +++-- src/allmydata/test/test_encode.py | 5 +++-- src/allmydata/test/test_system.py | 3 ++- src/allmydata/util/base62.py | 5 +++-- src/allmydata/util/hashutil.py | 3 ++- 9 files changed, 18 insertions(+), 15 deletions(-) diff --git a/newsfragments/4152.other b/newsfragments/4152.other index c12169c71..9bb0232e9 100644 --- a/newsfragments/4152.other +++ b/newsfragments/4152.other @@ -1 +1 @@ -remote more usage of deprecated future library +remote all usage of deprecated future library diff --git a/pyinstaller.spec b/pyinstaller.spec index 5c24df430..4b6e9f62d 100644 --- a/pyinstaller.spec +++ b/pyinstaller.spec @@ -40,7 +40,6 @@ hidden_imports = [ 'commands', 'Crypto', 'functools', - 'future.backports.misc', 'itertools', 'math', 'packaging.specifiers', diff --git a/pyproject.toml b/pyproject.toml index 31a0c9829..16a839e6d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -117,6 +117,7 @@ dependencies = [ "PyYAML >= 3.11", + # to be slowly removed from codebase "six >= 1.10.0", # For 'tahoe invite' and 'tahoe join' @@ -133,9 +134,6 @@ dependencies = [ # WebSocket library for twisted and asyncio "autobahn >= 22.4.3", - # Support for Python 3 transition - "future >= 0.18.2", - # Discover local network configuration "netifaces", diff --git a/src/allmydata/test/common.py b/src/allmydata/test/common.py index 4ec3c2300..e6ca325c9 100644 --- a/src/allmydata/test/common.py +++ b/src/allmydata/test/common.py @@ -3,8 +3,6 @@ Functionality related to a lot of the test suite. """ from __future__ import annotations -from past.builtins import chr as byteschr - __all__ = [ "SyncTestCase", "AsyncTestCase", @@ -127,6 +125,9 @@ EMPTY_CLIENT_CONFIG = config_from_string( "" ) +def byteschr(x): + return bytes([x]) + @attr.s class FakeDisk(object): """ diff --git a/src/allmydata/test/test_base62.py b/src/allmydata/test/test_base62.py index d77eaef9c..0081f0235 100644 --- a/src/allmydata/test/test_base62.py +++ b/src/allmydata/test/test_base62.py @@ -4,8 +4,6 @@ Tests for allmydata.util.base62. Ported to Python 3. """ -from past.builtins import chr as byteschr - import random, unittest from hypothesis import ( @@ -15,6 +13,9 @@ from hypothesis import ( from allmydata.util import base62, mathutil +def byteschr(x): + return bytes([x]) + def insecurerandstr(n): return bytes(list(map(random.randrange, [0]*n, [256]*n))) diff --git a/src/allmydata/test/test_encode.py b/src/allmydata/test/test_encode.py index ba11605ab..92757d88f 100644 --- a/src/allmydata/test/test_encode.py +++ b/src/allmydata/test/test_encode.py @@ -2,8 +2,6 @@ Ported to Python 3. """ -from past.builtins import chr as byteschr - from zope.interface import implementer from twisted.trial import unittest from twisted.internet import defer @@ -20,6 +18,9 @@ from allmydata.test.no_network import GridTestMixin class LostPeerError(Exception): pass +def byteschr(x): + return bytes([x]) + def flip_bit(good): # flips the last bit return good[:-1] + byteschr(ord(good[-1]) ^ 0x01) diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index 14e7f97f5..9e85ab032 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -3,7 +3,6 @@ Ported to Python 3. """ from __future__ import annotations -from past.builtins import chr as byteschr from six import ensure_text import os, re, sys, time, json @@ -47,6 +46,8 @@ from .web.common import ( from .common_system import SystemTestMixin from .common_util import run_cli_unicode +def byteschr(x): + return bytes([x]) class RunBinTahoeMixin(object): def run_bintahoe(self, args, stdin=None, python_options:Optional[list[str]]=None, env=None): diff --git a/src/allmydata/util/base62.py b/src/allmydata/util/base62.py index 3602ef0ef..829bca982 100644 --- a/src/allmydata/util/base62.py +++ b/src/allmydata/util/base62.py @@ -7,8 +7,6 @@ Ported to Python 3. maketrans = bytes.maketrans translate = bytes.translate -from past.builtins import chr as byteschr - from allmydata.util.mathutil import log_ceil, log_floor chars = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" @@ -20,6 +18,9 @@ c2vtranstable = maketrans(chars, vals) v2ctranstable = maketrans(vals, chars) identitytranstable = maketrans(chars, chars) +def byteschr(x): + return bytes([x]) + def b2a(os): """ @param os the data to be encoded (as bytes) diff --git a/src/allmydata/util/hashutil.py b/src/allmydata/util/hashutil.py index 7217a2d93..0f5e2676e 100644 --- a/src/allmydata/util/hashutil.py +++ b/src/allmydata/util/hashutil.py @@ -4,7 +4,8 @@ Hashing utilities. Ported to Python 3. """ -from past.builtins import chr as byteschr +def byteschr(x): + return bytes([x]) import os import hashlib From 7ca3a4c6610ff7c953eb9d936566c31148c27218 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Sat, 21 Dec 2024 19:08:16 +0100 Subject: [PATCH 2/2] define function before use --- src/allmydata/util/base62.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/allmydata/util/base62.py b/src/allmydata/util/base62.py index 829bca982..38370ea5a 100644 --- a/src/allmydata/util/base62.py +++ b/src/allmydata/util/base62.py @@ -13,14 +13,14 @@ chars = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" BASE62CHAR = b'[' + chars + b']' +def byteschr(x): + return bytes([x]) + vals = b''.join([byteschr(i) for i in range(62)]) c2vtranstable = maketrans(chars, vals) v2ctranstable = maketrans(vals, chars) identitytranstable = maketrans(chars, chars) -def byteschr(x): - return bytes([x]) - def b2a(os): """ @param os the data to be encoded (as bytes)