http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10100
Revision: 10100 Author: xqt Date: 2012-04-09 12:20:35 +0000 (Mon, 09 Apr 2012) Log Message: ----------- enable single number or single str/unicode for namespace filter
Modified Paths: -------------- trunk/pywikipedia/pagegenerators.py
Modified: trunk/pywikipedia/pagegenerators.py =================================================================== --- trunk/pywikipedia/pagegenerators.py 2012-04-09 12:00:15 UTC (rev 10099) +++ trunk/pywikipedia/pagegenerators.py 2012-04-09 12:20:35 UTC (rev 10100) @@ -1026,14 +1026,17 @@ of the given namespaces.
The namespace list can contain both integers (namespace numbers) and - strings/unicode strings (namespace names). + strings/unicode strings (namespace names). Namespace may also be a single + number or a single string. """ # convert namespace names to namespace numbers if site is None: site = pywikibot.getSite() + if isinstance(namespace, (int, basestring)): + namespace = [namespace] for i in xrange(len(namespaces)): ns = namespaces[i] - if isinstance(ns, unicode) or isinstance(ns, str): + if isinstance(ns, basestring): index = site.getNamespaceIndex(ns) if index is None: raise ValueError(u'Unknown namespace: %s' % ns)
pywikipedia-svn@lists.wikimedia.org