From: david-sarah Date: Sun, 25 Jul 2010 01:03:18 +0000 (-0700) Subject: Fix test failures due to Unicode basedir patches. X-Git-Tag: allmydata-tahoe-1.8.0b2~68 X-Git-Url: https://git.rkrishnan.org/listings/banana.xhtml?a=commitdiff_plain;h=f036dfaa4bfb9f90d6953cd567506cff758841a8;p=tahoe-lafs%2Ftahoe-lafs.git Fix test failures due to Unicode basedir patches. --- diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 12e74734..d4b61727 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -17,6 +17,7 @@ from allmydata.immutable.offloaded import Helper from allmydata.control import ControlServer from allmydata.introducer.client import IntroducerClient from allmydata.util import hashutil, base32, pollmixin, cachedir, log +from allmydata.util.encodingutil import get_filesystem_encoding from allmydata.util.abbreviate import parse_abbreviated_size from allmydata.util.time_format import parse_duration, parse_date from allmydata.stats import StatsProvider @@ -261,7 +262,7 @@ class Client(node.Node, pollmixin.PollMixin): d = self.when_tub_ready() # we can't do registerReference until the Tub is ready def _publish(res): - furl_file = os.path.join(self.basedir, "private", "storage.furl") + furl_file = os.path.join(self.basedir, "private", "storage.furl").encode(get_filesystem_encoding()) furl = self.tub.registerReference(ss, furlFile=furl_file) ri_name = RIStorageServer.__remote_name__ self.introducer_client.publish(furl, "storage", ri_name) @@ -373,7 +374,7 @@ class Client(node.Node, pollmixin.PollMixin): # same, since that makes 'cp' work smoothly, but the difference # between config inputs and generated outputs is hard to see. helper_furlfile = os.path.join(self.basedir, - "private", "helper.furl") + "private", "helper.furl").encode(get_filesystem_encoding()) self.tub.registerReference(self.helper, furlFile=helper_furlfile) d.addCallback(_publish) d.addErrback(log.err, facility="tahoe.init", diff --git a/src/allmydata/node.py b/src/allmydata/node.py index 108e82b4..851b7bc1 100644 --- a/src/allmydata/node.py +++ b/src/allmydata/node.py @@ -305,8 +305,8 @@ class Node(service.MultiService): ob.formatTime = newmeth # TODO: twisted >2.5.0 offers maxRotatedFiles=50 - self.tub.setOption("logport-furlfile", - os.path.join(self.basedir, "private","logport.furl")) + lgfurl_file = os.path.join(self.basedir, "private", "logport.furl").encode(get_filesystem_encoding()) + self.tub.setOption("logport-furlfile", lgfurl_file) lgfurl = self.get_config("node", "log_gatherer.furl", "") if lgfurl: # this is in addition to the contents of log-gatherer-furlfile diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index 6cb2786f..6a86888b 100644 --- a/src/allmydata/test/test_cli.py +++ b/src/allmydata/test/test_cli.py @@ -33,7 +33,7 @@ from twisted.python import usage from allmydata.util.assertutil import precondition from allmydata.util.encodingutil import listdir_unicode, unicode_platform, \ quote_output, get_output_encoding, get_argv_encoding, get_filesystem_encoding, \ - unicode_to_output, to_str, to_argv + unicode_to_output, unicode_to_argv, to_str from allmydata.util.fileutil import abspath_expanduser_unicode timeout = 480 # deep_check takes 360s on Zandr's linksys box, others take > 240s @@ -775,7 +775,7 @@ class Put(GridTestMixin, CLITestMixin, unittest.TestCase): self.set_up_grid() rel_fn = os.path.join(self.basedir, "DATAFILE") - abs_fn = to_argv(abspath_expanduser_unicode(unicode(rel_fn))) + abs_fn = unicode_to_argv(abspath_expanduser_unicode(unicode(rel_fn))) # we make the file small enough to fit in a LIT file, for speed fileutil.write(rel_fn, "short file") d = self.do_cli("put", rel_fn) diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index e2062ba4..93a71a0a 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -12,7 +12,7 @@ from allmydata.immutable import offloaded, upload from allmydata.immutable.filenode import ImmutableFileNode, LiteralFileNode from allmydata.util import idlib, mathutil from allmydata.util import log, base32 -from allmydata.util.encodingutil import quote_output +from allmydata.util.encodingutil import quote_output, unicode_to_argv, get_filesystem_encoding from allmydata.util.fileutil import abspath_expanduser_unicode from allmydata.util.consumer import MemoryConsumer, download_to_data from allmydata.scripts import runner @@ -1293,7 +1293,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase): out,err = StringIO(), StringIO() rc = runner.runner(["debug", "dump-share", "--offsets", - filename], + unicode_to_argv(filename)], stdout=out, stderr=err) output = out.getvalue() self.failUnlessEqual(rc, 0) @@ -1320,6 +1320,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase): # 'find-shares' tool sharedir, shnum = os.path.split(filename) storagedir, storage_index_s = os.path.split(sharedir) + storage_index_s = str(storage_index_s) out,err = StringIO(), StringIO() nodedirs = [self.getdir("client%d" % i) for i in range(self.numclients)] cmd = ["debug", "find-shares", storage_index_s] + nodedirs @@ -1355,8 +1356,9 @@ class SystemTest(SystemTestMixin, unittest.TestCase): d.addCallback(self._test_control2, control_furl_file) return d def _test_control2(self, rref, filename): - d = rref.callRemote("upload_from_file_to_uri", filename, convergence=None) - downfile = os.path.join(self.basedir, "control.downfile") + d = rref.callRemote("upload_from_file_to_uri", + filename.encode(get_filesystem_encoding()), convergence=None) + downfile = os.path.join(self.basedir, "control.downfile").encode(get_filesystem_encoding()) d.addCallback(lambda uri: rref.callRemote("download_from_uri_to_file", uri, downfile)) diff --git a/src/allmydata/util/encodingutil.py b/src/allmydata/util/encodingutil.py index cb891a21..5079184a 100644 --- a/src/allmydata/util/encodingutil.py +++ b/src/allmydata/util/encodingutil.py @@ -99,6 +99,21 @@ def argv_to_abspath(s): """ return abspath_expanduser_unicode(argv_to_unicode(s)) +def unicode_to_argv(s, mangle=False): + """ + Encode the given Unicode argument as a bytestring. + If the argument is to be passed to a different process, then the 'mangle' argument + should be true; on Windows, this uses a mangled encoding that will be reversed by + code in runner.py. + """ + precondition(isinstance(s, unicode), s) + + if mangle and sys.platform == "win32": + # This must be the same as 'mangle' in bin/tahoe-script.template. + return str(re.sub(ur'[^\x20-\x7F]', lambda m: u'\x7F%x;' % (ord(m.group(0)),), s)) + else: + return s.encode(argv_encoding) + def unicode_to_url(s): """ Encode an unicode object used in an URL. @@ -115,11 +130,6 @@ def to_str(s): return s return s.encode('utf-8') -def to_argv(s): - if isinstance(s, str): - return s - return s.encode(argv_encoding) - PRINTABLE_ASCII = re.compile(r'^[\n\r\x20-\x7E]*$', re.DOTALL) PRINTABLE_8BIT = re.compile(r'^[\n\r\x20-\x7E\x80-\xFF]*$', re.DOTALL)