Hacked optparse (yet again) to force it to play nice with unicode flags.
Previously, whenever a flag had unicode characters in it; it would all completely blow up.
This commit is contained in:
parent
f4b10ce15f
commit
c073e32dbe
|
@ -25,3 +25,10 @@ try:
|
||||||
except NameError:
|
except NameError:
|
||||||
def unicode(string):
|
def unicode(string):
|
||||||
return str(string)
|
return str(string)
|
||||||
|
|
||||||
|
def convert_command_line():
|
||||||
|
try:
|
||||||
|
for num, arg in enumerate(sys.argv):
|
||||||
|
sys.argv[num] = unicode(arg.decode("utf-8", "replace"))
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
|
@ -31,6 +31,7 @@ except:
|
||||||
|
|
||||||
import blame
|
import blame
|
||||||
import changes
|
import changes
|
||||||
|
import compatibility
|
||||||
import config
|
import config
|
||||||
import extensions
|
import extensions
|
||||||
import filtering
|
import filtering
|
||||||
|
@ -124,6 +125,7 @@ def __handle_version__(__option__, __opt_str__, __value__, __parser__):
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
compatibility.convert_command_line()
|
||||||
parser = optval.OptionParser(add_help_option=False)
|
parser = optval.OptionParser(add_help_option=False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -18,6 +18,11 @@
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
try:
|
||||||
|
from compatibility import unicode
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
import optparse
|
import optparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -77,3 +82,22 @@ class OptionParser(optparse.OptionParser):
|
||||||
raise OptionParsingError(_("invalid option -- '{0}'").format(variable[1:]))
|
raise OptionParsingError(_("invalid option -- '{0}'").format(variable[1:]))
|
||||||
|
|
||||||
raise OptionParsingError(_("invalid command-line options"))
|
raise OptionParsingError(_("invalid command-line options"))
|
||||||
|
|
||||||
|
#Originaly taken from the optparse module (and modified).
|
||||||
|
def parse_args(self, args=None, values=None):
|
||||||
|
rargs = self._get_args(args)
|
||||||
|
if values is None:
|
||||||
|
values = self.get_default_values()
|
||||||
|
|
||||||
|
#Pylint screams about these. However, this was how it was done in the original code.
|
||||||
|
self.rargs = rargs
|
||||||
|
self.largs = largs = []
|
||||||
|
self.values = values
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._process_args(largs, rargs, values)
|
||||||
|
except (optparse.BadOptionError, optparse.OptionValueError) as msg:
|
||||||
|
self.error(unicode(msg))
|
||||||
|
|
||||||
|
args = largs + rargs
|
||||||
|
return self.check_values(values, args)
|
||||||
|
|
Loading…
Reference in New Issue