mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-09 11:51:21 +00:00
Merge branch 'master' into 4072-no-more-blocking-part-2
This commit is contained in:
commit
62f59fb6b3
@ -12,9 +12,6 @@
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
|
@ -6,11 +6,6 @@
|
||||
# longer" to start the first test as the fixtures get built
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
def test_create_flogger(flog_gatherer):
|
||||
print("Created flog_gatherer")
|
||||
|
||||
|
@ -10,11 +10,6 @@ These tests use Paramiko, rather than Twisted's Conch, because:
|
||||
2. Its API is much simpler to use.
|
||||
"""
|
||||
|
||||
|
||||
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 os.path
|
||||
from posixpath import join
|
||||
from stat import S_ISDIR
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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_text
|
||||
|
||||
import json
|
||||
|
@ -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
|
||||
|
@ -1,11 +1,5 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from future.builtins import input
|
||||
|
||||
|
||||
import random, math, re
|
||||
from twisted.python import usage
|
||||
|
||||
|
0
newsfragments/4091.minor
Normal file
0
newsfragments/4091.minor
Normal file
0
newsfragments/4092.minor
Normal file
0
newsfragments/4092.minor
Normal file
0
newsfragments/4093.minor
Normal file
0
newsfragments/4093.minor
Normal file
@ -2,11 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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 sys
|
||||
|
||||
from allmydata.scripts.runner import run
|
||||
|
@ -4,41 +4,5 @@ Monkey-patching of third party libraries.
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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 warnings import catch_warnings
|
||||
|
||||
|
||||
def patch():
|
||||
"""Path third-party libraries to make Tahoe-LAFS work."""
|
||||
# Make sure Foolscap always get native strings passed to method names in callRemote.
|
||||
# This can be removed when any one of the following happens:
|
||||
#
|
||||
# 1. Tahoe-LAFS on Python 2 switches to version of Foolscap that fixes
|
||||
# https://github.com/warner/foolscap/issues/72
|
||||
# 2. Foolscap is dropped as a dependency.
|
||||
# 3. Tahoe-LAFS drops Python 2 support.
|
||||
|
||||
if not PY2:
|
||||
# Python 3 doesn't need to monkey patch Foolscap
|
||||
return
|
||||
|
||||
# We need to suppress warnings so as to prevent unexpected output from
|
||||
# breaking some integration tests.
|
||||
with catch_warnings(record=True):
|
||||
# Only tested with this version; ensure correctness with new releases,
|
||||
# and then either update the assert or hopefully drop the monkeypatch.
|
||||
from foolscap import __version__
|
||||
assert __version__ == "0.13.1", "Wrong version %s of Foolscap" % (__version__,)
|
||||
|
||||
from foolscap.referenceable import RemoteReference
|
||||
original_getMethodInfo = RemoteReference._getMethodInfo
|
||||
|
||||
def _getMethodInfo(self, name):
|
||||
if isinstance(name, str):
|
||||
name = name.encode("utf-8")
|
||||
return original_getMethodInfo(self, name)
|
||||
RemoteReference._getMethodInfo = _getMethodInfo
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 os
|
||||
|
||||
from zope.interface import implementer
|
||||
|
@ -1,12 +1,6 @@
|
||||
"""Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 unicode
|
||||
|
||||
from zope.interface import implementer
|
||||
from allmydata.interfaces import ICheckResults, ICheckAndRepairResults, \
|
||||
IDeepCheckResults, IDeepCheckAndRepairResults, IURI, IDisplayableServer
|
||||
@ -67,8 +61,8 @@ class CheckResults(object):
|
||||
# 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
|
||||
|
@ -4,10 +4,6 @@ CRS encoding and decoding.
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from 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 zope.interface import implementer
|
||||
from allmydata.util import mathutil
|
||||
from allmydata.util.assertutil import precondition
|
||||
|
@ -9,7 +9,3 @@ objects that `cryptography` documents.
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from 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
|
||||
|
@ -10,12 +10,6 @@ objects that `cryptography` documents.
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from 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 six
|
||||
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives.ciphers import (
|
||||
Cipher,
|
||||
@ -83,7 +77,7 @@ def encrypt_data(encryptor, plaintext):
|
||||
"""
|
||||
|
||||
_validate_cryptor(encryptor, encrypt=True)
|
||||
if not isinstance(plaintext, (six.binary_type, memoryview)):
|
||||
if not isinstance(plaintext, (bytes, memoryview)):
|
||||
raise ValueError(f'Plaintext must be bytes or memoryview: {type(plaintext)}')
|
||||
|
||||
return encryptor.update(plaintext)
|
||||
@ -122,7 +116,7 @@ def decrypt_data(decryptor, plaintext):
|
||||
"""
|
||||
|
||||
_validate_cryptor(decryptor, encrypt=False)
|
||||
if not isinstance(plaintext, (six.binary_type, memoryview)):
|
||||
if not isinstance(plaintext, (bytes, memoryview)):
|
||||
raise ValueError(f'Plaintext must be bytes or memoryview: {type(plaintext)}')
|
||||
|
||||
return decryptor.update(plaintext)
|
||||
@ -164,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')
|
||||
@ -179,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')
|
||||
|
@ -4,11 +4,6 @@ Exceptions raise by allmydata.crypto.* modules
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from 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
|
||||
|
||||
|
||||
class BadSignature(Exception):
|
||||
"""
|
||||
An alleged signature did not match
|
||||
|
@ -4,10 +4,6 @@ Utilities used by allmydata.crypto modules
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from 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 allmydata.crypto.error import BadPrefixError
|
||||
|
||||
|
||||
|
@ -3,10 +3,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 math
|
||||
|
||||
from allmydata.interfaces import IImmutableFileNode
|
||||
|
@ -3,10 +3,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
# Skip dict so it doesn't break things.
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, list, object, range, str, max, min # noqa: F401
|
||||
from past.builtins import unicode
|
||||
|
||||
import time
|
||||
|
@ -2,10 +2,6 @@
|
||||
Authentication for frontends.
|
||||
"""
|
||||
|
||||
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 zope.interface import implementer
|
||||
from twisted.internet import defer
|
||||
from twisted.cred import checkers, credentials
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 six
|
||||
import heapq, traceback, stat, struct
|
||||
from stat import S_IFREG, S_IFDIR
|
||||
@ -49,9 +45,6 @@ noisy = True
|
||||
from allmydata.util.log import NOISY, OPERATIONAL, WEIRD, \
|
||||
msg as logmsg, PrefixingLogMixin
|
||||
|
||||
if six.PY3:
|
||||
long = int
|
||||
|
||||
|
||||
def createSFTPError(errorCode, errorMessage):
|
||||
"""
|
||||
|
@ -49,11 +49,6 @@ or eat your children, but it might. Use at your own risk.
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from 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 allmydata.util import mathutil # from the pyutil library
|
||||
|
||||
from allmydata.util import base32
|
||||
|
@ -1,11 +1,6 @@
|
||||
"""Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 weakref
|
||||
|
||||
class History(object):
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 zope.interface import implementer
|
||||
from twisted.internet import defer
|
||||
from foolscap.api import DeadReferenceError, RemoteException
|
||||
|
@ -1,9 +1,3 @@
|
||||
"""
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
@ -2,11 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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
|
||||
|
||||
(AVAILABLE, PENDING, OVERDUE, COMPLETE, CORRUPT, DEAD, BADSEGNUM) = \
|
||||
("AVAILABLE", "PENDING", "OVERDUE", "COMPLETE", "CORRUPT", "DEAD", "BADSEGNUM")
|
||||
|
||||
|
@ -2,11 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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.python.failure import Failure
|
||||
from foolscap.api import eventually
|
||||
from allmydata.interfaces import NotEnoughSharesError, NoSharesError
|
||||
|
@ -2,9 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 time
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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
|
||||
now = time.time
|
||||
from zope.interface import Interface
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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
|
||||
now = time.time
|
||||
from zope.interface import implementer
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 struct
|
||||
import time
|
||||
now = time.time
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 itertools
|
||||
from zope.interface import implementer
|
||||
from allmydata.interfaces import IDownloadStatus
|
||||
|
@ -4,11 +4,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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
|
||||
from zope.interface import implementer
|
||||
from twisted.internet import defer
|
||||
|
@ -2,11 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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 functools import reduce
|
||||
import binascii
|
||||
from time import time as now
|
||||
|
@ -5,11 +5,6 @@ on.
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
# We omit dict, just in case newdict breaks things for external Python 2 code.
|
||||
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
from queue import PriorityQueue
|
||||
|
||||
|
||||
|
@ -2,11 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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 io import BytesIO
|
||||
|
||||
from zope.interface import implementer
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 os, stat, time, weakref
|
||||
from zope.interface import implementer
|
||||
from twisted.internet import defer
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 zope.interface import implementer
|
||||
from twisted.internet import defer
|
||||
from allmydata.storage.server import si_b2a
|
||||
|
@ -4,8 +4,6 @@ Ported to Python 3.
|
||||
|
||||
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
|
||||
@ -57,7 +55,7 @@ from eliot import (
|
||||
|
||||
_TOTAL_SHARES = Field.for_types(
|
||||
u"total_shares",
|
||||
[int, long],
|
||||
[int],
|
||||
u"The total number of shares desired.",
|
||||
)
|
||||
|
||||
@ -104,7 +102,7 @@ _HAPPINESS_MAPPINGS = Field(
|
||||
|
||||
_HAPPINESS = Field.for_types(
|
||||
u"happiness",
|
||||
[int, long],
|
||||
[int],
|
||||
u"The computed happiness of a certain placement.",
|
||||
)
|
||||
|
||||
@ -142,7 +140,7 @@ GET_SHARE_PLACEMENTS = MessageType(
|
||||
|
||||
_EFFECTIVE_HAPPINESS = Field.for_types(
|
||||
u"effective_happiness",
|
||||
[int, long],
|
||||
[int],
|
||||
u"The computed happiness value of a share placement map.",
|
||||
)
|
||||
|
||||
@ -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,
|
||||
@ -1622,7 +1620,7 @@ class AssistedUploader(object):
|
||||
# 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):
|
||||
@ -1701,7 +1699,7 @@ class BaseUploadable(object):
|
||||
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"]
|
||||
|
@ -6,13 +6,6 @@ Ported to Python 3.
|
||||
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 PY2, native_str
|
||||
if PY2:
|
||||
# Don't import object/str/dict/etc. types, so we don't break any
|
||||
# interfaces. Not importing open() because it triggers bogus flake8 error.
|
||||
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, pow, round, super, range, max, min # noqa: F401
|
||||
|
||||
from past.builtins import long
|
||||
from typing import Dict
|
||||
|
||||
from zope.interface import Interface, Attribute
|
||||
@ -116,7 +109,7 @@ ReadData = ListOf(ShareData)
|
||||
|
||||
|
||||
class RIStorageServer(RemoteInterface):
|
||||
__remote_name__ = native_str("RIStorageServer.tahoe.allmydata.com")
|
||||
__remote_name__ = "RIStorageServer.tahoe.allmydata.com"
|
||||
|
||||
def get_version():
|
||||
"""
|
||||
@ -2772,13 +2765,13 @@ UploadResults = Any() #DictOf(bytes, bytes)
|
||||
|
||||
|
||||
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)
|
||||
@ -2788,7 +2781,7 @@ class RIEncryptedUploadable(RemoteInterface):
|
||||
|
||||
|
||||
class RICHKUploadHelper(RemoteInterface):
|
||||
__remote_name__ = native_str("RIUploadHelper.tahoe.allmydata.com")
|
||||
__remote_name__ = "RIUploadHelper.tahoe.allmydata.com"
|
||||
|
||||
def get_version():
|
||||
"""
|
||||
@ -2801,7 +2794,7 @@ class RICHKUploadHelper(RemoteInterface):
|
||||
|
||||
|
||||
class RIHelper(RemoteInterface):
|
||||
__remote_name__ = native_str("RIHelper.tahoe.allmydata.com")
|
||||
__remote_name__ = "RIHelper.tahoe.allmydata.com"
|
||||
|
||||
def get_version():
|
||||
"""
|
||||
|
@ -2,12 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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 allmydata.introducer.server import create_introducer
|
||||
|
||||
# apparently need to support "old .tac files" that may have
|
||||
|
@ -2,11 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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
|
||||
|
||||
from six import ensure_text, ensure_str
|
||||
|
||||
import time
|
||||
@ -307,7 +302,7 @@ class IntroducerClient(service.Service, Referenceable):
|
||||
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")
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 re
|
||||
|
||||
from foolscap.furl import decode_furl
|
||||
|
@ -2,12 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
from future.utils import PY2, native_str
|
||||
if PY2:
|
||||
# Omitted types (bytes etc.) so future variants don't confuse Foolscap.
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, object, range, max, min # noqa: F401
|
||||
|
||||
from zope.interface import Interface
|
||||
from foolscap.api import StringConstraint, SetOf, DictOf, Any, \
|
||||
RemoteInterface, Referenceable
|
||||
@ -37,7 +31,7 @@ FURL = StringConstraint(1000)
|
||||
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."""
|
||||
@ -50,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()
|
||||
|
@ -4,7 +4,6 @@ Ported to Python 3.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from past.builtins import long
|
||||
from six import ensure_text
|
||||
|
||||
import time, os.path, textwrap
|
||||
@ -262,7 +261,7 @@ class IntroducerService(service.MultiService, Referenceable): # type: ignore[mi
|
||||
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
|
||||
|
@ -4,10 +4,6 @@ Manage status of long-running operations.
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from 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 zope.interface import Interface, implementer
|
||||
from allmydata.util import observer
|
||||
|
||||
|
@ -2,9 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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
|
||||
|
||||
from allmydata.uri import from_string
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
# Omit dict so Python 3 changes don't leak into API callers on Python 2.
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, list, object, range, str, max, min # noqa: F401
|
||||
from past.utils import old_div
|
||||
|
||||
import struct
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 os, time
|
||||
from io import BytesIO
|
||||
from itertools import count
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 zope.interface import implementer
|
||||
from twisted.internet import defer
|
||||
from allmydata.interfaces import IRepairResults, ICheckResults
|
||||
|
@ -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,
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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_binary
|
||||
|
||||
from twisted.python import usage
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 os.path, sys, time, random, stat
|
||||
|
||||
from allmydata.util.netstring import netstring
|
||||
|
@ -2,13 +2,7 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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 sys
|
||||
import six
|
||||
from allmydata.util.assertutil import precondition
|
||||
from allmydata.util.fileutil import abspath_expanduser_unicode
|
||||
|
||||
@ -18,10 +12,10 @@ if sys.platform == 'win32':
|
||||
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
|
||||
|
@ -1,6 +1,5 @@
|
||||
import os, sys
|
||||
from io import StringIO
|
||||
from past.builtins import unicode
|
||||
import six
|
||||
|
||||
from twisted.python import usage
|
||||
@ -66,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):
|
||||
@ -106,28 +105,7 @@ def parse_options(argv, config=None):
|
||||
config = Options()
|
||||
try:
|
||||
config.parseOptions(argv)
|
||||
except usage.error as e:
|
||||
if six.PY2:
|
||||
# On Python 2 the exception may hold non-ascii in a byte string.
|
||||
# This makes it impossible to convert the exception to any kind of
|
||||
# string using str() or unicode(). It could also hold non-ascii
|
||||
# in a unicode string which still makes it difficult to convert it
|
||||
# to a byte string later.
|
||||
#
|
||||
# So, reach inside and turn it into some entirely safe ascii byte
|
||||
# strings that will survive being written to stdout without
|
||||
# causing too much damage in the process.
|
||||
#
|
||||
# As a result, non-ascii will not be rendered correctly but
|
||||
# instead as escape sequences. At least this can go away when
|
||||
# we're done with Python 2 support.
|
||||
raise usage.error(*(
|
||||
arg.encode("ascii", errors="backslashreplace")
|
||||
if isinstance(arg, unicode)
|
||||
else arg.decode("utf-8").encode("ascii", errors="backslashreplace")
|
||||
for arg
|
||||
in e.args
|
||||
))
|
||||
except usage.error:
|
||||
raise
|
||||
return config
|
||||
|
||||
@ -284,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')
|
||||
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2, PY3
|
||||
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 os, time
|
||||
@ -83,9 +79,7 @@ class SlowOperationRunner(object):
|
||||
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")
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 os.path
|
||||
import codecs
|
||||
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 os.path
|
||||
import time
|
||||
from urllib.parse import quote as url_quote
|
||||
|
@ -2,11 +2,7 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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, ensure_text
|
||||
from six import ensure_text
|
||||
|
||||
from urllib.parse import quote as url_quote
|
||||
import json
|
||||
@ -172,7 +168,7 @@ class DeepCheckOutput(LineOnlyReceiver, object):
|
||||
# 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
|
||||
@ -250,13 +246,11 @@ class DeepCheckAndRepairOutput(LineOnlyReceiver, object):
|
||||
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
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 os.path
|
||||
from urllib.parse import quote as url_quote
|
||||
from collections import defaultdict
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2, PY3
|
||||
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 url_quote
|
||||
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
|
||||
UnknownAliasError
|
||||
@ -38,7 +34,7 @@ def get(options):
|
||||
outf = stdout
|
||||
# Make sure we can write bytes; on Python 3 stdout is Unicode by
|
||||
# default.
|
||||
if PY3 and getattr(outf, "encoding", None) is not None:
|
||||
if getattr(outf, "encoding", None) is not None:
|
||||
outf = outf.buffer
|
||||
while True:
|
||||
data = resp.read(4096)
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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_text
|
||||
|
||||
import time
|
||||
|
@ -2,12 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2, PY3
|
||||
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
|
||||
|
||||
from urllib.parse import quote as url_quote
|
||||
import json
|
||||
from twisted.protocols.basic import LineOnlyReceiver
|
||||
@ -58,8 +52,7 @@ class ManifestStreamer(LineOnlyReceiver, object):
|
||||
# use Twisted to split this into lines
|
||||
self.in_error = False
|
||||
# Writing bytes, so need binary stdout.
|
||||
if PY3:
|
||||
stdout = stdout.buffer
|
||||
stdout = stdout.buffer
|
||||
while True:
|
||||
chunk = resp.read(100)
|
||||
if not chunk:
|
||||
@ -101,8 +94,7 @@ class ManifestStreamer(LineOnlyReceiver, object):
|
||||
if vc:
|
||||
print(quote_output(vc, quotemarks=False), file=stdout)
|
||||
else:
|
||||
# ensure_str() only necessary for Python 2.
|
||||
print(ensure_str("%s %s") % (
|
||||
print("%s %s" % (
|
||||
quote_output(d["cap"], quotemarks=False),
|
||||
quote_path(d["path"], quotemarks=False)), file=stdout)
|
||||
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 url_quote
|
||||
from allmydata.scripts.common_http import do_http, check_http_error
|
||||
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, UnknownAliasError
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 re
|
||||
from urllib.parse import quote as url_quote
|
||||
import json
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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
|
||||
|
||||
__all__ = [
|
||||
"RunOptions",
|
||||
"run",
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 os
|
||||
from sys import stdout as _sys_stdout
|
||||
from urllib.parse import urlencode
|
||||
@ -28,13 +24,12 @@ def print(*args, **kwargs):
|
||||
encoding error handler and then write the result whereas builtin print
|
||||
uses the "strict" encoding error handler.
|
||||
"""
|
||||
from past.builtins import unicode
|
||||
out = kwargs.pop("file", None)
|
||||
if out is None:
|
||||
out = _sys_stdout
|
||||
encoding = out.encoding or "ascii"
|
||||
def ensafe(o):
|
||||
if isinstance(o, unicode):
|
||||
if isinstance(o, str):
|
||||
return o.encode(encoding, errors="replace").decode(encoding)
|
||||
return o
|
||||
return _print(
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 url_quote
|
||||
from allmydata.scripts.common_http import do_http, format_http_success, format_http_error
|
||||
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 url_quote
|
||||
|
||||
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2, PY3
|
||||
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 os.path
|
||||
from allmydata.util import base32
|
||||
|
||||
@ -45,7 +41,5 @@ def storage_index_to_dir(storageindex):
|
||||
Returns native string.
|
||||
"""
|
||||
sia = si_b2a(storageindex)
|
||||
if PY3:
|
||||
# On Python 3 we expect paths to be unicode.
|
||||
sia = sia.decode("ascii")
|
||||
sia = sia.decode("ascii")
|
||||
return os.path.join(sia[:2], sia)
|
||||
|
@ -4,11 +4,6 @@ Crawl the storage server shares.
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
from future.utils import PY2, PY3
|
||||
if PY2:
|
||||
from 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 os
|
||||
import time
|
||||
import json
|
||||
@ -152,10 +147,7 @@ def _dump_json_to_file(js, afile):
|
||||
"""
|
||||
with afile.open("wb") as f:
|
||||
data = json.dumps(js)
|
||||
if PY2:
|
||||
f.write(data)
|
||||
else:
|
||||
f.write(data.encode("utf8"))
|
||||
f.write(data.encode("utf8"))
|
||||
|
||||
|
||||
class _LeaseStateSerializer(object):
|
||||
@ -251,9 +243,7 @@ class ShareCrawler(service.MultiService):
|
||||
self._state_serializer = _LeaseStateSerializer(statefile)
|
||||
self.prefixes = [si_b2a(struct.pack(">H", i << (16-10)))[:2]
|
||||
for i in range(2**10)]
|
||||
if PY3:
|
||||
# On Python 3 we expect the paths to be unicode, not bytes.
|
||||
self.prefixes = [p.decode("ascii") for p in self.prefixes]
|
||||
self.prefixes = [p.decode("ascii") for p in self.prefixes]
|
||||
self.prefixes.sort()
|
||||
self.timer = None
|
||||
self.bucket_cache = (None, [])
|
||||
|
@ -1,7 +1,3 @@
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from 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 json
|
||||
import time
|
||||
import os
|
||||
|
@ -3,9 +3,7 @@ Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
from future.utils import PY2, bytes_to_native_str
|
||||
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 future.utils import bytes_to_native_str
|
||||
|
||||
import os, stat, struct, time
|
||||
|
||||
|
@ -2,11 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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 struct
|
||||
|
||||
import attr
|
||||
|
@ -2,11 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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 struct, time
|
||||
|
||||
import attr
|
||||
|
@ -2,11 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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 os, stat, struct
|
||||
|
||||
from allmydata.interfaces import (
|
||||
|
@ -2,11 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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 struct
|
||||
|
||||
import attr
|
||||
|
@ -2,11 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
|
||||
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 allmydata.storage.mutable import MutableShareFile
|
||||
from allmydata.storage.immutable import ShareFile
|
||||
|
||||
|
@ -16,10 +16,6 @@ some side-effects which make things better when the test suite runs.
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 traceback import extract_stack, format_list
|
||||
|
||||
from foolscap.pb import Listener
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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, ensure_text
|
||||
|
||||
from ...scripts import runner
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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
|
||||
|
||||
# We're going to override stdin/stderr, so want to match their behavior on respective Python versions.
|
||||
from io import StringIO
|
||||
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 json
|
||||
|
||||
from twisted.trial import unittest
|
||||
|
@ -2,12 +2,8 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 os.path
|
||||
from six.moves import cStringIO as StringIO
|
||||
from io import StringIO
|
||||
from datetime import timedelta
|
||||
import re
|
||||
|
||||
@ -16,7 +12,7 @@ from twisted.python.monkey import MonkeyPatcher
|
||||
|
||||
from allmydata.util import fileutil
|
||||
from allmydata.util.fileutil import abspath_expanduser_unicode
|
||||
from allmydata.util.encodingutil import get_io_encoding, unicode_to_argv
|
||||
from allmydata.util.encodingutil import unicode_to_argv
|
||||
from allmydata.util.namespace import Namespace
|
||||
from allmydata.scripts import cli, backupdb
|
||||
from ..common_util import StallMixin
|
||||
@ -368,8 +364,6 @@ class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
|
||||
nice_doc = u"nice_d\u00F8c.lyx"
|
||||
try:
|
||||
doc_pattern_arg_unicode = doc_pattern_arg = u"*d\u00F8c*"
|
||||
if PY2:
|
||||
doc_pattern_arg = doc_pattern_arg.encode(get_io_encoding())
|
||||
except UnicodeEncodeError:
|
||||
raise unittest.SkipTest("A non-ASCII command argument could not be encoded on this platform.")
|
||||
|
||||
@ -425,10 +419,7 @@ class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
|
||||
else:
|
||||
return original_open(name, *args, **kwargs)
|
||||
|
||||
if PY2:
|
||||
from allmydata.scripts import cli as module_to_patch
|
||||
else:
|
||||
import builtins as module_to_patch
|
||||
import builtins as module_to_patch
|
||||
patcher = MonkeyPatcher((module_to_patch, 'open', call_file))
|
||||
patcher.runWithPatches(parse_options, basedir, "backup", ['--exclude-from-utf-8', unicode_to_argv(exclude_file), 'from', 'to'])
|
||||
self.failUnless(ns.called)
|
||||
|
@ -2,14 +2,9 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
# Don't import future bytes so we don't break a couple of tests
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, dict, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
import sys
|
||||
import os.path, time
|
||||
from six.moves import cStringIO as StringIO
|
||||
from io import StringIO
|
||||
from twisted.trial import unittest
|
||||
|
||||
from allmydata.util import fileutil
|
||||
|
@ -1,13 +1,9 @@
|
||||
|
||||
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_text
|
||||
|
||||
import os.path
|
||||
import json
|
||||
from twisted.trial import unittest
|
||||
from six.moves import cStringIO as StringIO
|
||||
from io import StringIO
|
||||
|
||||
from allmydata import uri
|
||||
from allmydata.util import base32
|
||||
|
@ -2,11 +2,7 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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.moves import cStringIO as StringIO
|
||||
from io import StringIO
|
||||
import re
|
||||
from six import ensure_text
|
||||
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 os.path, json
|
||||
from twisted.trial import unittest
|
||||
from twisted.python import usage
|
||||
@ -13,8 +9,7 @@ from twisted.internet import defer
|
||||
|
||||
from allmydata.scripts import cli
|
||||
from allmydata.util import fileutil
|
||||
from allmydata.util.encodingutil import (quote_output, get_io_encoding,
|
||||
unicode_to_output, to_bytes)
|
||||
from allmydata.util.encodingutil import (quote_output, unicode_to_output, to_bytes)
|
||||
from allmydata.util.assertutil import _assert
|
||||
from ..no_network import GridTestMixin
|
||||
from .common import CLITestMixin
|
||||
@ -73,8 +68,6 @@ class Cp(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
self.failUnlessIn("files whose names could not be converted", err)
|
||||
else:
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
if PY2:
|
||||
out = out.decode(get_io_encoding())
|
||||
self.failUnlessReallyEqual(out, u"Metallica\n\u00C4rtonwall\n\u00C4rtonwall-2\n")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
d.addCallback(_check)
|
||||
@ -231,8 +224,6 @@ class Cp(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
self.failUnlessIn("files whose names could not be converted", err)
|
||||
else:
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
if PY2:
|
||||
out = out.decode(get_io_encoding())
|
||||
self.failUnlessReallyEqual(out, u"\u00C4rtonwall\n")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
d.addCallback(_check)
|
||||
|
@ -2,11 +2,7 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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.moves import StringIO
|
||||
from io import StringIO
|
||||
import os.path
|
||||
from twisted.trial import unittest
|
||||
from urllib.parse import quote as url_quote
|
||||
|
@ -2,11 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2, PY3
|
||||
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
|
||||
|
||||
from twisted.trial import unittest
|
||||
from twisted.internet import defer
|
||||
|
||||
@ -14,7 +9,7 @@ from allmydata.immutable import upload
|
||||
from allmydata.interfaces import MDMF_VERSION, SDMF_VERSION
|
||||
from allmydata.mutable.publish import MutableData
|
||||
from ..no_network import GridTestMixin
|
||||
from allmydata.util.encodingutil import quote_output, get_io_encoding
|
||||
from allmydata.util.encodingutil import quote_output
|
||||
from .common import CLITestMixin
|
||||
|
||||
|
||||
@ -28,10 +23,6 @@ class List(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
good_arg = u"g\u00F6\u00F6d"
|
||||
good_out = u"g\u00F6\u00F6d"
|
||||
|
||||
# On Python 2 we get bytes, so we need encoded version. On Python 3
|
||||
# stdio is unicode so can leave unchanged.
|
||||
good_out_encoded = good_out if PY3 else good_out.encode(get_io_encoding())
|
||||
|
||||
d = c0.create_dirnode()
|
||||
def _stash_root_and_create_file(n):
|
||||
self.rootnode = n
|
||||
@ -54,7 +45,7 @@ class List(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
self.assertEqual(len(err), 0, err)
|
||||
expected = sorted([ensure_str("0share"), ensure_str("1share"), good_out_encoded])
|
||||
expected = sorted(["0share", "1share", good_out])
|
||||
self.assertEqual(sorted(out.splitlines()), expected)
|
||||
d.addCallback(_check1)
|
||||
d.addCallback(lambda ign: self.do_cli("ls", "missing"))
|
||||
@ -87,8 +78,8 @@ class List(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
# listing a file (as dir/filename) should have the edge metadata,
|
||||
# including the filename
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
self.failUnlessIn(good_out_encoded, out)
|
||||
self.failIfIn(ensure_str("-r-- %d -" % len(small)), out,
|
||||
self.failUnlessIn(good_out, out)
|
||||
self.failIfIn("-r-- %d -" % len(small), out,
|
||||
"trailing hyphen means unknown date")
|
||||
|
||||
if good_arg is not None:
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 os.path
|
||||
from twisted.trial import unittest
|
||||
from allmydata.util import fileutil
|
||||
|
@ -5,7 +5,7 @@ Tests for ``allmydata.scripts.tahoe_run``.
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from six.moves import (
|
||||
from io import (
|
||||
StringIO,
|
||||
)
|
||||
|
||||
|
@ -2,9 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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_text
|
||||
|
||||
import os
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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
|
||||
|
||||
__all__ = [
|
||||
"CLINodeAPI",
|
||||
"Expect",
|
||||
|
@ -1427,7 +1427,4 @@ class TrialTestCase(_TrialTestCase):
|
||||
you try to turn that Exception instance into a string.
|
||||
"""
|
||||
|
||||
if six.PY2:
|
||||
if isinstance(msg, six.text_type):
|
||||
return super(TrialTestCase, self).fail(msg.encode("utf8"))
|
||||
return super(TrialTestCase, self).fail(msg)
|
||||
|
@ -2,11 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from future.utils import PY2, PY3, bchr, binary_type
|
||||
from future.builtins import str as future_str
|
||||
if PY2:
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, dict, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
@ -15,8 +10,6 @@ from functools import (
|
||||
partial,
|
||||
)
|
||||
from random import randrange
|
||||
if PY2:
|
||||
from StringIO import StringIO
|
||||
from io import (
|
||||
TextIOWrapper,
|
||||
BytesIO,
|
||||
@ -30,6 +23,9 @@ from ..util.assertutil import precondition
|
||||
from ..scripts import runner
|
||||
from allmydata.util.encodingutil import unicode_platform, get_filesystem_encoding, argv_type, unicode_to_argv
|
||||
|
||||
def bchr(s):
|
||||
return bytes([s])
|
||||
|
||||
|
||||
def skip_if_cannot_represent_filename(u):
|
||||
precondition(isinstance(u, str))
|
||||
@ -68,13 +64,13 @@ def run_cli_native(verb, *args, **kwargs):
|
||||
:param runner.Options options: The options instance to use to parse the
|
||||
given arguments.
|
||||
|
||||
:param native_str verb: The command to run. For example,
|
||||
:param str verb: The command to run. For example,
|
||||
``"create-node"``.
|
||||
|
||||
:param [native_str] args: The arguments to pass to the command. For
|
||||
:param [str] args: The arguments to pass to the command. For
|
||||
example, ``("--hostname=localhost",)``.
|
||||
|
||||
:param [native_str] nodeargs: Extra arguments to pass to the Tahoe
|
||||
:param [str] nodeargs: Extra arguments to pass to the Tahoe
|
||||
executable before ``verb``.
|
||||
|
||||
:param bytes|unicode stdin: Text or bytes to pass to the command via stdin.
|
||||
@ -103,22 +99,7 @@ def run_cli_native(verb, *args, **kwargs):
|
||||
)
|
||||
argv = ["tahoe"] + nodeargs + [verb] + list(args)
|
||||
stdin = kwargs.get("stdin", "")
|
||||
if PY2:
|
||||
# The original behavior, the Python 2 behavior, is to accept either
|
||||
# bytes or unicode and try to automatically encode or decode as
|
||||
# necessary. This works okay for ASCII and if LANG is set
|
||||
# appropriately. These aren't great constraints so we should move
|
||||
# away from this behavior.
|
||||
#
|
||||
# The encoding attribute doesn't change StringIO behavior on Python 2,
|
||||
# but it's there for realism of the emulation.
|
||||
stdin = StringIO(stdin)
|
||||
stdin.encoding = encoding
|
||||
stdout = StringIO()
|
||||
stdout.encoding = encoding
|
||||
stderr = StringIO()
|
||||
stderr.encoding = encoding
|
||||
else:
|
||||
if True:
|
||||
# The new behavior, the Python 3 behavior, is to accept unicode and
|
||||
# encode it using a specific encoding. For older versions of Python 3,
|
||||
# the encoding is determined from LANG (bad) but for newer Python 3,
|
||||
@ -148,13 +129,13 @@ def run_cli_native(verb, *args, **kwargs):
|
||||
stderr=stderr,
|
||||
)
|
||||
def _done(rc, stdout=stdout, stderr=stderr):
|
||||
if return_bytes and PY3:
|
||||
if return_bytes:
|
||||
stdout = stdout.buffer
|
||||
stderr = stderr.buffer
|
||||
return 0, _getvalue(stdout), _getvalue(stderr)
|
||||
def _err(f, stdout=stdout, stderr=stderr):
|
||||
f.trap(SystemExit)
|
||||
if return_bytes and PY3:
|
||||
if return_bytes:
|
||||
stdout = stdout.buffer
|
||||
stderr = stderr.buffer
|
||||
return f.value.code, _getvalue(stdout), _getvalue(stderr)
|
||||
@ -184,18 +165,14 @@ def run_cli_unicode(verb, argv, nodeargs=None, stdin=None, encoding=None):
|
||||
if nodeargs is None:
|
||||
nodeargs = []
|
||||
precondition(
|
||||
all(isinstance(arg, future_str) for arg in [verb] + nodeargs + argv),
|
||||
all(isinstance(arg, str) for arg in [verb] + nodeargs + argv),
|
||||
"arguments to run_cli_unicode must be unicode",
|
||||
verb=verb,
|
||||
nodeargs=nodeargs,
|
||||
argv=argv,
|
||||
)
|
||||
codec = encoding or "ascii"
|
||||
if PY2:
|
||||
encode = lambda t: None if t is None else t.encode(codec)
|
||||
else:
|
||||
# On Python 3 command-line parsing expects Unicode!
|
||||
encode = lambda t: t
|
||||
encode = lambda t: t
|
||||
d = run_cli_native(
|
||||
encode(verb),
|
||||
nodeargs=list(encode(arg) for arg in nodeargs),
|
||||
@ -240,7 +217,7 @@ def flip_bit(good, which):
|
||||
def flip_one_bit(s, offset=0, size=None):
|
||||
""" flip one random bit of the string s, in a byte greater than or equal to offset and less
|
||||
than offset+size. """
|
||||
precondition(isinstance(s, binary_type))
|
||||
precondition(isinstance(s, bytes))
|
||||
if size is None:
|
||||
size=len(s)-offset
|
||||
i = randrange(offset, offset+size)
|
||||
@ -252,13 +229,9 @@ def flip_one_bit(s, offset=0, size=None):
|
||||
class ReallyEqualMixin(object):
|
||||
def failUnlessReallyEqual(self, a, b, msg=None):
|
||||
self.assertEqual(a, b, msg)
|
||||
# Make sure unicode strings are a consistent type. Specifically there's
|
||||
# Future newstr (backported Unicode type) vs. Python 2 native unicode
|
||||
# type. They're equal, and _logically_ the same type, but have
|
||||
# different types in practice.
|
||||
if a.__class__ == future_str:
|
||||
if a.__class__ == str:
|
||||
a = str(a)
|
||||
if b.__class__ == future_str:
|
||||
if b.__class__ == str:
|
||||
b = str(b)
|
||||
self.assertEqual(type(a), type(b), "a :: %r (%s), b :: %r (%s), %r" % (a, type(a), b, type(b), msg))
|
||||
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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
|
||||
|
||||
__all__ = [
|
||||
|
@ -4,10 +4,6 @@ Testtools-style matchers useful to the Tahoe-LAFS test suite.
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 attr
|
||||
from hyperlink import DecodedURL
|
||||
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 ..common import AsyncTestCase
|
||||
from foolscap.api import flushEventualQueue
|
||||
from allmydata.monitor import Monitor
|
||||
|
@ -2,10 +2,6 @@
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
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 ..common import SyncTestCase
|
||||
from allmydata.mutable.publish import MutableData
|
||||
from testtools.matchers import Equals, HasLength
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user