Some progress towards passing tests on Python 3.

This commit is contained in:
Itamar Turner-Trauring 2021-03-15 10:37:03 -04:00
parent 4d80177b18
commit 44374487c7
5 changed files with 13 additions and 13 deletions

View File

@ -351,7 +351,7 @@ class BackupOptions(FileStoreOptions):
line. The file is assumed to be in the argv encoding."""
abs_filepath = argv_to_abspath(filepath)
try:
exclude_file = file(abs_filepath)
exclude_file = open(abs_filepath)
except:
raise BackupConfigurationError('Error opening exclude file %s.' % quote_local_unicode_path(abs_filepath))
try:

View File

@ -228,19 +228,19 @@ def get_alias(aliases, path_unicode, default):
precondition(isinstance(path_unicode, str), path_unicode)
from allmydata import uri
path = path_unicode.encode('utf-8').strip(" ")
path = path_unicode.encode('utf-8').strip(b" ")
if uri.has_uri_prefix(path):
# We used to require "URI:blah:./foo" in order to get a subpath,
# stripping out the ":./" sequence. We still allow that for compatibility,
# but now also allow just "URI:blah/foo".
sep = path.find(":./")
sep = path.find(b":./")
if sep != -1:
return path[:sep], path[sep+3:]
sep = path.find("/")
sep = path.find(b"/")
if sep != -1:
return path[:sep], path[sep+1:]
return path, ""
colon = path.find(":")
return path, b""
colon = path.find(b":")
if colon == -1:
# no alias
if default == None:

View File

@ -2,7 +2,7 @@ from __future__ import print_function
import os.path
import time
import urllib
from urllib.parse import quote as url_quote
import json
import datetime
from allmydata.scripts.common import get_alias, escape_path, DEFAULT_ALIAS, \
@ -52,7 +52,7 @@ def mkdir(contents, options):
def put_child(dirurl, childname, childcap):
assert dirurl[-1] != "/"
url = dirurl + "/" + urllib.quote(unicode_to_url(childname)) + "?t=uri"
url = dirurl + "/" + url_quote(unicode_to_url(childname)) + "?t=uri"
resp = do_http("PUT", url, childcap)
if resp.status not in (200, 201):
raise HTTPError("Error during put_child", resp)
@ -97,7 +97,7 @@ class BackerUpper(object):
except UnknownAliasError as e:
e.display(stderr)
return 1
to_url = nodeurl + "uri/%s/" % urllib.quote(rootcap)
to_url = nodeurl + "uri/%s/" % url_quote(rootcap)
if path:
to_url += escape_path(path)
if not to_url.endswith("/"):
@ -192,7 +192,7 @@ class BackerUpper(object):
filecap = r.was_uploaded()
self.verboseprint("checking %s" % quote_output(filecap))
nodeurl = self.options['node-url']
checkurl = nodeurl + "uri/%s?t=check&output=JSON" % urllib.quote(filecap)
checkurl = nodeurl + "uri/%s?t=check&output=JSON" % url_quote(filecap)
self._files_checked += 1
resp = do_http("POST", checkurl)
if resp.status != 200:
@ -225,7 +225,7 @@ class BackerUpper(object):
dircap = r.was_created()
self.verboseprint("checking %s" % quote_output(dircap))
nodeurl = self.options['node-url']
checkurl = nodeurl + "uri/%s?t=check&output=JSON" % urllib.quote(dircap)
checkurl = nodeurl + "uri/%s?t=check&output=JSON" % url_quote(dircap)
self._directories_checked += 1
resp = do_http("POST", checkurl)
if resp.status != 200:

View File

@ -55,5 +55,5 @@ class CLITestMixin(ReallyEqualMixin):
verb = ensure_str(verb)
args = [ensure_str(arg) for arg in args]
client_dir = ensure_str(self.get_clientdir(i=client_num))
nodeargs = [ b"--node-directory", client_dir ]
nodeargs = [ "--node-directory", client_dir ]
return run_cli(verb, *args, nodeargs=nodeargs, **kwargs)

View File

@ -412,7 +412,7 @@ class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
self.failUnlessEqual(name, abspath_expanduser_unicode(exclude_file))
return StringIO()
patcher = MonkeyPatcher((builtins, 'file', call_file))
patcher = MonkeyPatcher((builtins, 'open', call_file))
patcher.runWithPatches(parse_options, basedir, "backup", ['--exclude-from', unicode_to_argv(exclude_file), 'from', 'to'])
self.failUnless(ns.called)