r4096 pywikipedia - Code Review archive

Repository:pywikipedia
Revision:r4095‎ | r4096 | r4097 >
Date:14:17, 23 August 2007
Author:valhallasw
Status:old
Tags:
Comment:
Page.put() now obeys {{bots}} and {{nobots}} if not asked to ignore them (using the force=True parameter).
Using _flush(), get_throttle is now dropped at the end of the run.
Modified paths:
  • /trunk/pywikipedia/wikipedia.py (modified) (history)

Diff [purge]

Index: trunk/pywikipedia/wikipedia.py
@@ -1,4 +1,4 @@
2 -## -*- coding: utf-8 -*-
 2+## -*- coding: utf-8 -*-
33 """
44 Library to get and put pages on a MediaWiki.
55
@@ -1030,13 +1030,13 @@
10311031 yield Page(site, fileLink)
10321032
10331033 def put_async(self, newtext,
1034 - comment=None, watchArticle=None, minorEdit=True):
 1034+ comment=None, watchArticle=None, minorEdit=True, force=False):
10351035 """Asynchronous version of put (takes the same arguments), which
10361036 places pages on a queue to be saved by a daemon thread.
10371037 """
1038 - page_put_queue.put((self, newtext, comment, watchArticle, minorEdit))
 1038+ page_put_queue.put((self, newtext, comment, watchArticle, minorEdit, force))
10391039
1040 - def put(self, newtext, comment=None, watchArticle = None, minorEdit = True):
 1040+ def put(self, newtext, comment=None, watchArticle = None, minorEdit = True, force=False):
10411041 """Replace the new page with the contents of the first argument.
10421042 The second argument is a string that is to be used as the
10431043 summary for the modification
@@ -1051,6 +1051,11 @@
10521052 #except NoPage:
10531053 # pass
10541054
 1055+ # Determine if we are allowed to edit
 1056+ if not force:
 1057+ if not self.botMayEdit():
 1058+ raise LockedPage(u'Not allowed to edit %s because of a restricting template' % self.aslink())
 1059+
10551060 # If there is an unchecked edit restriction, we need to load the page
10561061 if self._editrestriction:
10571062 output(u'Page %s is semi-protected. Getting edit page to find out if we are allowed to edit.' % self.aslink())
@@ -4641,13 +4646,13 @@
46424647 Daemon that takes pages from the queue and tries to save them on the wiki.
46434648 '''
46444649 while True:
4645 - page, newtext, comment, watchArticle, minorEdit = page_put_queue.get()
 4650+ page, newtext, comment, watchArticle, minorEdit, force = page_put_queue.get()
46464651 if page is None:
46474652 # needed for compatibility with Python 2.3 and 2.4
46484653 # in 2.5, we could use the Queue's task_done() and join() methods
46494654 return
46504655 try:
4651 - page.put(newtext, comment, watchArticle, minorEdit)
 4656+ page.put(newtext, comment, watchArticle, minorEdit, force)
46524657 except SpamfilterError, ex:
46534658 output(u"Saving page [[%s]] prevented by spam filter: %s"
46544659 % (page.title(), ex.url))
@@ -4683,7 +4688,7 @@
46844689 remaining = datetime.timedelta(seconds=(page_put_queue.qsize()+1) * config.put_throttle)
46854690 output('Waiting for %i pages to be put. Estimated time remaining: %s' % (page_put_queue.qsize()+1, remaining))
46864691
4687 - page_put_queue.put((None, None, None, None, None))
 4692+ page_put_queue.put((None, None, None, None, None, None))
46884693
46894694 while(_putthread.isAlive()):
46904695 try:
@@ -4694,6 +4699,7 @@
46954700 ['yes', 'no'], ['y', 'N'], 'N')
46964701 if answer in ['y', 'Y']:
46974702 return
 4703+ get_throttle.drop()
46984704
46994705 import atexit
47004706 atexit.register(_flush)

Status & tagging log