tahoe_cp.py: Don't call urllib.quote with an Unicode argument, fix #1224

tahoe_backup.py: Fix another (potential) occurrence of calling urllib.quote()
with an Unicode parameter
This commit is contained in:
Francois Deppierraz 2010-10-16 11:09:22 +02:00 committed by Brian Warner
parent c18953c169
commit 14ee763c54
3 changed files with 35 additions and 2 deletions

View File

@ -50,7 +50,7 @@ def mkdir(contents, options):
def put_child(dirurl, childname, childcap):
assert dirurl[-1] == "/"
url = dirurl + urllib.quote(childname) + "?t=uri"
url = dirurl + urllib.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)

View File

@ -51,7 +51,7 @@ def mkdir(targeturl):
def make_tahoe_subdirectory(nodeurl, parent_writecap, name):
url = nodeurl + "/".join(["uri",
urllib.quote(parent_writecap),
urllib.quote(name),
urllib.quote(unicode_to_url(name)),
]) + "?t=mkdir"
resp = do_http("POST", url)
if resp.status in (200, 201):

View File

@ -1487,6 +1487,39 @@ class Cp(GridTestMixin, CLITestMixin, unittest.TestCase):
d.addCallback(_check)
return d
def test_unicode_dirnames(self):
self.basedir = "cli/Cp/unicode_dirnames"
fn1 = os.path.join(unicode(self.basedir), u"\u00C4rtonwall")
try:
fn1_arg = fn1.encode(get_argv_encoding())
artonwall_arg = u"\u00C4rtonwall".encode(get_argv_encoding())
except UnicodeEncodeError:
raise unittest.SkipTest("A non-ASCII command argument could not be encoded on this platform.")
self.skip_if_cannot_represent_filename(fn1)
self.set_up_grid()
d = self.do_cli("create-alias", "tahoe")
d.addCallback(lambda res: self.do_cli("mkdir", "tahoe:test/" + artonwall_arg))
d.addCallback(lambda res: self.do_cli("cp", "-r", "tahoe:test", "tahoe:test2"))
d.addCallback(lambda res: self.do_cli("ls", "tahoe:test2"))
def _check((rc, out, err)):
try:
unicode_to_output(u"\u00C4rtonwall")
except UnicodeEncodeError:
self.failUnlessReallyEqual(rc, 1)
self.failUnlessReallyEqual(out, "")
self.failUnlessIn(quote_output(u"\u00C4rtonwall"), err)
self.failUnlessIn("files whose names could not be converted", err)
else:
self.failUnlessReallyEqual(rc, 0)
self.failUnlessReallyEqual(out.decode(get_output_encoding()), u"\u00C4rtonwall\n")
self.failUnlessReallyEqual(err, "")
d.addCallback(_check)
return d
class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):