Commit 0de09846 by Pavel Yushchenko

fixes shlex unicode

parent ee02a2dd
...@@ -309,13 +309,13 @@ class OptionInput(InputTypeBase): ...@@ -309,13 +309,13 @@ class OptionInput(InputTypeBase):
id==description for now. TODO: make it possible to specify different id and descriptions. id==description for now. TODO: make it possible to specify different id and descriptions.
""" """
# parse the set of possible options # parse the set of possible options
lexer = shlex.shlex(options[1:-1]) lexer = shlex.shlex(options[1:-1].encode('utf8'))
lexer.quotes = "'" lexer.quotes = "'"
# Allow options to be separated by whitespace as well as commas # Allow options to be separated by whitespace as well as commas
lexer.whitespace = ", " lexer.whitespace = ", "
# remove quotes # remove quotes
tokens = [x[1:-1] for x in list(lexer)] tokens = [x[1:-1].decode('utf8') for x in list(lexer)]
# make list of (option_id, option_description), with description=id # make list of (option_id, option_description), with description=id
return [(t, t) for t in tokens] return [(t, t) for t in tokens]
......
...@@ -75,6 +75,10 @@ class OptionInputTest(unittest.TestCase): ...@@ -75,6 +75,10 @@ class OptionInputTest(unittest.TestCase):
check("('a', 'b')", ['a', 'b']) check("('a', 'b')", ['a', 'b'])
check("('a b','b')", ['a b', 'b']) check("('a b','b')", ['a b', 'b'])
check("('My \"quoted\"place','b')", ['My \"quoted\"place', 'b']) check("('My \"quoted\"place','b')", ['My \"quoted\"place', 'b'])
check(u"('б','в')", [u'б', u'в'])
check(u"('б', 'в')", [u'б', u'в'])
check(u"('б в','в')", [u'б в', u'в'])
check(u"('Мой \"кавыки\"место','в')", [u'Мой \"кавыки\"место', u'в'])
class ChoiceGroupTest(unittest.TestCase): class ChoiceGroupTest(unittest.TestCase):
......
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