jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] Allow multiple namespaces if available ......................................................................
[FIX] Allow multiple namespaces if available
Some modules don't support multiple namespaces (for example query+allpages) but it's possible that the generator factory sets it to multiple namespaces. This also emits a warning if the namespace is defined for a generator which does not support it.
Bug: T76794 Change-Id: I486d06fa6e03692f7c05725b22319e192b5d62c2 --- M pywikibot/data/api.py 1 file changed, 19 insertions(+), 7 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index cf8ce17..a460313 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -1383,14 +1383,26 @@
""" assert(self.limited_module) # some modules do not have a prefix - if isinstance(namespaces, list): - namespaces = "|".join(str(n) for n in namespaces) - else: - namespaces = str(namespaces) - param = self.site._paraminfo.parameter(self.limited_module, 'namespace') - if param: - self.request[self.prefix + "namespace"] = namespaces + if not param: + pywikibot.warning(u'{0} module does not support a namespace ' + 'parameter'.format(self.limited_module)) + return + + if isinstance(namespaces, basestring): + namespaces = namespaces.split('|') + + try: + iter(namespaces) + except TypeError: + namespaces = [namespaces] + + namespaces = [str(namespace) for namespace in namespaces] + if 'multi' not in param and len(namespaces) != 1: + raise pywikibot.Error(u'{0} module does not support multiple ' + 'namespaces.'.format(self.limited_module)) + + self.request[self.prefix + "namespace"] = namespaces
def _query_continue(self): if all(key not in self.data[self.continue_name]
pywikibot-commits@lists.wikimedia.org