MCPcopy
hub / github.com/scrapy/scrapy / getbool

Method getbool

scrapy/settings/__init__.py:175–203  ·  view source on GitHub ↗

Get a setting value as a boolean. ``1``, ``'1'``, `True`` and ``'True'`` return ``True``, while ``0``, ``'0'``, ``False``, ``'False'`` and ``None`` return ``False``. For example, settings populated through environment variables set to ``'0'`` will return ``

(self, name: _SettingsKey, default: bool = False)

Source from the content-addressed store, hash-verified

173 return self[name] if self[name] is not None else default
174
175 def getbool(self, name: _SettingsKey, default: bool = False) -> bool:
176 """
177 Get a setting value as a boolean.
178
179 ``1``, ``'1'``, `True`` and ``'True'`` return ``True``,
180 while ``0``, ``'0'``, ``False``, ``'False'`` and ``None`` return ``False``.
181
182 For example, settings populated through environment variables set to
183 ``'0'`` will return ``False`` when using this method.
184
185 :param name: the setting name
186 :type name: str
187
188 :param default: the value to return if no setting is found
189 :type default: object
190 """
191 got = self.get(name, default)
192 try:
193 return bool(int(got))
194 except ValueError:
195 if got in {"True", "true"}:
196 return True
197 if got in {"False", "false"}:
198 return False
199 raise ValueError(
200 "Supported values for boolean settings "
201 "are 0/1, True/False, '0'/'1', "
202 "'True'/'False' and 'true'/'false'"
203 ) from None
204
205 def getint(self, name: _SettingsKey, default: int = 0) -> int:
206 """

Callers 15

_apply_settingsMethod · 0.45
__init__Method · 0.45
crawlMethod · 0.45
__init__Method · 0.45
startMethod · 0.45
__init__Method · 0.45
executeFunction · 0.45
from_crawlerMethod · 0.45
from_crawlerMethod · 0.45
__init__Method · 0.45
inspect_responseFunction · 0.45
__init__Method · 0.45

Calls 1

getMethod · 0.95

Tested by

no test coverage detected