Revision: 8149
Author: xqt
Date: 2010-05-06 07:21:16 +0000 (Thu, 06 May 2010)
Log Message:
-----------
site.search(): yield only the given number of pages
page.categories(): enable api depending of a parameter which is True per default.
Documtentation added: pls be aware the api call returns also cats included by templates
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2010-05-06 05:46:59 UTC (rev 8148)
+++ trunk/pywikipedia/wikipedia.py 2010-05-06 07:21:16 UTC (rev 8149)
@@ -2165,19 +2165,14 @@
- def categories(self, get_redirect=False, force_api=False):
- """Return a list of categories that the article is in.
-
- This will retrieve the page text to do its work, so it can raise
- the same exceptions that are raised by the get() method.
-
- The return value is a list of Category objects, one for each of the
- category links in the page text.
+ def categories(self, get_redirect=False, api=True):
+ """Return a list of Category objects that the article is in.
+ Please be aware: the api call returns also categies which are included
+ by templates. This differs to the old non-api code. If you need only
+ these categories which are in the page text please use getCategoryLinks
+ (or set api=False but this could be deprecated in future).
"""
- # Note: This reads via api call if there is not page content
- # or page content already exist and force_api=True
- if not self.site().has_api() or \
- hasattr(self, '_contents') and not force_api:
+ if not (self.site().has_api() and api):
try:
category_links_to_return =
getCategoryLinks(self.get(get_redirect=get_redirect), self.site())
except NoPage:
@@ -5701,7 +5696,7 @@
params['srnamespace'] = namespaces
offset = 0
- while True:
+ while offset < number:
params['sroffset'] = offset
data = query.GetData(params, self)['query']
if 'error' in data:
Show replies by date