Skip to content

Commit 5c14e5b

Browse files
committed
refactor: simplify continue_on_failure parameter handling in SitemapExtractor
1 parent 6a71c29 commit 5c14e5b

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

libs/extractor-api-lib/src/extractor_api_lib/impl/extractors/sitemap_extractor.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,20 @@ def _parse_sitemap_loader_parameters(
166166
except (json.JSONDecodeError, TypeError):
167167
sitemap_loader_parameters[x.key] = x.value
168168
elif x.key == "continue_on_failure":
169-
if isinstance(x.value, bool):
170-
sitemap_loader_parameters[x.key] = x.value
171-
elif isinstance(x.value, str):
172-
normalized = x.value.strip().lower()
173-
if normalized in ("true", "1", "yes", "y", "on"):
174-
sitemap_loader_parameters[x.key] = True
175-
elif normalized in ("false", "0", "no", "n", "off"):
176-
sitemap_loader_parameters[x.key] = False
177-
else:
178-
sitemap_loader_parameters[x.key] = x.value
179-
else:
180-
sitemap_loader_parameters[x.key] = x.value
169+
sitemap_loader_parameters[x.key] = self._normalize_boolean(x.value)
181170
else:
182171
sitemap_loader_parameters[x.key] = int(x.value) if x.value.isdigit() else x.value
183172
return sitemap_loader_parameters, parser_override
173+
174+
def _normalize_boolean(self, value: str) -> Optional[bool]:
175+
if isinstance(value, bool):
176+
return value
177+
if isinstance(value, str):
178+
normalized = value.strip().lower()
179+
if normalized in ("true", "1", "yes", "y", "on"):
180+
return True
181+
if normalized in ("false", "0", "no", "n", "off"):
182+
return False
183+
if isinstance(value, (int, float)):
184+
return bool(value)
185+
return None

0 commit comments

Comments
 (0)