MCPcopy Index your code
hub / github.com/Python-Markdown/markdown / parseBoolValue

Function parseBoolValue

markdown/util.py:139–155  ·  view source on GitHub ↗

Parses a string representing a boolean value. If parsing was successful, returns `True` or `False`. If `preserve_none=True`, returns `True`, `False`, or `None`. If parsing was not successful, raises `ValueError`, or, if `fail_on_errors=False`, returns `None`.

(value: str | None, fail_on_errors: bool = True, preserve_none: bool = False)

Source from the content-addressed store, hash-verified

137
138
139def parseBoolValue(value: str | None, fail_on_errors: bool = True, preserve_none: bool = False) -> bool | None:
140 """Parses a string representing a boolean value. If parsing was successful,
141 returns `True` or `False`. If `preserve_none=True`, returns `True`, `False`,
142 or `None`. If parsing was not successful, raises `ValueError`, or, if
143 `fail_on_errors=False`, returns `None`."""
144 if not isinstance(value, str):
145 if preserve_none and value is None:
146 return value
147 return bool(value)
148 elif preserve_none and value.lower() == 'none':
149 return None
150 elif value.lower() in ('true', 'yes', 'y', 'on', '1'):
151 return True
152 elif value.lower() in ('false', 'no', 'n', 'off', '0', 'none'):
153 return False
154 elif fail_on_errors:
155 raise ValueError('Cannot parse bool value: %r' % value)
156
157
158def code_escape(text: str) -> str:

Callers 4

handle_attrsMethod · 0.85
__init__Method · 0.85
__init__Method · 0.85
setConfigMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…