Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/771825 )
Change subject: [page] Split page/__init__.py (part 2) ......................................................................
[page] Split page/__init__.py (part 2)
Change-Id: I6da67c0fbbe2ee00645646695e35beb450bd382a --- M pywikibot/CONTENT.rst A pywikibot/page/__init__.py M pywikibot/page/_basepage.py M tests/collections_tests.py M tox.ini 5 files changed, 110 insertions(+), 49 deletions(-)
Approvals: Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/CONTENT.rst b/pywikibot/CONTENT.rst index a9eed53..4712112 100644 --- a/pywikibot/CONTENT.rst +++ b/pywikibot/CONTENT.rst @@ -102,7 +102,9 @@ +----------------------------+------------------------------------------------------+ | page | Module with classes for MediaWiki page content | +============================+======================================================+ - | __init__.py | Objects representing MediaWiki pages | + | __init__.py | Interface representing MediaWiki pages | + +----------------------------+------------------------------------------------------+ + | _basepage.py | Objects representing MediaWiki pages | +----------------------------+------------------------------------------------------+ | _collections.py | Structures holding data for Wikibase entities | +----------------------------+------------------------------------------------------+ diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py new file mode 100644 index 0000000..c5c44f6 --- /dev/null +++ b/pywikibot/page/__init__.py @@ -0,0 +1,88 @@ +"""Interface of various types of MediaWiki pages.""" +# +# (C) Pywikibot team, 2022 +# +# Distributed under the terms of the MIT license. +# +from typing import Union + +from pywikibot.page._basepage import ( + BaseLink, + BasePage, + Category, + Claim, + FileInfo, + FilePage, + ItemPage, + Link, + MediaInfo, + Page, + Property, + PropertyPage, + SiteLink, + User, + WikibaseEntity, + WikibasePage, + html2unicode, +) +from pywikibot.page._revision import Revision +from pywikibot.site import BaseSite as _BaseSite +from pywikibot.tools import deprecated, issue_deprecation_warning +from pywikibot.tools.chars import url2string as _url2string + + +__all__ = ( + 'BaseLink', + 'Link', + 'SiteLink', + 'BasePage', + 'Page', + 'FilePage', + 'Category', + 'User', + 'WikibasePage', + 'ItemPage', + 'PropertyPage', + 'Property', + 'Claim', + 'FileInfo', + 'WikibaseEntity', + 'MediaInfo', + 'Revision', + 'html2unicode', + 'url2unicode', +) + +PageSourceType = Union[ + BaseLink, + _BaseSite, + Page, +] + + +@deprecated('pywikibot.tools.chars.url2string', since='6.2.0') +def url2unicode(title: str, encodings='utf-8') -> str: + """Convert URL-encoded text to unicode using several encoding. + + Uses the first encoding that doesn't cause an error. + + .. deprecated:: 6.2 + Use :func:`pywikibot.tools.chars.url2string` instead. + + :param title: URL-encoded character data to convert + :param encodings: Encodings to attempt to use during conversion. + :type encodings: str, list or Site + + :raise UnicodeError: Could not convert using any encoding. + """ + if isinstance(encodings, _BaseSite): + # use all possible encodings from Site object + encodings = encodings.encodings() + issue_deprecation_warning( + 'Passing BaseSite object to encodings parameter', + 'BaseSite.encodings()', + depth=1, + since='6.2.0' + ) + + return _url2string(title, encodings) diff --git a/pywikibot/page/_basepage.py b/pywikibot/page/_basepage.py index 904358f..05bc27b 100644 --- a/pywikibot/page/_basepage.py +++ b/pywikibot/page/_basepage.py @@ -80,32 +80,25 @@ PROTOCOL_REGEX = r'\Ahttps?://'
__all__ = ( + 'BaseLink', 'BasePage', - 'Page', - 'FilePage', 'Category', - 'User', - 'WikibasePage', + 'Claim', + 'FileInfo', + 'FilePage', 'ItemPage', + 'Link', + 'MediaInfo', + 'Page', 'Property', 'PropertyPage', - 'Claim', - 'Revision', - 'FileInfo', - 'BaseLink', - 'Link', 'SiteLink', - 'SiteLinkCollection', + 'User', + 'WikibaseEntity', + 'WikibasePage', 'html2unicode', - 'url2unicode', )
-PageSourceType = Union[ - 'pywikibot.site.BaseLink', - 'pywikibot.page.BaseSite', - 'pywikibot.page.Page', -] - logger = logging.getLogger('pywiki.wiki.page')
@@ -3555,6 +3548,12 @@ return self._file
def get(self, force: bool = False) -> dict: + """Fetch all MediaInfo entity data and cache it. + + :param force: override caching + :raise NoWikibaseEntityError: if this entity doesn't exist + :return: actual data which entity holds + """ if self.id == '-1': if force: if not self.file.exists(): @@ -5906,31 +5905,3 @@ return match.group(0)
return _ENTITY_SUB(handle_entity, text) - - -@deprecated('pywikibot.tools.chars.url2string', since='6.2.0') -def url2unicode(title: str, encodings='utf-8') -> str: - """Convert URL-encoded text to unicode using several encoding. - - Uses the first encoding that doesn't cause an error. - - .. deprecated:: 6.2 - Use :func:`pywikibot.tools.chars.url2string` instead. - - :param title: URL-encoded character data to convert - :param encodings: Encodings to attempt to use during conversion. - :type encodings: str, list or Site - - :raise UnicodeError: Could not convert using any encoding. - """ - if isinstance(encodings, pywikibot.site.BaseSite): - # use all possible encodings from Site object - encodings = encodings.encodings() - issue_deprecation_warning( - 'Passing BaseSite object to encodings parameter', - 'BaseSite.encodings()', - depth=1, - since='6.2.0' - ) - - return pywikibot.tools.chars.url2string(title, encodings) diff --git a/tests/collections_tests.py b/tests/collections_tests.py index f2b80ec..2d9096d 100755 --- a/tests/collections_tests.py +++ b/tests/collections_tests.py @@ -1,14 +1,14 @@ #!/usr/bin/python3 """Tests for the Wikidata parts of the page module.""" # -# (C) Pywikibot team, 2019-2021 +# (C) Pywikibot team, 2019-2022 # # Distributed under the terms of the MIT license. # import unittest from contextlib import suppress
-from pywikibot.page import ( +from pywikibot.page._collections import ( AliasesDict, ClaimCollection, LanguageDict, diff --git a/tox.ini b/tox.ini index 2e5202d..12254a4 100644 --- a/tox.ini +++ b/tox.ini @@ -148,7 +148,7 @@ pywikibot/fixes.py: E241 pywikibot/interwiki_graph.py: N802, N803, N806 pywikibot/login.py: N802, N816 - pywikibot/page/__init__.py: N802 + pywikibot/page/_basepage.py: N802 pywikibot/page/_collections.py: N802 pywikibot/pagegenerators.py: N802, N803, N806, N816 pywikibot/scripts/generate_family_file.py: T001
pywikibot-commits@lists.wikimedia.org