]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Fix test failures due to Unicode basedir patches.
authordavid-sarah <david-sarah@jacaranda.org>
Sun, 25 Jul 2010 01:03:18 +0000 (18:03 -0700)
committerdavid-sarah <david-sarah@jacaranda.org>
Sun, 25 Jul 2010 01:03:18 +0000 (18:03 -0700)
src/allmydata/client.py
src/allmydata/node.py
src/allmydata/test/test_cli.py
src/allmydata/test/test_system.py
src/allmydata/util/encodingutil.py

index 12e74734d46dd496607770a6d725cb1a9ac69b94..d4b6172761c531da8d299c685e2d0459c39f72d8 100644 (file)
@@ -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",
index 108e82b4cfeae67585680d95916d88c79154173e..851b7bc1c002fa147879fb241e0c27da9acf5ca8 100644 (file)
@@ -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
index 6cb2786fbee4bd2d185f44defccb9e7281988929..6a86888b182d3617662f996d894be231da965693 100644 (file)
@@ -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)
index e2062ba406da2718f86a6916979d23524b866a4c..93a71a0a28905b5dc4067f717993a564a5e95174 100644 (file)
@@ -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))
index cb891a21c99f838cb0d4f884c11661a82dbefb56..5079184a9158dc79f471540e48328c3c47dc4058 100644 (file)
@@ -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)