summaryrefslogtreecommitdiff
path: root/pygments
diff options
context:
space:
mode:
authorJean Abou Samra <jean@abou-samra.fr>2023-03-30 22:25:29 +0200
committerJean Abou Samra <jean@abou-samra.fr>2023-03-30 22:25:29 +0200
commit242e56e9c0ab98f5e51a1eb765a79b84e44125ce (patch)
tree9eed8175cff87f617bf9f48e6e56a76a8587b505 /pygments
parent243dd815b90bbc25f038149e9b99b70f0bd1a146 (diff)
downloadpygments-git-242e56e9c0ab98f5e51a1eb765a79b84e44125ce.tar.gz
Use autodoc for pygments.util
Diffstat (limited to 'pygments')
-rw-r--r--pygments/util.py28
1 files changed, 25 insertions, 3 deletions
diff --git a/pygments/util.py b/pygments/util.py
index d7ec9c11..941fdb9e 100644
--- a/pygments/util.py
+++ b/pygments/util.py
@@ -32,10 +32,16 @@ class ClassNotFound(ValueError):
class OptionError(Exception):
- pass
-
+ """
+ This exception will be raised by all option processing functions if
+ the type or value of the argument is not correct.
+ """
def get_choice_opt(options, optname, allowed, default=None, normcase=False):
+ """
+ If the key `optname` from the dictionary is not in the sequence
+ `allowed`, raise an error, otherwise return it.
+ """
string = options.get(optname, default)
if normcase:
string = string.lower()
@@ -46,6 +52,17 @@ def get_choice_opt(options, optname, allowed, default=None, normcase=False):
def get_bool_opt(options, optname, default=None):
+ """
+ Intuitively, this is `options.get(optname, default)`, but restricted to
+ Boolean value. The Booleans can be represented as string, in order to accept
+ Boolean value from the command line arguments. If the key `optname` is
+ present in the dictionary `options` and is not associated with a Boolean,
+ raise an `OptionError`. If it is absent, `default` is returned instead.
+
+ The valid string values for ``True`` are ``1``, ``yes``, ``true`` and
+ ``on``, the ones for ``False`` are ``0``, ``no``, ``false`` and ``off``
+ (matched case-insensitively).
+ """
string = options.get(optname, default)
if isinstance(string, bool):
return string
@@ -66,6 +83,7 @@ def get_bool_opt(options, optname, default=None):
def get_int_opt(options, optname, default=None):
+ """As :func:`get_bool_opt`, but interpret the value as an integer."""
string = options.get(optname, default)
try:
return int(string)
@@ -78,8 +96,12 @@ def get_int_opt(options, optname, default=None):
'must give an integer value' % (
string, optname))
-
def get_list_opt(options, optname, default=None):
+ """
+ If the key `optname` from the dictionary `options` is a string,
+ split it at whitespace and return it. If it is already a list
+ or a tuple, it is returned as a list.
+ """
val = options.get(optname, default)
if isinstance(val, str):
return val.split()