summaryrefslogtreecommitdiff
path: root/docutils/parsers/rst
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2013-03-04 13:20:49 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2013-03-04 13:20:49 +0000
commit6150a8dfd9f99865e48098ee3ef7953a5d02ed7b (patch)
treea0cbcaae7295d322f1479a29f020f169b9dcd98b /docutils/parsers/rst
parente1998a914a538b41956951572b80c098c0293d22 (diff)
downloaddocutils-6150a8dfd9f99865e48098ee3ef7953a5d02ed7b.tar.gz
Fix [ 3606028 ] ``assert`` is skipped with ``python -O``.
Also, raise ValueError with list of valid units if length_or_percentage_or_unitless() fails. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7621 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/parsers/rst')
-rw-r--r--docutils/parsers/rst/directives/__init__.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/docutils/parsers/rst/directives/__init__.py b/docutils/parsers/rst/directives/__init__.py
index fdc70d70f..ee919dd6f 100644
--- a/docutils/parsers/rst/directives/__init__.py
+++ b/docutils/parsers/rst/directives/__init__.py
@@ -232,9 +232,8 @@ def get_measure(argument, units):
"""
match = re.match(r'^([0-9.]+) *(%s)$' % '|'.join(units), argument)
try:
- assert match is not None
float(match.group(1))
- except (AssertionError, ValueError):
+ except (AttributeError, ValueError):
raise ValueError(
'not a positive measure of one of the following units:\n%s'
% ' '.join(['"%s"' % i for i in units]))
@@ -262,7 +261,11 @@ def length_or_percentage_or_unitless(argument, default=''):
try:
return get_measure(argument, length_units + ['%'])
except ValueError:
- return get_measure(argument, ['']) + default
+ try:
+ return get_measure(argument, ['']) + default
+ except ValueError:
+ # raise ValueError with list of valid units:
+ return get_measure(argument, length_units + ['%'])
def class_option(argument):
"""