Commit cbf4161e authored by Andrey Golovizin's avatar Andrey Golovizin

Fix CommandLine.recognize_legacy_options() in Python 2

parent bf09eb8c
......@@ -26,6 +26,8 @@ from __future__ import unicode_literals
import optparse
import sys
import six
from pybtex import __version__, errors
from pybtex.plugin import enumerate_plugin_names, find_plugin
from pybtex.textutils import add_period
......@@ -209,10 +211,19 @@ class CommandLine(object):
def recognize_legacy_optons(self, args):
"""Grok some legacy long options starting with a single `-'."""
return [
'-' + arg if arg.split('=', 1)[0] in self.legacy_options else arg
for arg in args
]
return [self._replace_legacy_option(arg) for arg in args]
def _replace_legacy_option(self, arg):
try:
# legacy options are ASCII
unicode_arg = arg if isinstance(arg, six.text_type) else arg.decode('ASCII')
except UnicodeDecodeError:
return arg
if unicode_arg.split('=', 1)[0] in self.legacy_options:
return type(arg)('-') + arg
else:
return arg
def _extract_kwargs(self, options):
return dict(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment