summaryrefslogtreecommitdiff
path: root/docutils
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2013-01-01 20:00:21 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2013-01-01 20:00:21 +0000
commit0c2338b73d9e01087c8fdd96c98e2321dac66d88 (patch)
treeaa61c768cf37d969c182881f1725a3381fb23503 /docutils
parentee2f101417deb0edec36cf757956bede4df9e0f7 (diff)
downloaddocutils-0c2338b73d9e01087c8fdd96c98e2321dac66d88.tar.gz
Unify/simplify type testing in "validate_*_list".
Circumvent the problem that the value may be "unicode" or "str" by testing for "not a list". git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@7584 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils')
-rw-r--r--docutils/docutils/frontend.py17
-rwxr-xr-xdocutils/test/test_settings.py13
2 files changed, 15 insertions, 15 deletions
diff --git a/docutils/docutils/frontend.py b/docutils/docutils/frontend.py
index ebecff19b..ef6a1f90b 100644
--- a/docutils/docutils/frontend.py
+++ b/docutils/docutils/frontend.py
@@ -158,7 +158,7 @@ def validate_threshold(setting, value, option_parser,
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 @@ def validate_comma_separated_list(setting, value, option_parser,
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(
diff --git a/docutils/test/test_settings.py b/docutils/test/test_settings.py
index d7c111c0f..bde80328f 100755
--- a/docutils/test/test_settings.py
+++ b/docutils/test/test_settings.py
@@ -198,9 +198,11 @@ class HelperFunctionsTests(unittest.TestCase):
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 @@ class HelperFunctionsTests(unittest.TestCase):
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(