jenkins-bot has submitted this change and it was merged.
Change subject: Change Site.ns_index() return type from int to Namespace
......................................................................
Change Site.ns_index() return type from int to Namespace
Adds Namespace operators mod, add, sub to support
existing use of returned value in algorithms.
Change-Id: Iffe4d65ac4bd9ed7f76ec22922baae18a8428ebb
---
M pywikibot/page.py
M pywikibot/site.py
2 files changed, 19 insertions(+), 6 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 5228395..01fbf23 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2709,7 +2709,7 @@
elif self.site.property_namespace.id == ns:
self._namespace = self.site.property_namespace
else:
- raise ValueError('%r: Namespace "%d" is not valid'
+ raise ValueError('%r: Namespace "%r" is not valid'
% (self.site, ns))
# .site forces a parse of the Link title to determine site
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 8cf9f60..126ba80 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -317,6 +317,15 @@
"""Compare whether two namespace objects are not equal."""
return not self.__eq__(other)
+ def __mod__(self, other):
+ return self.id.__mod__(other)
+
+ def __sub__(self, other):
+ return -(other) + self.id
+
+ def __add__(self, other):
+ return other + self.id
+
def _cmpkey(self):
"""Return the ID as a comparison key."""
return self.id
@@ -635,11 +644,15 @@
return self._iw_sites[prefix][1]
def ns_index(self, namespace):
- """Given a namespace name, return its int index, or None if invalid."""
- for ns in self.namespaces():
- if namespace.lower() in [name.lower()
- for name in self.namespaces()[ns]]:
- return ns
+ """
+ Return the Namespace for a given namespace name.
+
+ @param namespace: name
+ @type namespace: unicode
+ @return: The matching Namespace object on this Site
+ @rtype: Namespace, or None if invalid
+ """
+ return Namespace.lookup_name(namespace, self.namespaces)
# for backwards-compatibility
getNamespaceIndex = redirect_func(ns_index, old_name='getNamespaceIndex',
--
To view, visit https://gerrit.wikimedia.org/r/170714
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iffe4d65ac4bd9ed7f76ec22922baae18a8428ebb
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits