From: david-sarah Date: Wed, 28 Jul 2010 06:27:31 +0000 (-0700) Subject: Skip option arguments to the python interpreter when reconstructing Unicode argv... X-Git-Tag: allmydata-tahoe-1.8.0b2~52 X-Git-Url: https://git.rkrishnan.org/%5B/frontends/%22news.html/something?a=commitdiff_plain;h=88b6c57a1c12187f17b534db0172b2325f646dc6;p=tahoe-lafs%2Ftahoe-lafs.git Skip option arguments to the python interpreter when reconstructing Unicode argv on Windows. --- diff --git a/bin/tahoe-script.template b/bin/tahoe-script.template index 48bdbf18..347bb82b 100644 --- a/bin/tahoe-script.template +++ b/bin/tahoe-script.template @@ -65,6 +65,20 @@ if sys.platform == "win32": return str(re.sub(ur'[^\x20-\x7F]', lambda m: u'\x7F%x;' % (ord(m.group(0)),), s)) argv = [mangle(argv_unicode[i]) for i in xrange(1, argc.value)] + + # Skip option arguments to the Python interpreter. + while len(argv) > 0: + arg = argv[0] + if not arg.startswith(u"-") or arg == u"-": + break + argv = argv[1:] + if arg == u'-m': + # sys.argv[0] should really be the absolute path of the module source, but never mind + break + if arg == u'-c': + argv[0] = u'-c' + break + local_tahoe = "Scripts\\tahoe.pyscript" else: argv = sys.argv diff --git a/src/allmydata/windows/fixups.py b/src/allmydata/windows/fixups.py index 92e2fc59..ce8af4b2 100644 --- a/src/allmydata/windows/fixups.py +++ b/src/allmydata/windows/fixups.py @@ -169,17 +169,31 @@ def initialize(): # Because of (and similar limitations in # twisted), the 'bin/tahoe' script cannot invoke us with the actual Unicode arguments. - # Instead it "mangles" or escapes them using \x7f as an escape character, which we + # Instead it "mangles" or escapes them using \x7F as an escape character, which we # unescape here. def unmangle(s): - return re.sub(ur'\x7f[0-9a-fA-F]*\;', lambda m: unichr(int(m.group(0)[1:-1], 16)), s) + return re.sub(ur'\x7F[0-9a-fA-F]*\;', lambda m: unichr(int(m.group(0)[1:-1], 16)), s) try: - sys.argv = [unmangle(argv_unicode[i]).encode('utf-8') for i in xrange(1, argc.value)] + argv = [unmangle(argv_unicode[i]).encode('utf-8') for i in xrange(1, argc.value)] except Exception, e: _complain("%s: could not unmangle Unicode arguments.\n%r" % (sys.argv[0], [argv_unicode[i] for i in xrange(1, argc.value)])) raise - if sys.argv[0].endswith('.pyscript'): - sys.argv[0] = sys.argv[0][:-9] + # Skip option arguments to the Python interpreter. + while len(argv) > 0: + arg = argv[0] + if not arg.startswith(u"-") or arg == u"-": + if arg.endswith('.pyscript'): + argv[0] = arg[:-9] + break + argv = argv[1:] + if arg == u'-m': + # sys.argv[0] should really be the absolute path of the module source, but never mind + break + if arg == u'-c': + argv[0] = u'-c' + break + + sys.argv = argv