jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/693528 )
Change subject: Revert "[cleanup] Remove deprecated BaseSite namespace shortcuts" ......................................................................
Revert "[cleanup] Remove deprecated BaseSite namespace shortcuts"
This reverts commit beae2099293055abde3d766ec6b4eecd3f8f26f1.
Reason for revert: missing FutureWarning
Change-Id: I32fb84857a2fb6381fc1a1100294780f117dd90d --- M pywikibot/site/_basesite.py M tests/site_tests.py 2 files changed, 46 insertions(+), 0 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site/_basesite.py b/pywikibot/site/_basesite.py index d462376..eecc0d9 100644 --- a/pywikibot/site/_basesite.py +++ b/pywikibot/site/_basesite.py @@ -22,6 +22,7 @@ from pywikibot.tools import ( ComparableMixin, SelfCallString, + deprecated, first_upper, normalize_username, remove_last_args, @@ -407,6 +408,39 @@ name2 = first_upper(name2) return name1 == name2
+ # namespace shortcuts for backwards-compatibility + + @deprecated('namespaces.SPECIAL.custom_name', since='20160407') + def special_namespace(self): + """Return local name for the Special: namespace.""" + return self.namespace(-1) + + @deprecated('namespaces.FILE.custom_name', since='20160407') + def image_namespace(self): + """Return local name for the File namespace.""" + return self.namespace(6) + + @deprecated('namespaces.MEDIAWIKI.custom_name', since='20160407') + def mediawiki_namespace(self): + """Return local name for the MediaWiki namespace.""" + return self.namespace(8) + + @deprecated('namespaces.TEMPLATE.custom_name', since='20160407') + def template_namespace(self): + """Return local name for the Template namespace.""" + return self.namespace(10) + + @deprecated('namespaces.CATEGORY.custom_name', since='20160407') + def category_namespace(self): + """Return local name for the Category namespace.""" + return self.namespace(14) + + @deprecated('list(namespaces.CATEGORY)', since='20150829', + future_warning=True) + def category_namespaces(self): # pragma: no cover + """Return names for the Category namespace.""" + return list(self.namespace(14, all=True)) + # site-specific formatting preferences
def category_on_one_line(self): diff --git a/tests/site_tests.py b/tests/site_tests.py index 94c1067..d4b2721 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -85,6 +85,18 @@ self.assertFalse(page.isRedirectPage()) self.assertOneDeprecation()
+ def test_namespace_shortcuts(self): + """Test namespace shortcuts.""" + self.assertEqual(self.site.image_namespace(), self.site.namespace(6)) + self.assertEqual(self.site.mediawiki_namespace(), + self.site.namespace(8)) + self.assertEqual(self.site.template_namespace(), + self.site.namespace(10)) + self.assertEqual(self.site.category_namespace(), + self.site.namespace(14)) + self.assertEqual(self.site.category_namespaces(), + list(self.site.namespace(14, all=True))) +
class TestSiteDryDeprecatedFunctions(DefaultDrySiteTestCase, DeprecationTestCase):
pywikibot-commits@lists.wikimedia.org