Merge pull request #1052 from tahoe-lafs/3692.cli-tests-python-3

Finish porting CLI tests to Python 3

Fixes ticket:3692
This commit is contained in:
Itamar Turner-Trauring 2021-05-05 09:36:25 -04:00 committed by GitHub
commit 73726a99a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 248 additions and 211 deletions

0
newsfragments/3692.minor Normal file
View File

View File

@ -1,6 +1,7 @@
from __future__ import print_function
from past.builtins import unicode
from six import ensure_binary
try:
from allmydata.scripts.types_ import SubCommands
@ -49,8 +50,8 @@ def derive_pubkey(options):
out = options.stdout
from allmydata.crypto import ed25519
privkey_vs = options.privkey
private_key, public_key = ed25519.signing_keypair_from_string(
privkey_vs.encode("ascii"))
privkey_vs = ensure_binary(privkey_vs)
private_key, public_key = ed25519.signing_keypair_from_string(privkey_vs)
print("private:", unicode(ed25519.string_from_signing_key(private_key), "ascii"), file=out)
print("public:", unicode(ed25519.string_from_verifying_key(public_key), "ascii"), file=out)
return 0

View File

@ -1,5 +1,7 @@
from __future__ import print_function
from past.builtins import unicode
import os.path, re, fnmatch
try:
@ -36,7 +38,7 @@ class FileStoreOptions(BaseOptions):
# compute a node-url from the existing options, put in self['node-url']
if self['node-url']:
if (not isinstance(self['node-url'], basestring)
if (not isinstance(self['node-url'], (bytes, unicode))
or not NODEURL_RE.match(self['node-url'])):
msg = ("--node-url is required to be a string and look like "
"\"http://HOSTNAMEORADDR:PORT\", not: %r" %

View File

@ -452,7 +452,7 @@ def dump_cap(options):
from allmydata import uri
from allmydata.util import base32
from base64 import b32decode
import urlparse, urllib
from urllib.parse import unquote, urlparse
out = options.stdout
cap = options.cap
@ -461,18 +461,18 @@ def dump_cap(options):
nodeid = b32decode(options['nodeid'].upper())
secret = None
if options['client-secret']:
secret = base32.a2b(options['client-secret'])
secret = base32.a2b(options['client-secret'].encode("ascii"))
elif options['client-dir']:
secretfile = os.path.join(options['client-dir'], "private", "secret")
try:
secret = base32.a2b(open(secretfile, "r").read().strip())
secret = base32.a2b(open(secretfile, "rb").read().strip())
except EnvironmentError:
pass
if cap.startswith("http"):
scheme, netloc, path, params, query, fragment = urlparse.urlparse(cap)
scheme, netloc, path, params, query, fragment = urlparse(cap)
assert path.startswith("/uri/")
cap = urllib.unquote(path[len("/uri/"):])
cap = unquote(path[len("/uri/"):])
u = uri.from_string(cap)
@ -485,19 +485,19 @@ def _dump_secrets(storage_index, secret, nodeid, out):
if secret:
crs = hashutil.my_renewal_secret_hash(secret)
print(" client renewal secret:", base32.b2a(crs), file=out)
print(" client renewal secret:", unicode(base32.b2a(crs), "ascii"), file=out)
frs = hashutil.file_renewal_secret_hash(crs, storage_index)
print(" file renewal secret:", base32.b2a(frs), file=out)
print(" file renewal secret:", unicode(base32.b2a(frs), "ascii"), file=out)
if nodeid:
renew = hashutil.bucket_renewal_secret_hash(frs, nodeid)
print(" lease renewal secret:", base32.b2a(renew), file=out)
print(" lease renewal secret:", unicode(base32.b2a(renew), "ascii"), file=out)
ccs = hashutil.my_cancel_secret_hash(secret)
print(" client cancel secret:", base32.b2a(ccs), file=out)
print(" client cancel secret:", unicode(base32.b2a(ccs), "ascii"), file=out)
fcs = hashutil.file_cancel_secret_hash(ccs, storage_index)
print(" file cancel secret:", base32.b2a(fcs), file=out)
print(" file cancel secret:", unicode(base32.b2a(fcs), "ascii"), file=out)
if nodeid:
cancel = hashutil.bucket_cancel_secret_hash(fcs, nodeid)
print(" lease cancel secret:", base32.b2a(cancel), file=out)
print(" lease cancel secret:", unicode(base32.b2a(cancel), "ascii"), file=out)
def dump_uri_instance(u, nodeid, secret, out, show_header=True):
from allmydata import uri
@ -508,19 +508,19 @@ def dump_uri_instance(u, nodeid, secret, out, show_header=True):
if isinstance(u, uri.CHKFileURI):
if show_header:
print("CHK File:", file=out)
print(" key:", base32.b2a(u.key), file=out)
print(" UEB hash:", base32.b2a(u.uri_extension_hash), file=out)
print(" key:", unicode(base32.b2a(u.key), "ascii"), file=out)
print(" UEB hash:", unicode(base32.b2a(u.uri_extension_hash), "ascii"), file=out)
print(" size:", u.size, file=out)
print(" k/N: %d/%d" % (u.needed_shares, u.total_shares), file=out)
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
print(" storage index:", unicode(si_b2a(u.get_storage_index()), "ascii"), file=out)
_dump_secrets(u.get_storage_index(), secret, nodeid, out)
elif isinstance(u, uri.CHKFileVerifierURI):
if show_header:
print("CHK Verifier URI:", file=out)
print(" UEB hash:", base32.b2a(u.uri_extension_hash), file=out)
print(" UEB hash:", unicode(base32.b2a(u.uri_extension_hash), "ascii"), file=out)
print(" size:", u.size, file=out)
print(" k/N: %d/%d" % (u.needed_shares, u.total_shares), file=out)
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
print(" storage index:", unicode(si_b2a(u.get_storage_index()), "ascii"), file=out)
elif isinstance(u, uri.LiteralFileURI):
if show_header:
@ -530,52 +530,52 @@ def dump_uri_instance(u, nodeid, secret, out, show_header=True):
elif isinstance(u, uri.WriteableSSKFileURI): # SDMF
if show_header:
print("SDMF Writeable URI:", file=out)
print(" writekey:", base32.b2a(u.writekey), file=out)
print(" readkey:", base32.b2a(u.readkey), file=out)
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
print(" fingerprint:", base32.b2a(u.fingerprint), file=out)
print(" writekey:", unicode(base32.b2a(u.writekey), "ascii"), file=out)
print(" readkey:", unicode(base32.b2a(u.readkey), "ascii"), file=out)
print(" storage index:", unicode(si_b2a(u.get_storage_index()), "ascii"), file=out)
print(" fingerprint:", unicode(base32.b2a(u.fingerprint), "ascii"), file=out)
print(file=out)
if nodeid:
we = hashutil.ssk_write_enabler_hash(u.writekey, nodeid)
print(" write_enabler:", base32.b2a(we), file=out)
print(" write_enabler:", unicode(base32.b2a(we), "ascii"), file=out)
print(file=out)
_dump_secrets(u.get_storage_index(), secret, nodeid, out)
elif isinstance(u, uri.ReadonlySSKFileURI):
if show_header:
print("SDMF Read-only URI:", file=out)
print(" readkey:", base32.b2a(u.readkey), file=out)
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
print(" fingerprint:", base32.b2a(u.fingerprint), file=out)
print(" readkey:", unicode(base32.b2a(u.readkey), "ascii"), file=out)
print(" storage index:", unicode(si_b2a(u.get_storage_index()), "ascii"), file=out)
print(" fingerprint:", unicode(base32.b2a(u.fingerprint), "ascii"), file=out)
elif isinstance(u, uri.SSKVerifierURI):
if show_header:
print("SDMF Verifier URI:", file=out)
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
print(" fingerprint:", base32.b2a(u.fingerprint), file=out)
print(" storage index:", unicode(si_b2a(u.get_storage_index()), "ascii"), file=out)
print(" fingerprint:", unicode(base32.b2a(u.fingerprint), "ascii"), file=out)
elif isinstance(u, uri.WriteableMDMFFileURI): # MDMF
if show_header:
print("MDMF Writeable URI:", file=out)
print(" writekey:", base32.b2a(u.writekey), file=out)
print(" readkey:", base32.b2a(u.readkey), file=out)
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
print(" fingerprint:", base32.b2a(u.fingerprint), file=out)
print(" writekey:", unicode(base32.b2a(u.writekey), "ascii"), file=out)
print(" readkey:", unicode(base32.b2a(u.readkey), "ascii"), file=out)
print(" storage index:", unicode(si_b2a(u.get_storage_index()), "ascii"), file=out)
print(" fingerprint:", unicode(base32.b2a(u.fingerprint), "ascii"), file=out)
print(file=out)
if nodeid:
we = hashutil.ssk_write_enabler_hash(u.writekey, nodeid)
print(" write_enabler:", base32.b2a(we), file=out)
print(" write_enabler:", unicode(base32.b2a(we), "ascii"), file=out)
print(file=out)
_dump_secrets(u.get_storage_index(), secret, nodeid, out)
elif isinstance(u, uri.ReadonlyMDMFFileURI):
if show_header:
print("MDMF Read-only URI:", file=out)
print(" readkey:", base32.b2a(u.readkey), file=out)
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
print(" fingerprint:", base32.b2a(u.fingerprint), file=out)
print(" readkey:", unicode(base32.b2a(u.readkey), "ascii"), file=out)
print(" storage index:", unicode(si_b2a(u.get_storage_index()), "ascii"), file=out)
print(" fingerprint:", unicode(base32.b2a(u.fingerprint), "ascii"), file=out)
elif isinstance(u, uri.MDMFVerifierURI):
if show_header:
print("MDMF Verifier URI:", file=out)
print(" storage index:", si_b2a(u.get_storage_index()), file=out)
print(" fingerprint:", base32.b2a(u.fingerprint), file=out)
print(" storage index:", unicode(si_b2a(u.get_storage_index()), "ascii"), file=out)
print(" fingerprint:", unicode(base32.b2a(u.fingerprint), "ascii"), file=out)
elif isinstance(u, uri.ImmutableDirectoryURI): # CHK-based directory

View File

@ -1,5 +1,6 @@
from __future__ import print_function
from future.utils import PY3
from past.builtins import unicode
from six import ensure_str
@ -78,8 +79,13 @@ class SlowOperationRunner(object):
if not data["finished"]:
return False
if self.options.get("raw"):
if PY3:
# need to write bytes!
stdout = stdout.buffer
if is_printable_ascii(jdata):
print(jdata, file=stdout)
stdout.write(jdata)
stdout.write(b"\n")
stdout.flush()
else:
print("The JSON response contained unprintable characters:\n%s" % quote_output(jdata), file=stderr)
return True

View File

@ -5,7 +5,8 @@ from past.builtins import unicode
import os.path
from urllib.parse import quote as url_quote
from collections import defaultdict
from six.moves import cStringIO as StringIO
from io import BytesIO
from twisted.python.failure import Failure
from allmydata.scripts.common import get_alias, escape_path, \
DefaultAliasMarker, TahoeError
@ -200,13 +201,21 @@ class TahoeFileSource(object):
def open(self, caps_only):
if caps_only:
return StringIO(self.readcap)
return BytesIO(self.readcap)
url = self.nodeurl + "uri/" + url_quote(self.readcap)
return GET_to_file(url)
def bestcap(self):
return self.writecap or self.readcap
def seekable(file_like):
"""Return whether the file-like object is seekable."""
return hasattr(file_like, "seek") and (
not hasattr(file_like, "seekable") or file_like.seekable()
)
class TahoeFileTarget(object):
def __init__(self, nodeurl, mutable, writecap, readcap, url):
self.nodeurl = nodeurl
@ -220,7 +229,7 @@ class TahoeFileTarget(object):
assert self.url
# our do_http() call currently requires a string or a filehandle with
# a real .seek
if not hasattr(inf, "seek"):
if not seekable(inf):
inf = inf.read()
PUT(self.url, inf)
# TODO: this always creates immutable files. We might want an option
@ -306,7 +315,7 @@ class TahoeMissingTarget(object):
def put_file(self, inf):
# We want to replace this object in-place.
if not hasattr(inf, "seek"):
if not seekable(inf):
inf = inf.read()
PUT(self.url, inf)
# TODO: this always creates immutable files. We might want an option
@ -417,7 +426,7 @@ class TahoeDirectoryTarget(object):
def put_file(self, name, inf):
precondition(isinstance(name, unicode), name)
url = self.nodeurl + "uri"
if not hasattr(inf, "seek"):
if not seekable(inf):
inf = inf.read()
if self.children is None:

View File

@ -1,5 +1,6 @@
from __future__ import print_function
from future.utils import PY3
from past.builtins import unicode
from urllib.parse import quote as url_quote
@ -51,6 +52,9 @@ class ManifestStreamer(LineOnlyReceiver, object):
#print("RESP", dir(resp))
# use Twisted to split this into lines
self.in_error = False
# Writing bytes, so need binary stdout.
if PY3:
stdout = stdout.buffer
while True:
chunk = resp.read(100)
if not chunk:

View File

@ -1,6 +1,6 @@
from __future__ import print_function
import urllib
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, \
UnknownAliasError
@ -27,7 +27,7 @@ def unlink(options, command="unlink"):
'tahoe %s' can only unlink directory entries, so a path must be given.""" % (command,), file=stderr)
return 1
url = nodeurl + "uri/%s" % urllib.quote(rootcap)
url = nodeurl + "uri/%s" % url_quote(rootcap)
url += "/" + escape_path(path)
resp = do_http("DELETE", url)

View File

@ -1,9 +1,22 @@
from six import ensure_str
"""
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 six import ensure_str, ensure_text
from ...scripts import runner
from ..common_util import ReallyEqualMixin, run_cli, run_cli_unicode
def parse_options(basedir, command, args):
args = [ensure_text(s) for s in args]
o = runner.Options()
o.parseOptions(["--node-directory", basedir, command] + args)
while hasattr(o, "subOptions"):

View File

@ -1,10 +1,23 @@
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 six.moves import cStringIO as StringIO
from six import ensure_text, ensure_str
import os.path
from six.moves import cStringIO as StringIO
import urllib, sys
import sys
import re
from mock import patch, Mock
from urllib.parse import quote as url_quote
from twisted.trial import unittest
from twisted.python.monkey import MonkeyPatcher
@ -46,6 +59,7 @@ from allmydata.util.encodingutil import listdir_unicode, get_io_encoding
class CLI(CLITestMixin, unittest.TestCase):
def _dump_cap(self, *args):
args = [ensure_text(s) for s in args]
config = debug.DumpCapOptions()
config.stdout,config.stderr = StringIO(), StringIO()
config.parseOptions(args)
@ -55,8 +69,8 @@ class CLI(CLITestMixin, unittest.TestCase):
return output
def test_dump_cap_chk(self):
key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
uri_extension_hash = hashutil.uri_extension_hash("stuff")
key = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
uri_extension_hash = hashutil.uri_extension_hash(b"stuff")
needed_shares = 25
total_shares = 100
size = 1234
@ -77,14 +91,14 @@ class CLI(CLITestMixin, unittest.TestCase):
u.to_string())
self.failUnless("client renewal secret: znxmki5zdibb5qlt46xbdvk2t55j7hibejq3i5ijyurkr6m6jkhq" in output, output)
output = self._dump_cap(u.get_verify_cap().to_string())
output = self._dump_cap(str(u.get_verify_cap().to_string(), "ascii"))
self.failIf("key: " in output, output)
self.failUnless("UEB hash: nf3nimquen7aeqm36ekgxomalstenpkvsdmf6fplj7swdatbv5oa" in output, output)
self.failUnless("size: 1234" in output, output)
self.failUnless("k/N: 25/100" in output, output)
self.failUnless("storage index: hdis5iaveku6lnlaiccydyid7q" in output, output)
prefixed_u = "http://127.0.0.1/uri/%s" % urllib.quote(u.to_string())
prefixed_u = "http://127.0.0.1/uri/%s" % url_quote(u.to_string())
output = self._dump_cap(prefixed_u)
self.failUnless("CHK File:" in output, output)
self.failUnless("key: aaaqeayeaudaocajbifqydiob4" in output, output)
@ -94,14 +108,14 @@ class CLI(CLITestMixin, unittest.TestCase):
self.failUnless("storage index: hdis5iaveku6lnlaiccydyid7q" in output, output)
def test_dump_cap_lit(self):
u = uri.LiteralFileURI("this is some data")
u = uri.LiteralFileURI(b"this is some data")
output = self._dump_cap(u.to_string())
self.failUnless("Literal File URI:" in output, output)
self.failUnless("data: 'this is some data'" in output, output)
def test_dump_cap_sdmf(self):
writekey = "\x01" * 16
fingerprint = "\xfe" * 32
writekey = b"\x01" * 16
fingerprint = b"\xfe" * 32
u = uri.WriteableSSKFileURI(writekey, fingerprint)
output = self._dump_cap(u.to_string())
@ -151,8 +165,8 @@ class CLI(CLITestMixin, unittest.TestCase):
self.failUnless("fingerprint: 737p57x6737p57x6737p57x6737p57x6737p57x6737p57x6737a" in output, output)
def test_dump_cap_mdmf(self):
writekey = "\x01" * 16
fingerprint = "\xfe" * 32
writekey = b"\x01" * 16
fingerprint = b"\xfe" * 32
u = uri.WriteableMDMFFileURI(writekey, fingerprint)
output = self._dump_cap(u.to_string())
@ -203,8 +217,8 @@ class CLI(CLITestMixin, unittest.TestCase):
def test_dump_cap_chk_directory(self):
key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
uri_extension_hash = hashutil.uri_extension_hash("stuff")
key = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
uri_extension_hash = hashutil.uri_extension_hash(b"stuff")
needed_shares = 25
total_shares = 100
size = 1234
@ -237,8 +251,8 @@ class CLI(CLITestMixin, unittest.TestCase):
self.failUnless("storage index: hdis5iaveku6lnlaiccydyid7q" in output, output)
def test_dump_cap_sdmf_directory(self):
writekey = "\x01" * 16
fingerprint = "\xfe" * 32
writekey = b"\x01" * 16
fingerprint = b"\xfe" * 32
u1 = uri.WriteableSSKFileURI(writekey, fingerprint)
u = uri.DirectoryURI(u1)
@ -281,8 +295,8 @@ class CLI(CLITestMixin, unittest.TestCase):
self.failUnless("fingerprint: 737p57x6737p57x6737p57x6737p57x6737p57x6737p57x6737a" in output, output)
def test_dump_cap_mdmf_directory(self):
writekey = "\x01" * 16
fingerprint = "\xfe" * 32
writekey = b"\x01" * 16
fingerprint = b"\xfe" * 32
u1 = uri.WriteableMDMFFileURI(writekey, fingerprint)
u = uri.MDMFDirectoryURI(u1)
@ -342,7 +356,7 @@ class CLI(CLITestMixin, unittest.TestCase):
fileutil.write("cli/test_catalog_shares/node1/storage/shares/mq/not-a-dir", "")
# write a bogus share that looks a little bit like CHK
fileutil.write(os.path.join(sharedir, "8"),
"\x00\x00\x00\x01" + "\xff" * 200) # this triggers an assert
b"\x00\x00\x00\x01" + b"\xff" * 200) # this triggers an assert
nodedir2 = "cli/test_catalog_shares/node2"
fileutil.make_dirs(nodedir2)
@ -350,7 +364,7 @@ class CLI(CLITestMixin, unittest.TestCase):
# now make sure that the 'catalog-shares' commands survives the error
out, err = self._catalog_shares(nodedir1, nodedir2)
self.failUnlessReallyEqual(out, "", out)
self.assertEqual(out, "")
self.failUnless("Error processing " in err,
"didn't see 'error processing' in '%s'" % err)
#self.failUnless(nodedir1 in err,
@ -374,60 +388,60 @@ class CLI(CLITestMixin, unittest.TestCase):
def ga1(path):
return get_alias(aliases, path, u"tahoe")
uses_lettercolon = common.platform_uses_lettercolon_drivename()
self.failUnlessReallyEqual(ga1(u"bare"), (TA, "bare"))
self.failUnlessReallyEqual(ga1(u"baredir/file"), (TA, "baredir/file"))
self.failUnlessReallyEqual(ga1(u"baredir/file:7"), (TA, "baredir/file:7"))
self.failUnlessReallyEqual(ga1(u"tahoe:"), (TA, ""))
self.failUnlessReallyEqual(ga1(u"tahoe:file"), (TA, "file"))
self.failUnlessReallyEqual(ga1(u"tahoe:dir/file"), (TA, "dir/file"))
self.failUnlessReallyEqual(ga1(u"work:"), (WA, ""))
self.failUnlessReallyEqual(ga1(u"work:file"), (WA, "file"))
self.failUnlessReallyEqual(ga1(u"work:dir/file"), (WA, "dir/file"))
self.failUnlessReallyEqual(ga1(u"bare"), (TA, b"bare"))
self.failUnlessReallyEqual(ga1(u"baredir/file"), (TA, b"baredir/file"))
self.failUnlessReallyEqual(ga1(u"baredir/file:7"), (TA, b"baredir/file:7"))
self.failUnlessReallyEqual(ga1(u"tahoe:"), (TA, b""))
self.failUnlessReallyEqual(ga1(u"tahoe:file"), (TA, b"file"))
self.failUnlessReallyEqual(ga1(u"tahoe:dir/file"), (TA, b"dir/file"))
self.failUnlessReallyEqual(ga1(u"work:"), (WA, b""))
self.failUnlessReallyEqual(ga1(u"work:file"), (WA, b"file"))
self.failUnlessReallyEqual(ga1(u"work:dir/file"), (WA, b"dir/file"))
# default != None means we really expect a tahoe path, regardless of
# whether we're on windows or not. This is what 'tahoe get' uses.
self.failUnlessReallyEqual(ga1(u"c:"), (CA, ""))
self.failUnlessReallyEqual(ga1(u"c:file"), (CA, "file"))
self.failUnlessReallyEqual(ga1(u"c:dir/file"), (CA, "dir/file"))
self.failUnlessReallyEqual(ga1(u"URI:stuff"), ("URI:stuff", ""))
self.failUnlessReallyEqual(ga1(u"URI:stuff/file"), ("URI:stuff", "file"))
self.failUnlessReallyEqual(ga1(u"URI:stuff:./file"), ("URI:stuff", "file"))
self.failUnlessReallyEqual(ga1(u"URI:stuff/dir/file"), ("URI:stuff", "dir/file"))
self.failUnlessReallyEqual(ga1(u"URI:stuff:./dir/file"), ("URI:stuff", "dir/file"))
self.failUnlessReallyEqual(ga1(u"c:"), (CA, b""))
self.failUnlessReallyEqual(ga1(u"c:file"), (CA, b"file"))
self.failUnlessReallyEqual(ga1(u"c:dir/file"), (CA, b"dir/file"))
self.failUnlessReallyEqual(ga1(u"URI:stuff"), (b"URI:stuff", b""))
self.failUnlessReallyEqual(ga1(u"URI:stuff/file"), (b"URI:stuff", b"file"))
self.failUnlessReallyEqual(ga1(u"URI:stuff:./file"), (b"URI:stuff", b"file"))
self.failUnlessReallyEqual(ga1(u"URI:stuff/dir/file"), (b"URI:stuff", b"dir/file"))
self.failUnlessReallyEqual(ga1(u"URI:stuff:./dir/file"), (b"URI:stuff", b"dir/file"))
self.failUnlessRaises(common.UnknownAliasError, ga1, u"missing:")
self.failUnlessRaises(common.UnknownAliasError, ga1, u"missing:dir")
self.failUnlessRaises(common.UnknownAliasError, ga1, u"missing:dir/file")
def ga2(path):
return get_alias(aliases, path, None)
self.failUnlessReallyEqual(ga2(u"bare"), (DefaultAliasMarker, "bare"))
self.failUnlessReallyEqual(ga2(u"bare"), (DefaultAliasMarker, b"bare"))
self.failUnlessReallyEqual(ga2(u"baredir/file"),
(DefaultAliasMarker, "baredir/file"))
(DefaultAliasMarker, b"baredir/file"))
self.failUnlessReallyEqual(ga2(u"baredir/file:7"),
(DefaultAliasMarker, "baredir/file:7"))
(DefaultAliasMarker, b"baredir/file:7"))
self.failUnlessReallyEqual(ga2(u"baredir/sub:1/file:7"),
(DefaultAliasMarker, "baredir/sub:1/file:7"))
self.failUnlessReallyEqual(ga2(u"tahoe:"), (TA, ""))
self.failUnlessReallyEqual(ga2(u"tahoe:file"), (TA, "file"))
self.failUnlessReallyEqual(ga2(u"tahoe:dir/file"), (TA, "dir/file"))
(DefaultAliasMarker, b"baredir/sub:1/file:7"))
self.failUnlessReallyEqual(ga2(u"tahoe:"), (TA, b""))
self.failUnlessReallyEqual(ga2(u"tahoe:file"), (TA, b"file"))
self.failUnlessReallyEqual(ga2(u"tahoe:dir/file"), (TA, b"dir/file"))
# on windows, we really want c:foo to indicate a local file.
# default==None is what 'tahoe cp' uses.
if uses_lettercolon:
self.failUnlessReallyEqual(ga2(u"c:"), (DefaultAliasMarker, "c:"))
self.failUnlessReallyEqual(ga2(u"c:file"), (DefaultAliasMarker, "c:file"))
self.failUnlessReallyEqual(ga2(u"c:"), (DefaultAliasMarker, b"c:"))
self.failUnlessReallyEqual(ga2(u"c:file"), (DefaultAliasMarker, b"c:file"))
self.failUnlessReallyEqual(ga2(u"c:dir/file"),
(DefaultAliasMarker, "c:dir/file"))
(DefaultAliasMarker, b"c:dir/file"))
else:
self.failUnlessReallyEqual(ga2(u"c:"), (CA, ""))
self.failUnlessReallyEqual(ga2(u"c:file"), (CA, "file"))
self.failUnlessReallyEqual(ga2(u"c:dir/file"), (CA, "dir/file"))
self.failUnlessReallyEqual(ga2(u"work:"), (WA, ""))
self.failUnlessReallyEqual(ga2(u"work:file"), (WA, "file"))
self.failUnlessReallyEqual(ga2(u"work:dir/file"), (WA, "dir/file"))
self.failUnlessReallyEqual(ga2(u"URI:stuff"), ("URI:stuff", ""))
self.failUnlessReallyEqual(ga2(u"URI:stuff/file"), ("URI:stuff", "file"))
self.failUnlessReallyEqual(ga2(u"URI:stuff:./file"), ("URI:stuff", "file"))
self.failUnlessReallyEqual(ga2(u"URI:stuff/dir/file"), ("URI:stuff", "dir/file"))
self.failUnlessReallyEqual(ga2(u"URI:stuff:./dir/file"), ("URI:stuff", "dir/file"))
self.failUnlessReallyEqual(ga2(u"c:"), (CA, b""))
self.failUnlessReallyEqual(ga2(u"c:file"), (CA, b"file"))
self.failUnlessReallyEqual(ga2(u"c:dir/file"), (CA, b"dir/file"))
self.failUnlessReallyEqual(ga2(u"work:"), (WA, b""))
self.failUnlessReallyEqual(ga2(u"work:file"), (WA, b"file"))
self.failUnlessReallyEqual(ga2(u"work:dir/file"), (WA, b"dir/file"))
self.failUnlessReallyEqual(ga2(u"URI:stuff"), (b"URI:stuff", b""))
self.failUnlessReallyEqual(ga2(u"URI:stuff/file"), (b"URI:stuff", b"file"))
self.failUnlessReallyEqual(ga2(u"URI:stuff:./file"), (b"URI:stuff", b"file"))
self.failUnlessReallyEqual(ga2(u"URI:stuff/dir/file"), (b"URI:stuff", b"dir/file"))
self.failUnlessReallyEqual(ga2(u"URI:stuff:./dir/file"), (b"URI:stuff", b"dir/file"))
self.failUnlessRaises(common.UnknownAliasError, ga2, u"missing:")
self.failUnlessRaises(common.UnknownAliasError, ga2, u"missing:dir")
self.failUnlessRaises(common.UnknownAliasError, ga2, u"missing:dir/file")
@ -440,26 +454,26 @@ class CLI(CLITestMixin, unittest.TestCase):
finally:
common.pretend_platform_uses_lettercolon = old
return retval
self.failUnlessReallyEqual(ga3(u"bare"), (DefaultAliasMarker, "bare"))
self.failUnlessReallyEqual(ga3(u"bare"), (DefaultAliasMarker, b"bare"))
self.failUnlessReallyEqual(ga3(u"baredir/file"),
(DefaultAliasMarker, "baredir/file"))
(DefaultAliasMarker, b"baredir/file"))
self.failUnlessReallyEqual(ga3(u"baredir/file:7"),
(DefaultAliasMarker, "baredir/file:7"))
(DefaultAliasMarker, b"baredir/file:7"))
self.failUnlessReallyEqual(ga3(u"baredir/sub:1/file:7"),
(DefaultAliasMarker, "baredir/sub:1/file:7"))
self.failUnlessReallyEqual(ga3(u"tahoe:"), (TA, ""))
self.failUnlessReallyEqual(ga3(u"tahoe:file"), (TA, "file"))
self.failUnlessReallyEqual(ga3(u"tahoe:dir/file"), (TA, "dir/file"))
self.failUnlessReallyEqual(ga3(u"c:"), (DefaultAliasMarker, "c:"))
self.failUnlessReallyEqual(ga3(u"c:file"), (DefaultAliasMarker, "c:file"))
(DefaultAliasMarker, b"baredir/sub:1/file:7"))
self.failUnlessReallyEqual(ga3(u"tahoe:"), (TA, b""))
self.failUnlessReallyEqual(ga3(u"tahoe:file"), (TA, b"file"))
self.failUnlessReallyEqual(ga3(u"tahoe:dir/file"), (TA, b"dir/file"))
self.failUnlessReallyEqual(ga3(u"c:"), (DefaultAliasMarker, b"c:"))
self.failUnlessReallyEqual(ga3(u"c:file"), (DefaultAliasMarker, b"c:file"))
self.failUnlessReallyEqual(ga3(u"c:dir/file"),
(DefaultAliasMarker, "c:dir/file"))
self.failUnlessReallyEqual(ga3(u"work:"), (WA, ""))
self.failUnlessReallyEqual(ga3(u"work:file"), (WA, "file"))
self.failUnlessReallyEqual(ga3(u"work:dir/file"), (WA, "dir/file"))
self.failUnlessReallyEqual(ga3(u"URI:stuff"), ("URI:stuff", ""))
self.failUnlessReallyEqual(ga3(u"URI:stuff:./file"), ("URI:stuff", "file"))
self.failUnlessReallyEqual(ga3(u"URI:stuff:./dir/file"), ("URI:stuff", "dir/file"))
(DefaultAliasMarker, b"c:dir/file"))
self.failUnlessReallyEqual(ga3(u"work:"), (WA, b""))
self.failUnlessReallyEqual(ga3(u"work:file"), (WA, b"file"))
self.failUnlessReallyEqual(ga3(u"work:dir/file"), (WA, b"dir/file"))
self.failUnlessReallyEqual(ga3(u"URI:stuff"), (b"URI:stuff", b""))
self.failUnlessReallyEqual(ga3(u"URI:stuff:./file"), (b"URI:stuff", b"file"))
self.failUnlessReallyEqual(ga3(u"URI:stuff:./dir/file"), (b"URI:stuff", b"dir/file"))
self.failUnlessRaises(common.UnknownAliasError, ga3, u"missing:")
self.failUnlessRaises(common.UnknownAliasError, ga3, u"missing:dir")
self.failUnlessRaises(common.UnknownAliasError, ga3, u"missing:dir/file")
@ -482,14 +496,14 @@ class CLI(CLITestMixin, unittest.TestCase):
self.failUnlessRaises(common.UnknownAliasError, ga5, u"C:\\Windows")
def test_alias_tolerance(self):
def s128(c): return base32.b2a(c*(128/8))
def s256(c): return base32.b2a(c*(256/8))
TA = "URI:DIR2:%s:%s" % (s128("T"), s256("T"))
def s128(c): return base32.b2a(c*(128//8))
def s256(c): return base32.b2a(c*(256//8))
TA = b"URI:DIR2:%s:%s" % (s128(b"T"), s256(b"T"))
aliases = {"present": TA,
"future": "URI-FROM-FUTURE:ooh:aah"}
"future": b"URI-FROM-FUTURE:ooh:aah"}
def ga1(path):
return get_alias(aliases, path, u"tahoe")
self.failUnlessReallyEqual(ga1(u"present:file"), (TA, "file"))
self.failUnlessReallyEqual(ga1(u"present:file"), (TA, b"file"))
# this throws, via assert IDirnodeURI.providedBy(), since get_alias()
# wants a dirnode, and the future cap gives us UnknownURI instead.
self.failUnlessRaises(AssertionError, ga1, u"future:stuff")
@ -504,9 +518,9 @@ class CLI(CLITestMixin, unittest.TestCase):
fileutil.make_dirs(basedir)
for name in filenames:
open(os.path.join(unicode(basedir), name), "wb").close()
open(os.path.join(str(basedir), name), "wb").close()
for file in listdir_unicode(unicode(basedir)):
for file in listdir_unicode(str(basedir)):
self.failUnlessIn(normalize(file), filenames)
def test_exception_catcher(self):
@ -673,7 +687,7 @@ class Ln(GridTestMixin, CLITestMixin, unittest.TestCase):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("error:", err)
self.failUnlessReallyEqual(out, "")
self.assertEqual(out, "")
d.addCallback(_check)
# Make sure that validation extends to the "to" parameter
d.addCallback(lambda ign: self.do_cli("create-alias", "havasu"))
@ -732,8 +746,8 @@ class Admin(unittest.TestCase):
def test_derive_pubkey(self):
priv_key, pub_key = ed25519.create_signing_keypair()
priv_key_str = unicode(ed25519.string_from_signing_key(priv_key), "ascii")
pub_key_str = unicode(ed25519.string_from_verifying_key(pub_key), "ascii")
priv_key_str = str(ed25519.string_from_signing_key(priv_key), "ascii")
pub_key_str = str(ed25519.string_from_verifying_key(pub_key), "ascii")
d = run_cli("admin", "derive-pubkey", priv_key_str)
def _done(args):
(rc, stdout, stderr) = args
@ -756,11 +770,11 @@ class Errors(GridTestMixin, CLITestMixin, unittest.TestCase):
self.set_up_grid()
c0 = self.g.clients[0]
self.fileurls = {}
DATA = "data" * 100
d = c0.upload(upload.Data(DATA, convergence=""))
DATA = b"data" * 100
d = c0.upload(upload.Data(DATA, convergence=b""))
def _stash_bad(ur):
self.uri_1share = ur.get_uri()
self.delete_shares_numbered(ur.get_uri(), range(1,10))
self.delete_shares_numbered(ur.get_uri(), list(range(1,10)))
d.addCallback(_stash_bad)
# the download is abandoned as soon as it's clear that we won't get
@ -824,7 +838,7 @@ class Get(GridTestMixin, CLITestMixin, unittest.TestCase):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("error:", err)
self.failUnlessReallyEqual(out, "")
self.assertEqual(out, "")
d.addCallback(_check)
return d
@ -839,7 +853,7 @@ class Get(GridTestMixin, CLITestMixin, unittest.TestCase):
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("error:", err)
self.failUnlessIn("nonexistent", err)
self.failUnlessReallyEqual(out, "")
self.assertEqual(out, "")
d.addCallback(_check)
return d
@ -856,7 +870,7 @@ class Manifest(GridTestMixin, CLITestMixin, unittest.TestCase):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("error:", err)
self.failUnlessReallyEqual(out, "")
self.assertEqual(out, "")
d.addCallback(_check)
return d
@ -871,7 +885,7 @@ class Manifest(GridTestMixin, CLITestMixin, unittest.TestCase):
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("error:", err)
self.failUnlessIn("nonexistent", err)
self.failUnlessReallyEqual(out, "")
self.assertEqual(out, "")
d.addCallback(_check)
return d
@ -886,7 +900,7 @@ class Mkdir(GridTestMixin, CLITestMixin, unittest.TestCase):
def _check(args):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 0)
self.failUnlessReallyEqual(err, "")
self.assertEqual(err, "")
self.failUnlessIn("URI:", out)
d.addCallback(_check)
@ -899,7 +913,7 @@ class Mkdir(GridTestMixin, CLITestMixin, unittest.TestCase):
def _check(args, st):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 0)
self.failUnlessReallyEqual(err, "")
self.assertEqual(err, "")
self.failUnlessIn(st, out)
return out
@ -935,7 +949,7 @@ class Mkdir(GridTestMixin, CLITestMixin, unittest.TestCase):
def _check(args, st):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 0)
self.failUnlessReallyEqual(err, "")
self.assertEqual(err, "")
self.failUnlessIn(st, out)
return out
d.addCallback(_check, "URI:DIR2")
@ -979,7 +993,7 @@ class Mkdir(GridTestMixin, CLITestMixin, unittest.TestCase):
def _check(args):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 0)
self.failUnlessReallyEqual(err, "")
self.assertEqual(err, "")
self.failUnlessIn("URI:", out)
d.addCallback(_check)
@ -995,7 +1009,7 @@ class Mkdir(GridTestMixin, CLITestMixin, unittest.TestCase):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("error:", err)
self.failUnlessReallyEqual(out, "")
self.assertEqual(out, "")
d.addCallback(_check)
return d
@ -1019,7 +1033,7 @@ class Unlink(GridTestMixin, CLITestMixin, unittest.TestCase):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("error:", err)
self.failUnlessReallyEqual(out, "")
self.assertEqual(out, "")
d.addCallback(_check)
d.addCallback(lambda ign: self.do_cli(self.command, "afile"))
@ -1037,7 +1051,7 @@ class Unlink(GridTestMixin, CLITestMixin, unittest.TestCase):
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("error:", err)
self.failUnlessIn("nonexistent", err)
self.failUnlessReallyEqual(out, "")
self.assertEqual(out, "")
d.addCallback(_check)
d.addCallback(lambda ign: self.do_cli(self.command, "nonexistent:afile"))
@ -1063,7 +1077,7 @@ class Unlink(GridTestMixin, CLITestMixin, unittest.TestCase):
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("'tahoe %s'" % (self.command,), err)
self.failUnlessIn("path must be given", err)
self.failUnlessReallyEqual(out, "")
self.assertEqual(out, "")
d.addCallback(_check)
return d
@ -1084,7 +1098,7 @@ class Stats(GridTestMixin, CLITestMixin, unittest.TestCase):
d.addCallback(lambda ign: self.do_cli("stats", self.rooturi))
def _check_stats(args):
(rc, out, err) = args
self.failUnlessReallyEqual(err, "")
self.assertEqual(err, "")
self.failUnlessReallyEqual(rc, 0)
lines = out.splitlines()
self.failUnlessIn(" count-immutable-files: 0", lines)
@ -1108,7 +1122,7 @@ class Stats(GridTestMixin, CLITestMixin, unittest.TestCase):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("error:", err)
self.failUnlessReallyEqual(out, "")
self.assertEqual(out, "")
d.addCallback(_check)
return d
@ -1122,7 +1136,7 @@ class Stats(GridTestMixin, CLITestMixin, unittest.TestCase):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("error:", err)
self.failUnlessReallyEqual(out, "")
self.assertEqual(out, "")
d.addCallback(_check)
return d
@ -1139,7 +1153,7 @@ class Webopen(GridTestMixin, CLITestMixin, unittest.TestCase):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 1)
self.failUnlessIn("error:", err)
self.failUnlessReallyEqual(out, "")
self.assertEqual(out, "")
d.addCallback(_check)
return d
@ -1147,7 +1161,7 @@ class Webopen(GridTestMixin, CLITestMixin, unittest.TestCase):
# TODO: replace with @patch that supports Deferreds.
import webbrowser
def call_webbrowser_open(url):
self.failUnlessIn(self.alias_uri.replace(':', '%3A'), url)
self.failUnlessIn(str(self.alias_uri, "ascii").replace(':', '%3A'), url)
self.webbrowser_open_called = True
def _cleanup(res):
webbrowser.open = self.old_webbrowser_open
@ -1164,15 +1178,15 @@ class Webopen(GridTestMixin, CLITestMixin, unittest.TestCase):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 0, repr((rc, out, err)))
self.failUnlessIn("Alias 'alias' created", out)
self.failUnlessReallyEqual(err, "")
self.assertEqual(err, "")
self.alias_uri = get_aliases(self.get_clientdir())["alias"]
d.addCallback(_check_alias)
d.addCallback(lambda res: self.do_cli("webopen", "alias:"))
def _check_webopen(args):
(rc, out, err) = args
self.failUnlessReallyEqual(rc, 0, repr((rc, out, err)))
self.failUnlessReallyEqual(out, "")
self.failUnlessReallyEqual(err, "")
self.assertEqual(out, "")
self.assertEqual(err, "")
self.failUnless(self.webbrowser_open_called)
d.addCallback(_check_webopen)
d.addBoth(_cleanup)
@ -1198,31 +1212,31 @@ class Options(ReallyEqualMixin, unittest.TestCase):
fileutil.make_dirs("cli/test_options")
fileutil.make_dirs("cli/test_options/private")
fileutil.write("cli/test_options/node.url", "http://localhost:8080/\n")
filenode_uri = uri.WriteableSSKFileURI(writekey="\x00"*16,
fingerprint="\x00"*32)
filenode_uri = uri.WriteableSSKFileURI(writekey=b"\x00"*16,
fingerprint=b"\x00"*32)
private_uri = uri.DirectoryURI(filenode_uri).to_string()
fileutil.write("cli/test_options/private/root_dir.cap", private_uri + "\n")
fileutil.write("cli/test_options/private/root_dir.cap", private_uri + b"\n")
def parse2(args): return parse_options("cli/test_options", "ls", args)
o = parse2([])
self.failUnlessEqual(o['node-url'], "http://localhost:8080/")
self.failUnlessEqual(o.aliases[DEFAULT_ALIAS], private_uri)
self.failUnlessEqual(o.aliases[DEFAULT_ALIAS].encode("ascii"), private_uri)
self.failUnlessEqual(o.where, u"")
o = parse2(["--node-url", "http://example.org:8111/"])
self.failUnlessEqual(o['node-url'], "http://example.org:8111/")
self.failUnlessEqual(o.aliases[DEFAULT_ALIAS], private_uri)
self.failUnlessEqual(o.aliases[DEFAULT_ALIAS].encode("ascii"), private_uri)
self.failUnlessEqual(o.where, u"")
# -u for --node-url used to clash with -u for --uri (tickets #1949 and #2137).
o = parse2(["-u", "http://example.org:8111/"])
self.failUnlessEqual(o['node-url'], "http://example.org:8111/")
self.failUnlessEqual(o.aliases[DEFAULT_ALIAS], private_uri)
self.failUnlessEqual(o.aliases[DEFAULT_ALIAS].encode("ascii"), private_uri)
self.failUnlessEqual(o.where, u"")
self.failIf(o["uri"])
o = parse2(["-u", "http://example.org:8111/", "--uri"])
self.failUnlessEqual(o['node-url'], "http://example.org:8111/")
self.failUnlessEqual(o.aliases[DEFAULT_ALIAS], private_uri)
self.failUnlessEqual(o.aliases[DEFAULT_ALIAS].encode("ascii"), private_uri)
self.failUnlessEqual(o.where, u"")
self.failUnless(o["uri"])
@ -1231,17 +1245,17 @@ class Options(ReallyEqualMixin, unittest.TestCase):
self.failUnlessEqual(o.aliases[DEFAULT_ALIAS], "root")
self.failUnlessEqual(o.where, u"")
other_filenode_uri = uri.WriteableSSKFileURI(writekey="\x11"*16,
fingerprint="\x11"*32)
other_filenode_uri = uri.WriteableSSKFileURI(writekey=b"\x11"*16,
fingerprint=b"\x11"*32)
other_uri = uri.DirectoryURI(other_filenode_uri).to_string()
o = parse2(["--dir-cap", other_uri])
self.failUnlessEqual(o['node-url'], "http://localhost:8080/")
self.failUnlessEqual(o.aliases[DEFAULT_ALIAS], other_uri)
self.failUnlessEqual(o.aliases[DEFAULT_ALIAS].encode("ascii"), other_uri)
self.failUnlessEqual(o.where, u"")
o = parse2(["--dir-cap", other_uri, "subdir"])
self.failUnlessEqual(o['node-url'], "http://localhost:8080/")
self.failUnlessEqual(o.aliases[DEFAULT_ALIAS], other_uri)
self.failUnlessEqual(o.aliases[DEFAULT_ALIAS].encode("ascii"), other_uri)
self.failUnlessEqual(o.where, u"subdir")
self.failUnlessRaises(usage.UsageError, parse2,
@ -1328,7 +1342,7 @@ class Run(unittest.TestCase):
If the pidfile exists but does not contain a numeric value, a complaint to
this effect is written to stderr.
"""
basedir = FilePath(self.mktemp().decode("ascii"))
basedir = FilePath(ensure_str(self.mktemp()))
basedir.makedirs()
basedir.child(u"twistd.pid").setContent(b"foo")
basedir.child(u"tahoe-client.tac").setContent(b"")
@ -1336,7 +1350,7 @@ class Run(unittest.TestCase):
config = tahoe_run.RunOptions()
config.stdout = StringIO()
config.stderr = StringIO()
config['basedir'] = basedir.path
config['basedir'] = ensure_text(basedir.path)
config.twistd_args = []
result_code = tahoe_run.run(config)

View File

@ -85,7 +85,7 @@ def run_cli_native(verb, *args, **kwargs):
bytes.
"""
nodeargs = kwargs.pop("nodeargs", [])
encoding = kwargs.pop("encoding", "utf-8")
encoding = kwargs.pop("encoding", None) or "utf-8"
return_bytes = kwargs.pop("return_bytes", False)
verb = maybe_unicode_to_argv(verb)
args = [maybe_unicode_to_argv(a) for a in args]

View File

@ -17,10 +17,10 @@ from __future__ import unicode_literals
# (Pdb) pp data
# '334:12:b\'mutable-good\',90:URI:SSK-RO:...
from past.builtins import unicode as str
from future.utils import PY3, 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, max, min # noqa: F401
from six import ensure_text
import os, json
from urllib.parse import quote as url_quote
@ -170,7 +170,8 @@ class DeepCheckBase(GridTestMixin, ErrorMixin, StallMixin, ShouldFailMixin,
return data
def parse_streamed_json(self, s):
for unit in s.split(b"\n"):
s = ensure_text(s)
for unit in s.split("\n"):
if not unit:
# stream should end with a newline, so split returns ""
continue
@ -746,8 +747,6 @@ class DeepCheckWebGood(DeepCheckBase, unittest.TestCase):
def do_test_cli_good(self, ignored):
d = defer.succeed(None)
if PY3: # TODO fixme once Python 3 CLI porting is done
return d
d.addCallback(lambda ign: self.do_cli_manifest_stream1())
d.addCallback(lambda ign: self.do_cli_manifest_stream2())
d.addCallback(lambda ign: self.do_cli_manifest_stream3())
@ -758,7 +757,7 @@ class DeepCheckWebGood(DeepCheckBase, unittest.TestCase):
return d
def _check_manifest_storage_index(self, out):
lines = [l for l in out.split(b"\n") if l]
lines = [l.encode("utf-8") for l in out.split("\n") if l]
self.failUnlessEqual(len(lines), 3)
self.failUnless(base32.b2a(self.root.get_storage_index()) in lines)
self.failUnless(base32.b2a(self.mutable.get_storage_index()) in lines)
@ -769,7 +768,7 @@ class DeepCheckWebGood(DeepCheckBase, unittest.TestCase):
def _check(args):
(rc, out, err) = args
self.failUnlessEqual(err, "")
lines = [l for l in out.split(b"\n") if l]
lines = [l for l in out.split("\n") if l]
self.failUnlessEqual(len(lines), 8)
caps = {}
for l in lines:
@ -778,7 +777,7 @@ class DeepCheckWebGood(DeepCheckBase, unittest.TestCase):
except ValueError:
cap = l.strip()
path = ""
caps[cap] = path
caps[cap.encode("ascii")] = path
self.failUnless(self.root.get_uri() in caps)
self.failUnlessEqual(caps[self.root.get_uri()], "")
self.failUnlessEqual(caps[self.mutable.get_uri()], "mutable")
@ -814,7 +813,7 @@ class DeepCheckWebGood(DeepCheckBase, unittest.TestCase):
def _check(args):
(rc, out, err) = args
self.failUnlessEqual(err, "")
lines = [l for l in out.split(b"\n") if l]
lines = [l.encode("utf-8") for l in out.split("\n") if l]
self.failUnlessEqual(len(lines), 3)
self.failUnless(self.root.get_verify_cap().to_string() in lines)
self.failUnless(self.mutable.get_verify_cap().to_string() in lines)
@ -827,7 +826,7 @@ class DeepCheckWebGood(DeepCheckBase, unittest.TestCase):
def _check(args):
(rc, out, err) = args
self.failUnlessEqual(err, "")
lines = [l for l in out.split(b"\n") if l]
lines = [l.encode("utf-8") for l in out.split("\n") if l]
self.failUnlessEqual(len(lines), 3)
self.failUnless(self.root.get_repair_cap().to_string() in lines)
self.failUnless(self.mutable.get_repair_cap().to_string() in lines)
@ -839,7 +838,7 @@ class DeepCheckWebGood(DeepCheckBase, unittest.TestCase):
d = self.do_cli("stats", self.root_uri)
def _check3(args):
(rc, out, err) = args
lines = [l.strip() for l in out.split(b"\n") if l]
lines = [l.strip() for l in out.split("\n") if l]
self.failUnless("count-immutable-files: 1" in lines)
self.failUnless("count-mutable-files: 1" in lines)
self.failUnless("count-literal-files: 3" in lines)

View File

@ -1,12 +1,12 @@
"""
Ported to Python 3, partially: test_filesystem* will be done in a future round.
Ported to Python 3.
"""
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from future.utils import PY2, PY3
from future.utils import PY2
if PY2:
# Don't import bytes since it causes issues on (so far unported) modules on Python 2.
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, dict, list, object, range, max, min, str # noqa: F401
@ -16,7 +16,6 @@ from six import ensure_text, ensure_str
import os, re, sys, time, json
from functools import partial
from unittest import skipIf
from bs4 import BeautifulSoup
@ -1665,8 +1664,6 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
d.addCallback(self.log, "did _check_publish_private")
d.addCallback(self._test_web)
d.addCallback(self._test_control)
if PY2:
# TODO when CLI is ported to Python 3, reenable.
d.addCallback(self._test_cli)
# P now has four top-level children:
# P/personal/sekrit data
@ -2298,7 +2295,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
def _check_aliases_1(out_and_err):
(out, err) = out_and_err
self.failUnlessEqual(err, "")
self.failUnlessEqual(out.strip(" \n"), "tahoe: %s" % private_uri)
self.failUnlessEqual(out.strip(" \n"), "tahoe: %s" % str(private_uri, "ascii"))
d.addCallback(_check_aliases_1)
# now that that's out of the way, remove root_dir.cap and work with
@ -2355,7 +2352,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
(out, err) = out_and_err
self.failUnlessEqual(err, "")
if filenum is not None:
self.failUnlessEqual(out, datas[filenum])
self.failUnlessEqual(out, str(datas[filenum], "ascii"))
if data is not None:
self.failUnlessEqual(out, data)
@ -2369,7 +2366,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
uri0 = out.strip()
return run(None, "get", uri0)
d.addCallback(_put_out)
d.addCallback(lambda out_err: self.failUnlessEqual(out_err[0], datas[0]))
d.addCallback(lambda out_err: self.failUnlessEqual(out_err[0], str(datas[0], "ascii")))
d.addCallback(run, "put", files[1], "subdir/tahoe-file1")
# tahoe put bar tahoe:FOO
@ -2411,14 +2408,14 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
def _check_outfile0(out_and_err):
(out, err) = out_and_err
data = open(outfile0,"rb").read()
self.failUnlessEqual(data, "data to be uploaded: file2\n")
self.failUnlessEqual(data, b"data to be uploaded: file2\n")
d.addCallback(_check_outfile0)
outfile1 = os.path.join(self.basedir, "outfile0")
d.addCallback(run, "get", "tahoe:subdir/tahoe-file1", outfile1)
def _check_outfile1(out_and_err):
(out, err) = out_and_err
data = open(outfile1,"rb").read()
self.failUnlessEqual(data, "data to be uploaded: file1\n")
self.failUnlessEqual(data, b"data to be uploaded: file1\n")
d.addCallback(_check_outfile1)
d.addCallback(run, "unlink", "tahoe-file0")
@ -2455,7 +2452,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
if "file3" in l:
rw_uri = self._mutable_file3_uri
u = uri.from_string_mutable_filenode(rw_uri)
ro_uri = u.get_readonly().to_string()
ro_uri = str(u.get_readonly().to_string(), "ascii")
self.failUnless(ro_uri in l)
d.addCallback(_check_ls_rouri)
@ -2528,17 +2525,17 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
dn = os.path.join(self.basedir, "dir1")
os.makedirs(dn)
with open(os.path.join(dn, "rfile1"), "wb") as f:
f.write("rfile1")
f.write(b"rfile1")
with open(os.path.join(dn, "rfile2"), "wb") as f:
f.write("rfile2")
f.write(b"rfile2")
with open(os.path.join(dn, "rfile3"), "wb") as f:
f.write("rfile3")
f.write(b"rfile3")
sdn2 = os.path.join(dn, "subdir2")
os.makedirs(sdn2)
with open(os.path.join(sdn2, "rfile4"), "wb") as f:
f.write("rfile4")
f.write(b"rfile4")
with open(os.path.join(sdn2, "rfile5"), "wb") as f:
f.write("rfile5")
f.write(b"rfile5")
# from disk into tahoe
d.addCallback(run, "cp", "-r", dn, "tahoe:")
@ -2582,7 +2579,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
(out, err) = out_and_err
x = open(os.path.join(dn_copy2, "dir1", "subdir2", "rfile4")).read()
y = uri.from_string_filenode(x)
self.failUnlessEqual(y.data, "rfile4")
self.failUnlessEqual(y.data, b"rfile4")
d.addCallback(_check_capsonly)
# and tahoe-to-tahoe
@ -2615,7 +2612,6 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
return d
@skipIf(PY3, "Python 3 CLI support hasn't happened yet.")
def test_filesystem_with_cli_in_subprocess(self):
# We do this in a separate test so that test_filesystem doesn't skip if we can't run bin/tahoe.
@ -2659,9 +2655,9 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
def _check_ls(res):
out, err, rc_or_sig = res
self.failUnlessEqual(rc_or_sig, 0, str(res))
self.failUnlessEqual(err, "", str(res))
self.failUnlessIn("tahoe-moved", out)
self.failIfIn("tahoe-file", out)
self.failUnlessEqual(err, b"", str(res))
self.failUnlessIn(b"tahoe-moved", out)
self.failIfIn(b"tahoe-file", out)
d.addCallback(_check_ls)
return d

View File

@ -98,6 +98,7 @@ PORTED_MODULES = [
"allmydata.storage.shares",
"allmydata.test",
"allmydata.test.cli",
"allmydata.test.cli.common",
"allmydata.test.cli_node_api",
"allmydata.test.common",
"allmydata.test.common_util",
@ -177,6 +178,7 @@ PORTED_TEST_MODULES = [
"allmydata.test.cli.test_backup",
"allmydata.test.cli.test_backupdb",
"allmydata.test.cli.test_check",
"allmydata.test.cli.test_cli",
"allmydata.test.cli.test_cp",
"allmydata.test.cli.test_create",
"allmydata.test.cli.test_create_alias",
@ -216,11 +218,7 @@ PORTED_TEST_MODULES = [
"allmydata.test.test_consumer",
"allmydata.test.test_crawler",
"allmydata.test.test_crypto",
# Only partially ported, CLI-using test code is disabled for now until CLI
# is ported.
"allmydata.test.test_deepcheck",
"allmydata.test.test_deferredutil",
"allmydata.test.test_dictutil",
"allmydata.test.test_dirnode",
@ -258,12 +256,7 @@ PORTED_TEST_MODULES = [
"allmydata.test.test_storage",
"allmydata.test.test_storage_client",
"allmydata.test.test_storage_web",
# Only partially ported, test_filesystem_with_cli_in_subprocess isn't
# ported yet, nor is part of test_filesystem (the call to _test_cli). This
# should be done once CLI is ported.
"allmydata.test.test_system",
"allmydata.test.test_testing",
"allmydata.test.test_time_format",
"allmydata.test.test_tor_provider",