jenkins-bot has submitted this change and it was merged.
Change subject: Page.namespace() shall return Namespace() for pages in Main ns
......................................................................
Page.namespace() shall return Namespace() for pages in Main ns
This reverts commit 5a612064e70653d4a6dd043c5b727d54cb5193c8
and restores f6556636fd91a13394f7f6412593ae29c238b2b3.
Bug: T104864
Change-Id: I2d91ca1a9772d909874102e0e9149aa5bfd96b62
---
M pywikibot/page.py
1 file changed, 16 insertions(+), 14 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index c0c8294..dc83ae4 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -4873,7 +4873,11 @@
self._source = source or pywikibot.Site()
self._text = text
- self._defaultns = defaultNamespace
+ # See bug T104864, defaultNamespace might have been deleted.
+ try:
+ self._defaultns = self._source.namespaces[defaultNamespace]
+ except KeyError:
+ self._defaultns = defaultNamespace
# preprocess text (these changes aren't site-dependent)
# First remove anchor, which is stored unchanged, if there is one
@@ -4988,7 +4992,7 @@
while u":" in t:
# Initial colon indicates main namespace rather than default
if t.startswith(u":"):
- self._namespace = 0
+ self._namespace = self._site.namespaces[0]
# remove the colon but continue processing
# remove any subsequent whitespace
t = t.lstrip(u":").lstrip(u" ")
@@ -5146,7 +5150,8 @@
def canonical_title(self):
"""Return full page title, including localized
namespace."""
- if self.namespace:
+ # Avoid that ':' will be added to the title for Main ns.
+ if self.namespace != Namespace.MAIN:
return "%s:%s" % (self.site.namespace(self.namespace),
self.title)
else:
@@ -5162,26 +5167,23 @@
@raise pywikibot.Error: no corresponding namespace is found in onsite
"""
- ns_id = self.namespace
- ns = self.site.namespaces[ns_id]
-
if onsite is None:
- namespace = ns.canonical_name
+ name = self.namespace.canonical_name
else:
# look for corresponding ns in onsite by name comparison
- for alias in ns:
+ for alias in self.namespace:
namespace = onsite.namespaces.lookup_name(alias)
- if namespace:
- namespace = namespace.custom_name
+ if namespace is not None:
+ name = namespace.custom_name
break
else:
# not found
raise pywikibot.Error(
u'No corresponding namespace found for namespace %s on %s.'
- % (self.site.namespaces[ns_id], onsite))
+ % (self.namespace, onsite))
- if namespace:
- return u'%s:%s' % (namespace, self.title)
+ if self.namespace != Namespace.MAIN:
+ return u'%s:%s' % (name, self.title)
else:
return self.title
@@ -5196,7 +5198,7 @@
if onsite is None:
onsite = self._source
title = self.title
- if self.namespace:
+ if self.namespace != Namespace.MAIN:
title = onsite.namespace(self.namespace) + ":" + title
if self.section:
title = title + "#" + self.section
--
To view, visit
https://gerrit.wikimedia.org/r/279948
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2d91ca1a9772d909874102e0e9149aa5bfd96b62
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>