Skip to content

Commit

Permalink
Merge "[IMPR] Show a warning if ignore_extension was set and the exte…
Browse files Browse the repository at this point in the history
…nsion is invalid."
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Nov 26, 2024
2 parents a21843b + 17ed3ca commit 644583e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions pywikibot/page/_filepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ def __init__(self, source, title: str = '', *,
"""Initializer.
.. versionchanged:: 8.4
check for valid extensions.
Check for valid extensions.
.. versionchanged:: 9.3
*ignore_extension* parameter was added
Added the optional *ignore_extension* parameter.
.. versionchanged:: 9.6
Show a warning if *ignore_extension* was set and the
extension is invalid.
.. seealso::
:meth:`Site.file_extensions
<pywikibot.site._apisite.APISite.file_extensions>`
:param source: the source of the page
:type source: pywikibot.page.BaseLink (or subclass),
Expand All @@ -62,16 +68,15 @@ def __init__(self, source, title: str = '', *,
if self.namespace() != 6:
raise ValueError(f"'{self.title()}' is not in the file namespace!")

if ignore_extension:
return

title = self.title(with_ns=False, with_section=False)
_, sep, extension = title.rpartition('.')
if not sep or extension.lower() not in self.site.file_extensions:
raise ValueError(
f'{title!r} does not have a valid extension '
f'({", ".join(self.site.file_extensions)}).'
)
msg = (f'{title!r} does not have a valid extension\n'
f'({", ".join(self.site.file_extensions)}).')
if not ignore_extension:
raise ValueError(msg)

pywikibot.warning(msg)

def _load_file_revisions(self, imageinfo) -> None:
"""Save a file revision of FilePage (a FileInfo object) in local cache.
Expand Down

0 comments on commit 644583e

Please sign in to comment.