Revision: 6948
Author: valhallasw
Date: 2009-06-10 19:41:57 +0000 (Wed, 10 Jun 2009)
Log Message:
-----------
* Extended version of put() that allows a maximum number of attempts to be
given. If the maximum is reached, a MaxTriesExceededError exception is thrown
* I have not touched put_async: its call signature is not the same as put() and
I don't know why - I'm staying on the safe side for that :)
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2009-06-09 18:40:41 UTC (rev 6947)
+++ trunk/pywikipedia/wikipedia.py 2009-06-10 19:41:57 UTC (rev 6948)
@@ -208,6 +208,9 @@
self.length = arg
self.limit = arg2,
+class MaxTriesExceededError(PageNotSaved):
+ """Saving the page has failed because the maximum number of attempts has
been reached"""
+
class ServerError(Error):
"""Got unexpected server response"""
@@ -1359,7 +1362,7 @@
force, callback))
def put(self, newtext, comment=None, watchArticle=None, minorEdit=True,
- force=False, sysop=False, botflag=True):
+ force=False, sysop=False, botflag=True, maxTries=-1):
"""Save the page with the contents of the first argument as the text.
Optional parameters:
@@ -1369,6 +1372,7 @@
watchlist (if None, leave watchlist status unchanged)
minorEdit: mark this edit as minor if True
force: ignore botMayEdit() setting.
+ maxTries: the maximum amount of save attempts. -1 for infinite.
"""
# Login
try:
@@ -1417,7 +1421,7 @@
comment = encodeEsperantoX(comment)
return self._putPage(newtext, comment, watchArticle, minorEdit,
- newPage, self.site().getToken(sysop = sysop),
sysop = sysop, botflag=botflag)
+ newPage, self.site().getToken(sysop = sysop),
sysop = sysop, botflag=botflag, maxTries=maxTries)
def _encodeArg(self, arg, msgForError):
"""Encode an ascii string/Unicode string to the site's encoding"""
@@ -1435,7 +1439,7 @@
def _putPage(self, text, comment=None, watchArticle=False, minorEdit=True,
newPage=False, token=None, newToken=False, sysop=False,
- captcha=None, botflag=True):
+ captcha=None, botflag=True, maxTries=-1):
"""Upload 'text' as new content of Page by filling out the edit form.
Don't use this directly, use put() instead.
@@ -1490,6 +1494,9 @@
retry_attempt = 1
dblagged = False
while True:
+ if (maxTries == 0):
+ raise MaxTriesExceededError()
+ maxTries -= 1
# Check whether we are not too quickly after the previous
# putPage, and wait a bit until the interval is acceptable
if not dblagged:
_______________________________________________
Pywikipedia-svn mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn