jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/761395 )
Change subject: [cleanup] Remove functions and methods deprecated since release 3.0 ......................................................................
[cleanup] Remove functions and methods deprecated since release 3.0
- update tests - update archived scripts
Change-Id: Ib4247ae2d9b302f26d2e7d08141ba789b5ad3a19 --- M pywikibot/page/__init__.py M pywikibot/pagegenerators.py M scripts/archive/imagecopy.py M scripts/archive/imagecopy_self.py M tests/pagegenerators_tests.py 5 files changed, 3 insertions(+), 374 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py index 91a74d2..e86ed10 100644 --- a/pywikibot/page/__init__.py +++ b/pywikibot/page/__init__.py @@ -1035,11 +1035,6 @@ """ return self.site.page_can_be_edited(self, action)
- @deprecated("Page.has_permission('edit')", since='3.0.20200508') - def canBeEdited(self): # pragma: no cover - """DEPRECATED. Determine whether the page may be edited.""" - return self.has_permission() - def botMayEdit(self) -> bool: """ Determine whether the active bot is allowed to edit the page. @@ -2391,11 +2386,6 @@ url_param=url_param) return self.latest_file_info.thumburl
- @deprecated('file_is_shared', since='3.0.20200703') - def fileIsShared(self) -> bool: # pragma: no cover - """DEPRECATED. Check if the image is stored on Wikimedia Commons.""" - return self.file_is_shared() - def file_is_shared(self) -> bool: """Check if the file is stored on any known shared repository.""" # as of now, the only known repositories are commons and wikitravel diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index 0190518..7889c4f 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -61,7 +61,6 @@ from pywikibot.proofreadpage import ProofreadPage from pywikibot.tools import ( DequeGenerator, - deprecated, filter_unique, intersect_generators, itergroup, @@ -1446,26 +1445,6 @@ return gen
-@deprecated('File.usingPages()', since='3.0.20200609') -def FileLinksGenerator(referredFilePage: 'pywikibot.page.FilePage', - total: Optional[int] = None, - content: bool = False - ) -> Iterable['pywikibot.page.Page']: - """DEPRECATED. Yield Pages on which referredFilePage file is displayed.""" - return referredFilePage.usingPages(total=total, - content=content) # pragma: no cover - - -@deprecated('Page.imagelinks()', since='3.0.20200609') -def ImagesPageGenerator(pageWithImages: 'pywikibot.page.Page', - total: Optional[int] = None, - content: bool = False - ) -> Iterable['pywikibot.page.Page']: - """DEPRECATED. Yield FilePages displayed on pageWithImages.""" - return pageWithImages.imagelinks(total=total, - content=content) # pragma: no cover - - def InterwikiPageGenerator(page: 'pywikibot.page.Page' ) -> Iterable['pywikibot.page.Page']: """Iterate over all interwiki (non-language) links on a page.""" @@ -1535,25 +1514,6 @@ yield s
-@deprecated('Page.linkedPages()', since='3.0.20200609') -def LinkedPageGenerator(linkingPage: 'pywikibot.page.Page', - total: Optional[int] = None, - content: bool = False - ) -> Iterable['pywikibot.page.Page']: - """DEPRECATED. Yield all pages linked from a specific page. - - See :py:obj:`pywikibot.page.BasePage.linkedPages` for details. - - :param linkingPage: the page that links to the pages we want - :param total: the total number of pages to iterate - :param content: if True, retrieve the current content of each linked page - :return: a generator that yields Page objects of pages linked to - linkingPage - """ - return linkingPage.linkedPages(total=total, - content=content) # pragma: no cover - - def _yield_titles(f: Union[codecs.StreamReaderWriter, io.StringIO], site: pywikibot.site.BaseSite ) -> Iterable['pywikibot.page.Page']: @@ -1630,27 +1590,6 @@ yield pywikibot.Page(pywikibot.Link(title, site))
-@deprecated('site.load_pages_from_pageids()', since='3.0.20200609') -def PagesFromPageidGenerator(pageids: Iterable[str], - site: OPT_SITE_TYPE = None - ) -> Iterable['pywikibot.page.Page']: - """ - DEPRECATED. Return a page generator from pageids. - - Pages are iterated in the same order than in the underlying pageids. - Pageids are filtered and only one page is returned in case of - duplicate pageid. - - :param pageids: an iterable that returns pageids, or a comma-separated - string of pageids (e.g. '945097,1483753,956608') - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - - return site.load_pages_from_pageids(pageids) - - def UserContributionsGenerator(username: str, namespaces: Optional[List[int]] = None, site: OPT_SITE_TYPE = None, @@ -2319,143 +2258,6 @@ yield page
-@deprecated('Site.unusedfiles()', since='3.0.20200609') -def UnusedFilesGenerator(total: Optional[int] = None, # pragma: no cover - site: OPT_SITE_TYPE = None - ) -> Iterable['pywikibot.page.FilePage']: - """ - DEPRECATED. Unused files generator. - - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - return site.unusedfiles(total=total) - - -@deprecated('Site.withoutinterwiki()', since='3.0.20200609') -def WithoutInterwikiPageGenerator(total: Optional[int] = None, - site: OPT_SITE_TYPE = None - ) -> Iterable['pywikibot.page.Page']: - """ - DEPRECATED. Page lacking interwikis generator. - - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - return site.withoutinterwiki(total=total) - - -@deprecated('Site.uncategorizedcategories()', since='3.0.20200609') -def UnCategorizedCategoryGenerator(total: Optional[int] = 100, - site: OPT_SITE_TYPE = None - ) -> Iterable['pywikibot.Category']: - """ - DEPRECATED. Uncategorized category generator. - - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - return site.uncategorizedcategories(total=total) - - -@deprecated('Site.uncategorizedimages()', since='3.0.20200609') -def UnCategorizedImageGenerator(total: int = 100, # pragma: no cover - site: OPT_SITE_TYPE = None - ) -> Iterable['pywikibot.page.FilePage']: - """ - DEPRECATED. Uncategorized file generator. - - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - return site.uncategorizedimages(total=total) - - -@deprecated('Site.uncategorizedpages()', since='3.0.20200609') -def UnCategorizedPageGenerator(total: int = 100, # pragma: no cover - site: OPT_SITE_TYPE = None - ) -> Iterable['pywikibot.page.Page']: - """ - DEPRECATED. Uncategorized page generator. - - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - return site.uncategorizedpages(total=total) - - -@deprecated('Site.uncategorizedtemplates()', since='3.0.20200609') -def UnCategorizedTemplateGenerator(total: int = 100, # pragma: no cover - site: OPT_SITE_TYPE = None - ) -> Iterable['pywikibot.page.Page']: - """ - DEPRECATED. Uncategorized template generator. - - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - return site.uncategorizedtemplates(total=total) - - -@deprecated('Site.lonelypages()', since='3.0.20200609') -def LonelyPagesPageGenerator(total: Optional[int] = None, # pragma: no cover - site: OPT_SITE_TYPE = None - ) -> Iterable['pywikibot.page.Page']: - """ - DEPRECATED. Lonely page generator. - - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - return site.lonelypages(total=total) - - -@deprecated('Site.unwatchedpages()', since='3.0.20200609') -def UnwatchedPagesPageGenerator(total: Optional[int] = None, - site: OPT_SITE_TYPE = None - ) -> Iterable['pywikibot.page.Page']: - """ - DEPRECATED. Unwatched page generator. - - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - return site.unwatchedpages(total=total) - - -@deprecated('Site.pages_with_property()', since='3.0.20200609') -def page_with_property_generator(name: str, # pragma: no cover - total: Optional[int] = None, - site: OPT_SITE_TYPE = None - ) -> Iterable['pywikibot.page.Page']: - """ - Special:PagesWithProperty page generator. - - :param name: Property name of pages to be retrieved - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - return site.pages_with_property(name, total=total) - - def AncientPagesPageGenerator(total: int = 100, # pragma: no cover site: OPT_SITE_TYPE = None ) -> Iterator['pywikibot.page.Page']: @@ -2470,21 +2272,6 @@ return (page for page, _ in site.ancientpages(total=total))
-@deprecated('Site.deadendpages()', since='3.0.20200609') -def DeadendPagesPageGenerator(total: int = 100, # pragma: no cover - site: OPT_SITE_TYPE = None - ) -> Iterable['pywikibot.page.Page']: - """ - DEPRECATED. Dead-end page generator. - - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - return site.deadendpages(total=total) - - def LongPagesPageGenerator(total: int = 100, site: OPT_SITE_TYPE = None ) -> Iterator['pywikibot.page.Page']: @@ -2513,83 +2300,6 @@ return (page for page, _ in site.shortpages(total=total))
-@deprecated('Site.randompages()', since='3.0.20200609') -def RandomPageGenerator(total: Optional[int] = None, # pragma: no cover - site: OPT_SITE_TYPE = None, - namespaces: Optional[ - Sequence[NAMESPACE_OR_STR_TYPE]] = None - ) -> Iterable['pywikibot.page.Page']: - """ - DEPRECATED. Random page generator. - - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - return site.randompages(total=total, namespaces=namespaces) - - -@deprecated('Site.randompages()', since='3.0.20200609') -def RandomRedirectPageGenerator(total: Optional[int] = None, - site: OPT_SITE_TYPE = None, - namespaces: Optional[ - Sequence[NAMESPACE_OR_STR_TYPE]] = None - ) -> Iterable['pywikibot.page.Page']: - """ - DEPRECATED. Random redirect generator. - - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - return site.randompages(total=total, namespaces=namespaces, - redirects=True) - - -@deprecated('Site.exturlusage()', since='3.0.20200609') -def LinksearchPageGenerator(url: str, - namespaces: Optional[List[int]] = None, - total: Optional[int] = None, - site: OPT_SITE_TYPE = None, - protocol: Optional[str] = None - ) -> Iterable['pywikibot.page.Page']: - """DEPRECATED. Yield all pages that link to a certain URL. - - :param url: The URL to search for (with ot without the protocol prefix); - this may include a '*' as a wildcard, only at the start of the - hostname - :param namespaces: list of namespace numbers to fetch contribs from - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results - :param protocol: Protocol to search for, likely http or https, http by - default. Full list shown on Special:LinkSearch wikipage - """ - if site is None: - site = pywikibot.Site() - return site.exturlusage(url, namespaces=namespaces, protocol=protocol, - total=total, content=False) - - -@deprecated('Site.search()', since='3.0.20200609') -def SearchPageGenerator(query: str, # pragma: no cover - total: Optional[int] = None, - namespaces: Optional[ - Sequence[NAMESPACE_OR_STR_TYPE]] = None, - site: OPT_SITE_TYPE = None - ) -> Iterable['pywikibot.page.Page']: - """ - DEPRECATED. Yield pages from the MediaWiki internal search engine. - - :param total: Maximum number of pages to retrieve in total - :param site: Site for generator results. - """ - if site is None: - site = pywikibot.Site() - return site.search(query, total=total, namespaces=namespaces) - - def LiveRCPageGenerator(site: OPT_SITE_TYPE = None, total: Optional[int] = None ) -> Iterator['pywikibot.page.Page']: diff --git a/scripts/archive/imagecopy.py b/scripts/archive/imagecopy.py index d4646b4..7e35eec 100755 --- a/scripts/archive/imagecopy.py +++ b/scripts/archive/imagecopy.py @@ -312,7 +312,7 @@ pywikibot.showDiff(self.imagePage.get(), imtxt + addTemplate) self.imagePage.put(imtxt + addTemplate, comment=commentText)
- self.gen = pagegenerators.FileLinksGenerator(self.imagePage) + self.gen = self.imagePage.usingPages() self.preloadingGen = pagegenerators.PreloadingGenerator(self.gen)
moveSummary = i18n.twtranslate( diff --git a/scripts/archive/imagecopy_self.py b/scripts/archive/imagecopy_self.py index 44a9b5a..57d9f83 100755 --- a/scripts/archive/imagecopy_self.py +++ b/scripts/archive/imagecopy_self.py @@ -1001,7 +1001,7 @@ def replaceUsage(self, imagepage, filename): """Replace all usage if image is uploaded under a different name.""" if imagepage.title(with_ns=False) != filename: - gen = pagegenerators.FileLinksGenerator(imagepage) + gen = imagepage.usingPages() preloadingGen = pagegenerators.PreloadingGenerator(gen)
moveSummary = i18n.twtranslate( diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py index 31d0f0f..f195ffe 100644 --- a/tests/pagegenerators_tests.py +++ b/tests/pagegenerators_tests.py @@ -22,7 +22,7 @@ PreloadingGenerator, WikibaseItemFilterPageGenerator, ) -from pywikibot.tools import has_module, suppress_warnings +from pywikibot.tools import has_module from tests import join_data_path from tests.aspects import ( DefaultSiteTestCase, @@ -34,13 +34,6 @@ from tests.tools_tests import GeneratorIntersectTestCase
-LINKSEARCH_MSG = (r'.*pywikibot.pagegenerators.LinksearchPageGenerator .*' - r'is deprecated for .*; use Site.exturlusage') - -PAGES_ID_GEN_MSG = (r'.*pywikibot.pagegenerators.PagesFromPageidGenerator .*' - r'is deprecated for .*; use site.load_pages_from_pageids') - - en_wp_page_titles = ( # just a bunch of randomly selected titles for English Wikipedia tests 'Eastern Sayan', @@ -209,21 +202,6 @@ self.titles = [self.base_title.format(i) for i in range(1, 11)]
-class TestPagesFromPageidGenerator(BasetitleTestCase): - - """Test PagesFromPageidGenerator method.""" - - def test_PagesFromPageidGenerator(self): - """Test PagesFromPageidGenerator.""" - gen_pages = pagegenerators.PagesFromTitlesGenerator(self.titles, - self.site) - pageids = [page.pageid for page in gen_pages] - - with suppress_warnings(PAGES_ID_GEN_MSG, category=FutureWarning): - gen = pagegenerators.PagesFromPageidGenerator(pageids, self.site) - self.assertPageTitlesEqual(gen, self.titles) - - class TestCategoryFilterPageGenerator(BasetitleTestCase):
"""Test CategoryFilterPageGenerator method.""" @@ -1671,55 +1649,6 @@ self.assertIn(key, rcinfo.keys())
-class TestLinksearchPageGenerator(TestCase): - - """Tests for pagegenerators.LinksearchPageGenerator.""" - - family = 'wikipedia' - code = 'en' - - def test_weblink(self): - """Test -weblink.""" - cases = (('wikipedia.org', 'http://wikipedia.org'), - ('en.wikipedia.org', 'http://en.wikipedia.org'), - ('https://fr.wikipedia.org', 'https://fr.wikipedia.org'), - ('ftp://*', 'ftp://')) - - for search, expected in cases: - gf = pagegenerators.GeneratorFactory(site=self.site) - gf.handle_arg('-weblink:{}'.format(search)) - gf.handle_arg('-ns:2') - gf.handle_arg('-limit:1') - gen = gf.getCombinedGenerator() - genlist = list(gen) - self.assertLength(genlist, 1) - - page = genlist[0] - self.assertIsInstance(page, pywikibot.Page) - self.assertTrue(page.exists()) - self.assertEqual(page.namespace(), 2) - self.assertIn(expected, page.text) - - def test_double_opposite_protocols(self): - """Test LinksearchPageGenerator with two opposite protocols.""" - with suppress_warnings(LINKSEARCH_MSG, category=FutureWarning): - with self.assertRaises(ValueError): - pagegenerators.LinksearchPageGenerator( - 'http://w.wiki', - protocol='https', - site=self.site) - - def test_double_same_protocols(self): - """Test LinksearchPageGenerator with two same protocols.""" - with suppress_warnings(LINKSEARCH_MSG, category=FutureWarning): - gen = pagegenerators.LinksearchPageGenerator('https://w.wiki', - protocol='https', - site=self.site, - total=1) - self.assertIsInstance(gen, pywikibot.data.api.PageGenerator) - self.assertLength(list(gen), 1) - - if __name__ == '__main__': # pragma: no cover with suppress(SystemExit): unittest.main()
pywikibot-commits@lists.wikimedia.org