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
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)
# 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",
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
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
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)
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
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)
# '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
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))
"""
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.
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)