Revision: 5883
Author: russblau
Date: 2008-09-10 20:29:47 +0000 (Wed, 10 Sep 2008)
Log Message:
-----------
fix "asLink" bug
Modified Paths:
--------------
branches/rewrite/pywikibot/page.py
Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py 2008-09-09 20:25:32 UTC (rev 5882)
+++ branches/rewrite/pywikibot/page.py 2008-09-10 20:29:47 UTC (rev 5883)
@@ -176,14 +176,16 @@
title = urllib.quote(encodedTitle)
if asLink:
if forceInterwiki or (allowInterwiki and
- (self.site().family != pywikibot.default_family
+ (self.site().family.name != pywikibot.default_family
or self.site().code != pywikibot.default_code)):
- if self.site().family != pywikibot.default_family \
+ if self.site().family.name != pywikibot.default_family \
and self.site().family.name != self.site().code:
return u'[[%s:%s:%s]]' % (self.site().family.name,
self.site().code,
self._title)
else:
+ # use this form for sites like commons, where the
+ # code is the same as the family name
return u'[[%s:%s]]' % (self.site().code,
self._title)
elif textlink and (self.isImage() or self.isCategory()):
Revision: 5882
Author: russblau
Date: 2008-09-09 20:25:32 +0000 (Tue, 09 Sep 2008)
Log Message:
-----------
Expand docs.
Modified Paths:
--------------
branches/rewrite/pywikibot/data/api.py
Modified: branches/rewrite/pywikibot/data/api.py
===================================================================
--- branches/rewrite/pywikibot/data/api.py 2008-09-09 14:06:44 UTC (rev 5881)
+++ branches/rewrite/pywikibot/data/api.py 2008-09-09 20:25:32 UTC (rev 5882)
@@ -55,33 +55,28 @@
the dict interface. All attributes must be strings (or unicode). Use
an empty string for parameters that don't require a value (e.g.,
"action=query&...&redirects").
+
+ This is the lowest-level interface to the API, and can be used for any
+ request that a particular site's API supports. See the API documentation
+ (http://www.mediawiki.org/wiki/API) and site-specific settings for
+ details on what parameters are accepted for each request type.
+
+ Returns a dict containing the JSON data returned by the wiki. Normally,
+ one of the dict keys will be equal to the value of the 'action'
+ parameter. Errors are caught and raise an APIError exception.
- @param site: The Site to which the request will be submitted. If not
- supplied, uses the user's configured default Site.
- @param max_retries: (optional) Maximum number of times to retry after
- errors, defaults to 25
- @param retry_wait: (optional) Minimum time to wait after an error,
- defaults to 5 seconds (doubles each retry until max of 120 is
- reached)
- @param format: (optional) Defaults to "json"
-
Example:
>>> r = Request(site=mysite, action="query", meta="userinfo")
>>> # This is equivalent to
>>> # http://{path}/api.php?action=query&meta=userinfo&format=json
- >>> # r.data is undefined until request is submitted
- >>> print r.data
- Traceback (most recent call last):
- ...
- AttributeError: Request instance has no attribute 'data'
>>> # change a parameter
>>> r['meta'] = "userinfo|siteinfo"
>>> # add a new parameter
>>> r['siprop'] = "namespaces"
>>> # note that "uiprop" param gets added automatically
>>> r.params
- {'maxlag': '5', 'format': 'json', 'meta': 'userinfo|siteinfo', 'action': 'query', 'siprop': 'namespaces', 'uiprop': 'blockinfo|hasmsg'}
+ {'action': 'query', 'meta': 'userinfo|siteinfo', 'siprop': 'namespaces'}
>>> data = r.submit()
>>> type(data)
<type 'dict'>
@@ -90,6 +85,15 @@
>>> data[u'query'].keys()
[u'userinfo', u'namespaces']
+ @param site: The Site to which the request will be submitted. If not
+ supplied, uses the user's configured default Site.
+ @param max_retries: (optional) Maximum number of times to retry after
+ errors, defaults to 25
+ @param retry_wait: (optional) Minimum time to wait after an error,
+ defaults to 5 seconds (doubles each retry until max of 120 is
+ reached)
+ @param format: (optional) Defaults to "json"
+
"""
def __init__(self, **kwargs):
try:
@@ -251,7 +255,6 @@
# double the next wait, but do not exceed 120 seconds
self.retry_wait = min(120, self.retry_wait * 2)
-#TODO - refactor all these generator classes into a parent/subclass hierarchy
class QueryGenerator(object):
"""Base class for iterators that handle responses to API action=query.
@@ -263,6 +266,11 @@
iterating that many values. If limit is negative, the limit parameter
will not be passed to the API at all.
+ Most common query types are more efficiently handled by subclasses, but
+ this class can be used directly for custom queries and miscellaneous
+ types (such as "meta=...") that don't return the usual list of pages or
+ links. See the API documentation for specific query options.
+
"""
def __init__(self, **kwargs):
"""
@@ -370,8 +378,6 @@
% (self.__class__.__name__, pagedata.keys(),
self.limit))
pagedata = pagedata.values()
- # for generators, this yields the pages in order of
- # their pageids, not their titles.... FIXME?
else:
logger.debug("%s received %s; limit=%s"
% (self.__class__.__name__, pagedata,
@@ -395,7 +401,13 @@
class PageGenerator(QueryGenerator):
- """Iterator for response to a request of type action=query&generator=foo."""
+ """Iterator for response to a request of type action=query&generator=foo.
+
+ This class can be used for any of the query types that are listed in the
+ API documentation as being able to be used as a generator. Instances of
+ this class iterate Page objects.
+
+ """
def __init__(self, generator, **kwargs):
"""
Required and optional parameters are as for C{Request}, except that
@@ -435,7 +447,7 @@
class CategoryPageGenerator(PageGenerator):
- """Generator that yields Category objects instead of Pages."""
+ """Like PageGenerator, but yields Category objects instead of Pages."""
def result(self, pagedata):
p = PageGenerator.result(self, pagedata)
@@ -443,7 +455,7 @@
class ImagePageGenerator(PageGenerator):
- """Generator that yields ImagePage objects instead of Pages."""
+ """Like PageGenerator, but yields ImagePage objects instead of Pages."""
def result(self, pagedata):
p = PageGenerator.result(self, pagedata)
@@ -454,11 +466,16 @@
class PropertyGenerator(QueryGenerator):
- """Generator for queries of type action=query&property=...
+ """Iterator for queries of type action=query&property=...
- Note that this generator yields one or more dict object(s) corresponding
+ See the API documentation for types of page properties that can be
+ queried.
+
+ This iterator yields one or more dict object(s) corresponding
to each "page" item(s) from the API response; the calling module has to
- decide what to do with the contents of the dict.
+ decide what to do with the contents of the dict. There will be one
+ dict for each page queried via a titles= or ids= parameter (which must
+ be supplied when instantiating this class).
"""
def __init__(self, prop, **kwargs):
@@ -475,8 +492,19 @@
class ListGenerator(QueryGenerator):
- """Iterator for queries with action=query&list=... parameters"""
+ """Iterator for queries of type action=query&list=...
+ See the API documentation for types of lists that can be queried. Lists
+ include both side-wide information (such as 'allpages') and page-specific
+ information (such as 'backlinks').
+
+ This iterator yields a dict object for each member of the list returned
+ by the API, with the format of the dict depending on the particular list
+ command used. For those lists that contain page information, it may be
+ easier to use the PageGenerator class instead, as that will convert the
+ returned information into a Page object.
+
+ """
def __init__(self, listaction, **kwargs):
"""
Required and optional parameters are as for C{Request}, except that
@@ -492,12 +520,12 @@
class LoginManager(login.LoginManager):
"""Supplies getCookie() method to use API interface."""
def getCookie(self, remember=True, captchaId=None, captchaAnswer=None):
- """
- Login to the site.
+ """Login to the site.
Parameters are all ignored.
Returns cookie data if succesful, None otherwise.
+
"""
if hasattr(self, '_waituntil'):
if datetime.now() < self._waituntil:
@@ -528,7 +556,7 @@
def update_page(page, pagedict):
- """Update attributes of Page object page, based on query data in pagequery
+ """Update attributes of Page object page, based on query data in pagedict
@param page: object to be updated
@type page: Page
@@ -554,9 +582,10 @@
for item in pagedict['protection']:
page._protection[item['type']] = item['level'], item['expiry']
+
if __name__ == "__main__":
from pywikibot import Site
- logger.setLevel(logger.DEBUG)
+ logger.setLevel(pywikibot.logging.DEBUG)
mysite = Site("en", "wikipedia")
print "starting test...."
def _test():
Bugs item #1633513, was opened at 2007-01-11 20:20
Message generated for change (Comment added) made by malafaya
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1633513&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: interwiki
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: tuvic (tuvic)
Assigned to: Nobody/Anonymous (nobody)
Summary: Interwiki.py graphs when in autonomous mode
Initial Comment:
The interwiki-bot tries to make graphs when it's in autonomous mode, if you have the option interwiki-graphs switched on.
It shouldn't do that, because it destroys the autonomous behavior.
>>if config.interwiki_graph:<<
on line 745 of the code (r 1.343) should be changed to
>>if config.interwiki_graph and (not globalvar.autonomous):<<
Greetings, Tuvic
----------------------------------------------------------------------
>Comment By: André Malafaya Baptista (malafaya)
Date: 2008-09-09 17:09
Message:
As for me, I find it useful even in autonomous mode.
Sometimes, I just process a full category in autonomous mode and check the
graphs later.
In my opinion, the option of creating graphs in autonomous mode should be
left to the operator (i.e., leave the feature as it is now).
P.S. should this bug be closed? it's been more than 18 months since it was
opened.
----------------------------------------------------------------------
Comment By: tuvic (tuvic)
Date: 2007-01-12 15:20
Message:
Logged In: YES
user_id=1557188
Originator: YES
I'm sorry, I forgot I had put in a little piece of code that first asks
before creating a graph.
So, it doesn't destroy the autonomous mode, but it will use up a lot
(sometimes a gigantic amount) of cpu unnecessary.
It creates graphs while you can't do anything with them at that point, and
most likely the situation will have changed when you run a manual bot the
next time.
Greetings, Tuvic
----------------------------------------------------------------------
Comment By: Daniel Herding (wikipedian)
Date: 2007-01-12 11:50
Message:
Logged In: YES
user_id=880694
Originator: NO
Why does it destroy autonomous behaviour? Creating graphs is done fully
automatic.
I think the real problem here is that creating graphs takes too long.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1633513&group_…
Bugs item #1981134, was opened at 2008-06-01 06:58
Message generated for change (Comment added) made by malafaya
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1981134&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: interwiki
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Mikko Silvonen (silvonen)
Assigned to: Nobody/Anonymous (nobody)
Summary: New languages not sorted correctly
Initial Comment:
Some new languages (myv, ext, hif, gan, kaa, mdf, sah, szl and srn) were added in r5440, but the codes were not added in self.alphabetic_revised and self.alphabetic_lb in the file families/wikipedia_family.py, so these languages are not always sorted correctly.
Another problem: As far as I can see, hif, kaa, sah and szl are sorted incorrectly in self.alphabetic in the file family.py. Shouldn't they be sorted as follows?
fa,
hif (Fiji Hindi),
fo (Froyskt);
pt (Portugus),
kaa (Qaraqalpaqsha),
crh (Qrmtatarca);
ru (),
sah ( / Sakha tyla),
se (Smegiella); and
sl (Slovenina),
szl (lnski),
so (Soomaaliga).
I am attaching a patch for family.py. Sorry, no patch for families/wikipedia_family yet.
----------------------------------------------------------------------
>Comment By: Andr Malafaya Baptista (malafaya)
Date: 2008-09-09 15:08
Message:
Partially corrected in r5881.
Not done:
* Languages hif & srn not listed in
http://meta.wikimedia.org/wiki/Interwiki_sorting_order
* Couldn't find a list for alphabetical_lb
----------------------------------------------------------------------
Comment By: Mikko Silvonen (silvonen)
Date: 2008-06-03 06:27
Message:
Logged In: YES
user_id=127947
Originator: YES
Sorry, but r5500 fixed the problem only for some languages. The new
languages need to be added also in self.alphabetic_revised and
self.alphabetic_lb in families/wikipedia_family.py, where the sorting order
is different. I just didn't have time to propose a patch for this file.
----------------------------------------------------------------------
Comment By: siebrand (siebrand)
Date: 2008-06-02 23:30
Message:
Logged In: YES
user_id=1107255
Originator: NO
Fixed in r...
----------------------------------------------------------------------
Comment By: siebrand (siebrand)
Date: 2008-06-02 23:30
Message:
Logged In: YES
user_id=1107255
Originator: NO
Fixed in r5500
----------------------------------------------------------------------
Comment By: Mikko Silvonen (silvonen)
Date: 2008-06-01 07:30
Message:
Logged In: YES
user_id=127947
Originator: YES
Hmm, I wonder how many errors there are with previously added languages?
At least stq (Seeltersk) is sorted incorrectly in self.alphabetic and
missing from the other tables.
Does anyone have a sorting order test kit?
----------------------------------------------------------------------
Comment By: Mikko Silvonen (silvonen)
Date: 2008-06-01 07:09
Message:
Logged In: YES
user_id=127947
Originator: YES
Also ext is sorted incorrectly in self.alphabetic. I'll upload a corrected
patch.
File Added: family.diff
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1981134&group_…
Bugs item #2070151, was opened at 2008-08-23 20:09
Message generated for change (Comment added) made by nobody
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2070151&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: interwiki
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: ulana merops (spacebirdy)
Assigned to: Nobody/Anonymous (nobody)
Summary: readd om.wiktionary to wiktionary family
Initial Comment:
Dear all, please readd om.wiktionary to the family it had not been closed, and got activity lately. I would like to run my bot there.
Many thanks in advance.
----------------------------------------------------------------------
Comment By: Nobody/Anonymous (nobody)
Date: 2008-09-09 13:47
Message:
Sorry, It was wrongly listed as "Closed" in
http://meta.wikimedia.org/wiki/Proposals_for_closing_projects it is fixed
now, please readd, thanks.
The person who reopened the request only reopened the first and forgot the
second link.
http://meta.wikimedia.org/wiki/Proposals_for_closing_projects/Closure_of_Or…http://meta.wikimedia.org/wiki/Proposals_for_closing_projects
----------------------------------------------------------------------
Comment By: ulana merops (spacebirdy)
Date: 2008-09-07 00:52
Message:
Logged In: YES
user_id=191312
Originator: YES
Please can this be fixed soon, I would like to use my bot there, I have no
idea how I can add it in the script myself, thanks.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2070151&group_…
Bugs item #2083535, was opened at 2008-08-30 06:57
Message generated for change (Comment added) made by malafaya
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2083535&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: interwiki
Group: None
Status: Open
Resolution: None
Priority: 3
Private: No
Submitted By: Purodha B Blissenbach (purodha)
Assigned to: Nobody/Anonymous (nobody)
Summary: interwiki.py note gives wrong count
Initial Comment:
Interwiki.py, when started up, ays something like:
NOTE: Number of pages queued is 0, trying to add 255 more.
If you specify parameters -number:10 and -query:255, it displays "add 255 more", but then only adds 10.
I have not tested that, but likely, limiting -array: will have a similar effect.
So, better interwiki.py should first compute how many pages are to be added this time, then display the figure, instead of doing it the other way round.
----------------------------------------------------------------------
>Comment By: Andr Malafaya Baptista (malafaya)
Date: 2008-09-09 14:05
Message:
I understand it as "TRYING to add 255 more" (sic). It tried to get 255 but
it may get less. That's my interpretation.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2083535&group_…
Bugs item #2086421, was opened at 2008-09-01 09:39
Message generated for change (Comment added) made by malafaya
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2086421&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Alex S.H. Lin (lin4h)
Assigned to: Nobody/Anonymous (nobody)
Summary: unknown reason to remove interwiki link in dewiki
Initial Comment:
Pywikipedia [http] trunk/pywikipedia (r5869, Aug 31 2008, 22:46:50)
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
parameters use -new:120 , -autonomous and -force.
user contributions in http://de.wikipedia.org/wiki/Spezial:Beitr%C3%A4ge/alexbot
some pages in the auto-works could remove some exists page link. Sometime is disambiguation pages, but some pages I checked later, it's not disambiguation page. (see de:Thomas Wolsey http://de.wikipedia.org/w/index.php?title=Thomas_Wolsey&diff=prev&oldid=502… ) And I've no idea why current code could remove this page.
this bug let my de account blocked.
----------------------------------------------------------------------
>Comment By: Andr Malafaya Baptista (malafaya)
Date: 2008-09-09 14:01
Message:
I have no clue. I tried:
interwiki.py -lang:de -force -autonomous Thomas Wolsey
I didn't use -new:120 cause it wouldn't work anymore.
No interwiki was removed (including ru:).
Maybe you got a temporary buggy version?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2086421&group_…
Bugs item #2091286, was opened at 2008-09-03 10:56
Message generated for change (Comment added) made by djbarrett
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2091286&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: General
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: shizhao (wikishizhao)
Assigned to: Nobody/Anonymous (nobody)
Summary: weblinkchecker.py error
Initial Comment:
see:
Exception in thread 中華民國國旗 - http://law.moj.gov.tw/Scripts/Query1A.asp?no=1D0020020&K1=國旗:
Traceback (most recent call last):
File "/usr/lib/python2.5/threading.py", line 486, in __bootstrap_inner
self.run()
File "weblinkchecker.py", line 504, in run
linkChecker = LinkChecker(self.url, HTTPignore = self.HTTPignore)
File "weblinkchecker.py", line 302, in __init__
self.changeUrl(url)
File "weblinkchecker.py", line 357, in changeUrl
self.query = unicode(urllib.quote(self.query.encode(encoding), '=&'))
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 17-18: ordinal not in range(256)
----------------------------------------------------------------------
Comment By: Daniel Barrett (djbarrett)
Date: 2008-09-08 13:33
Message:
I am getting the same error (tuple index out of range) reported by
wikishizhao. It occurs for many URLs.
Platform:
Pywikipedia [http] trunk/pywikipedia (r5880, Sep 07 2008, 21:16:02)
Python 2.4.3 (#1, May 24 2008, 13:57:05)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)]
Example:
Exception while processing URL
http://core3.bsn.endeca.com/wine45/controller.jsp?N=0 in page Advanced
gallery vendor blog
Exception in thread Advanced gallery vendor blog -
http://core3.bsn.endeca.com/wine45/controller.jsp?N=0:
Traceback (most recent call last):
File "/usr/lib64/python2.4/threading.py", line 442, in __bootstrap
self.run()
File "weblinkchecker.py", line 506, in run
ok, message = linkChecker.check()
File "weblinkchecker.py", line 437, in check
msg = error[1]
IndexError: tuple index out of range
----------------------------------------------------------------------
Comment By: shizhao (wikishizhao)
Date: 2008-09-03 11:01
Message:
Logged In: YES
user_id=1853316
Originator: YES
and:
Exception while processing URL
http://sat2.hp.infoseek.co.jp/taiwan/cts.jpg in page 中華電視公司
Exception in thread 中華電視公司 -
http://sat2.hp.infoseek.co.jp/taiwan/cts.jpg:
Traceback (most recent call last):
File "/usr/lib/python2.5/threading.py", line 486, in __bootstrap_inner
self.run()
File "weblinkchecker.py", line 506, in run
ok, message = linkChecker.check()
File "weblinkchecker.py", line 437, in check
msg = error[1]
IndexError: tuple index out of range
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2091286&group_…