Fix test failures due to Unicode basedir patches.

This commit is contained in:
david-sarah
2010-07-24 18:03:18 -07:00
parent 28e6ad51a7
commit f036dfaa4b
5 changed files with 28 additions and 15 deletions

View File

@ -17,6 +17,7 @@ from allmydata.immutable.offloaded import Helper
from allmydata.control import ControlServer from allmydata.control import ControlServer
from allmydata.introducer.client import IntroducerClient from allmydata.introducer.client import IntroducerClient
from allmydata.util import hashutil, base32, pollmixin, cachedir, log 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.abbreviate import parse_abbreviated_size
from allmydata.util.time_format import parse_duration, parse_date from allmydata.util.time_format import parse_duration, parse_date
from allmydata.stats import StatsProvider from allmydata.stats import StatsProvider
@ -261,7 +262,7 @@ class Client(node.Node, pollmixin.PollMixin):
d = self.when_tub_ready() d = self.when_tub_ready()
# we can't do registerReference until the Tub is ready # we can't do registerReference until the Tub is ready
def _publish(res): 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) furl = self.tub.registerReference(ss, furlFile=furl_file)
ri_name = RIStorageServer.__remote_name__ ri_name = RIStorageServer.__remote_name__
self.introducer_client.publish(furl, "storage", ri_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 # same, since that makes 'cp' work smoothly, but the difference
# between config inputs and generated outputs is hard to see. # between config inputs and generated outputs is hard to see.
helper_furlfile = os.path.join(self.basedir, 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) self.tub.registerReference(self.helper, furlFile=helper_furlfile)
d.addCallback(_publish) d.addCallback(_publish)
d.addErrback(log.err, facility="tahoe.init", d.addErrback(log.err, facility="tahoe.init",

View File

@ -305,8 +305,8 @@ class Node(service.MultiService):
ob.formatTime = newmeth ob.formatTime = newmeth
# TODO: twisted >2.5.0 offers maxRotatedFiles=50 # TODO: twisted >2.5.0 offers maxRotatedFiles=50
self.tub.setOption("logport-furlfile", lgfurl_file = os.path.join(self.basedir, "private", "logport.furl").encode(get_filesystem_encoding())
os.path.join(self.basedir, "private","logport.furl")) self.tub.setOption("logport-furlfile", lgfurl_file)
lgfurl = self.get_config("node", "log_gatherer.furl", "") lgfurl = self.get_config("node", "log_gatherer.furl", "")
if lgfurl: if lgfurl:
# this is in addition to the contents of log-gatherer-furlfile # this is in addition to the contents of log-gatherer-furlfile

View File

@ -33,7 +33,7 @@ from twisted.python import usage
from allmydata.util.assertutil import precondition from allmydata.util.assertutil import precondition
from allmydata.util.encodingutil import listdir_unicode, unicode_platform, \ from allmydata.util.encodingutil import listdir_unicode, unicode_platform, \
quote_output, get_output_encoding, get_argv_encoding, get_filesystem_encoding, \ 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 from allmydata.util.fileutil import abspath_expanduser_unicode
timeout = 480 # deep_check takes 360s on Zandr's linksys box, others take > 240s 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() self.set_up_grid()
rel_fn = os.path.join(self.basedir, "DATAFILE") 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 # we make the file small enough to fit in a LIT file, for speed
fileutil.write(rel_fn, "short file") fileutil.write(rel_fn, "short file")
d = self.do_cli("put", rel_fn) d = self.do_cli("put", rel_fn)

View File

@ -12,7 +12,7 @@ from allmydata.immutable import offloaded, upload
from allmydata.immutable.filenode import ImmutableFileNode, LiteralFileNode from allmydata.immutable.filenode import ImmutableFileNode, LiteralFileNode
from allmydata.util import idlib, mathutil from allmydata.util import idlib, mathutil
from allmydata.util import log, base32 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.fileutil import abspath_expanduser_unicode
from allmydata.util.consumer import MemoryConsumer, download_to_data from allmydata.util.consumer import MemoryConsumer, download_to_data
from allmydata.scripts import runner from allmydata.scripts import runner
@ -1293,7 +1293,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
out,err = StringIO(), StringIO() out,err = StringIO(), StringIO()
rc = runner.runner(["debug", "dump-share", "--offsets", rc = runner.runner(["debug", "dump-share", "--offsets",
filename], unicode_to_argv(filename)],
stdout=out, stderr=err) stdout=out, stderr=err)
output = out.getvalue() output = out.getvalue()
self.failUnlessEqual(rc, 0) self.failUnlessEqual(rc, 0)
@ -1320,6 +1320,7 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
# 'find-shares' tool # 'find-shares' tool
sharedir, shnum = os.path.split(filename) sharedir, shnum = os.path.split(filename)
storagedir, storage_index_s = os.path.split(sharedir) storagedir, storage_index_s = os.path.split(sharedir)
storage_index_s = str(storage_index_s)
out,err = StringIO(), StringIO() out,err = StringIO(), StringIO()
nodedirs = [self.getdir("client%d" % i) for i in range(self.numclients)] nodedirs = [self.getdir("client%d" % i) for i in range(self.numclients)]
cmd = ["debug", "find-shares", storage_index_s] + nodedirs 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) d.addCallback(self._test_control2, control_furl_file)
return d return d
def _test_control2(self, rref, filename): def _test_control2(self, rref, filename):
d = rref.callRemote("upload_from_file_to_uri", filename, convergence=None) d = rref.callRemote("upload_from_file_to_uri",
downfile = os.path.join(self.basedir, "control.downfile") filename.encode(get_filesystem_encoding()), convergence=None)
downfile = os.path.join(self.basedir, "control.downfile").encode(get_filesystem_encoding())
d.addCallback(lambda uri: d.addCallback(lambda uri:
rref.callRemote("download_from_uri_to_file", rref.callRemote("download_from_uri_to_file",
uri, downfile)) uri, downfile))

View File

@ -99,6 +99,21 @@ def argv_to_abspath(s):
""" """
return abspath_expanduser_unicode(argv_to_unicode(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): def unicode_to_url(s):
""" """
Encode an unicode object used in an URL. Encode an unicode object used in an URL.
@ -115,11 +130,6 @@ def to_str(s):
return s return s
return s.encode('utf-8') 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_ASCII = re.compile(r'^[\n\r\x20-\x7E]*$', re.DOTALL)
PRINTABLE_8BIT = re.compile(r'^[\n\r\x20-\x7E\x80-\xFF]*$', re.DOTALL) PRINTABLE_8BIT = re.compile(r'^[\n\r\x20-\x7E\x80-\xFF]*$', re.DOTALL)