jenkins-bot has submitted this change and it was merged.
Change subject: (bugfix) Test whether a method is supported by mediawiki version ......................................................................
(bugfix) Test whether a method is supported by mediawiki version
The given assert in some generators does not work because Site.versionnumber is a function, not an attribute holding the value.
The assert function is replaced by the decorator "need_version" to require a certain mediawiki version number.
Change-Id: I40460e83189954a7b2d0b37e5198084993d1a5a4 --- M pywikibot/site.py 1 file changed, 24 insertions(+), 3 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py index bbacf31..7b00999 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -723,6 +723,27 @@ return decorator
+def need_version(number): + """ Decorator to require a certain mediawiki version number. + + @param number: the mw version number required + @return: a decorator to make sure the requirement is statisfied when + the decorated function is called. + """ + def decorator(fn): + def callee(self, *args, **kwargs): + if self.versionnumber() < number: + raise NotImplementedError( + u'Method or function "%s"\n' + u"isn't implemented in mediawiki version < %d" + % (fn.__name__, number)) + return fn(self, *args, **kwargs) + callee.__name__ = fn.__name__ + callee.__doc__ = fn.__doc__ + return callee + return decorator + + class APISite(BaseSite): """API interface to MediaWiki site.
@@ -3593,27 +3614,27 @@ step=step, total=total) return wigen
+ @need_version(18) def broken_redirects(self, step=None, total=None): """Yield Pages without language links from Special:BrokenRedirects.""" - assert self.versionnumber >= 18 brgen = self._generator(api.PageGenerator, type_arg="querypage", gqppage="BrokenRedirects", step=step, total=total) return brgen
+ @need_version(18) def double_redirects(self, step=None, total=None): """Yield Pages without language links from Special:BrokenRedirects.""" - assert self.versionnumber >= 18 drgen = self._generator(api.PageGenerator, type_arg="querypage", gqppage="DoubleRedirects", step=step, total=total) return drgen
+ @need_version(18) def redirectpages(self, step=None, total=None): """Yield redirect pages from Special:ListRedirects.""" - assert self.versionnumber >= 18 lrgen = self._generator(api.PageGenerator, type_arg="querypage", gqppage="Listredirects",
pywikibot-commits@lists.wikimedia.org