summaryrefslogtreecommitdiff
path: root/pygments/util.py
diff options
context:
space:
mode:
authorgbrandl <devnull@localhost>2007-02-18 15:40:55 +0100
committergbrandl <devnull@localhost>2007-02-18 15:40:55 +0100
commit4f20affc8e7133fc897c754ea8d5ef403ab44399 (patch)
tree6f0f860be85a6be739b3f6683139dc93e84de7fd /pygments/util.py
parentfd77019bad3bc2f829a83b25e75cf61ddcc544a1 (diff)
downloadpygments-4f20affc8e7133fc897c754ea8d5ef403ab44399.tar.gz
[svn] Add a new test for pygments.util, fix coverage test.
Diffstat (limited to 'pygments/util.py')
-rw-r--r--pygments/util.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/pygments/util.py b/pygments/util.py
index 79fa250e..3331400a 100644
--- a/pygments/util.py
+++ b/pygments/util.py
@@ -18,7 +18,7 @@ doctype_lookup_re = re.compile(r'''(?smx)
[a-zA-Z_][a-zA-Z0-9]*\s+
[a-zA-Z_][a-zA-Z0-9]*\s+
"[^"]*")
- [^>]+>
+ [^>]*>
''')
tag_re = re.compile(r'<(.+?)(\s.*?)?>.*?</\1>(?uism)')
@@ -37,6 +37,12 @@ def get_bool_opt(options, optname, default=None):
string = options.get(optname, default)
if isinstance(string, bool):
return string
+ elif isinstance(string, int):
+ return bool(string)
+ elif not isinstance(string, basestring):
+ raise OptionError('Invalid type %r for option %s; use '
+ '1/0, yes/no, true/false, on/off' % (
+ string, optname))
elif string.lower() in ('1', 'yes', 'true', 'on'):
return True
elif string.lower() in ('0', 'no', 'false', 'off'):
@@ -51,6 +57,10 @@ def get_int_opt(options, optname, default=None):
string = options.get(optname, default)
try:
return int(string)
+ except TypeError:
+ raise OptionError('Invalid type %r for option %s; you '
+ 'must give an integer value' % (
+ string, optname))
except ValueError:
raise OptionError('Invalid value %r for option %s; you '
'must give an integer value' % (
@@ -64,7 +74,7 @@ def get_list_opt(options, optname, default=None):
elif isinstance(val, (list, tuple)):
return list(val)
else:
- raise OptionError('Invalid value %r for option %s; you '
+ raise OptionError('Invalid type %r for option %s; you '
'must give a list value' % (
val, optname))