From: <mi...@us...> - 2013-01-01 20:00:28
|
Revision: 7584 http://docutils.svn.sourceforge.net/docutils/?rev=7584&view=rev Author: milde Date: 2013-01-01 20:00:21 +0000 (Tue, 01 Jan 2013) Log Message: ----------- Unify/simplify type testing in "validate_*_list". Circumvent the problem that the value may be "unicode" or "str" by testing for "not a list". Modified Paths: -------------- trunk/docutils/docutils/frontend.py trunk/docutils/test/test_settings.py Modified: trunk/docutils/docutils/frontend.py =================================================================== --- trunk/docutils/docutils/frontend.py 2012-12-31 13:05:27 UTC (rev 7583) +++ trunk/docutils/docutils/frontend.py 2013-01-01 20:00:21 UTC (rev 7584) @@ -158,7 +158,7 @@ def validate_colon_separated_string_list( setting, value, option_parser, config_parser=None, config_section=None): - if isinstance(value, unicode): + if not isinstance(value, list): value = value.split(':') else: last = value.pop() @@ -169,20 +169,15 @@ config_parser=None, config_section=None): """Check/normalize list arguments (split at "," and strip whitespace). """ - # `value` is already a list when given as command line option - # and "action" is "append" - # in python2 buildhtml.py calls this once with str after several - # times with unicode. MAYBE fix somewhere else. - #if isinstance(value, unicode): #py3 - #if isinstance(value, basestr): # py3 and py2.7 - if not hasattr(value, 'pop'): + # `value` is already a ``list`` when given as command line option + # and "action" is "append" and ``unicode`` or ``str`` else. + if not isinstance(value, list): value = [value] # this function is called for every option added to `value` # -> split the last item and append the result: last = value.pop() - classes = [cls.strip(u' \t\n') for cls in last.split(',') - if cls.strip(u' \t\n')] - value.extend(classes) + items = [i.strip(u' \t\n') for i in last.split(u',') if i.strip(u' \t\n')] + value.extend(items) return value def validate_url_trailing_slash( Modified: trunk/docutils/test/test_settings.py =================================================================== --- trunk/docutils/test/test_settings.py 2012-12-31 13:05:27 UTC (rev 7583) +++ trunk/docutils/test/test_settings.py 2013-01-01 20:00:21 UTC (rev 7584) @@ -198,9 +198,11 @@ def test_validate_colon_separated_string_list(self): tests = ( (u'a', ['a',] ), - (u'a:12', ['a', '12'] ), + ('a', ['a',] ), + (u'a:b', ['a', 'b'] ), + ('a:b', ['a', 'b'] ), ([u'a',], ['a',] ), - # TODO ("u'a',", ['a',] ), AttributeError: 'str' object has no attribute 'pop' + ([u'a', u'b:c'], ['a', 'b', 'c'] ), ) for t in tests: self.assertEqual( @@ -211,9 +213,12 @@ def test_validate_comma_separated_list(self): tests = ( (u'a', ['a',] ), - (u'a,12', ['a', '12'] ), + ('a', ['a',] ), + (u'a,b', ['a', 'b'] ), + ('a,b', ['a', 'b'] ), ([u'a',], ['a',] ), - ('a,', ['a',] ), # in python3 this is unicode too + ([u'a', u'b,c'], ['a', 'b', 'c'] ), + (['a', 'b,c'], ['a', 'b', 'c'] ), ) for t in tests: self.assertEqual( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |