[Pywikipedia-l] SVN: [6340] branches/rewrite/pywikibot

russblau at svn.wikimedia.org russblau at svn.wikimedia.org
Tue Feb 10 16:02:13 UTC 2009


Revision: 6340
Author:   russblau
Date:     2009-02-10 16:02:13 +0000 (Tue, 10 Feb 2009)

Log Message:
-----------
improve error-catching on page save

Modified Paths:
--------------
    branches/rewrite/pywikibot/page.py
    branches/rewrite/pywikibot/site.py

Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py	2009-02-09 14:41:27 UTC (rev 6339)
+++ branches/rewrite/pywikibot/page.py	2009-02-10 16:02:13 UTC (rev 6340)
@@ -673,16 +673,25 @@
 
     def _save(self, comment, minor, watch, unwatch, callback):
         err = None
+        link = self.title(asLink=True)
         try:
             done = self.site().editpage(self, summary=comment, minor=minor,
                                         watch=watch, unwatch=unwatch)
             if not done:
-                pywikibot.output("Page %s not saved" % self.title(asLink=True),
+                pywikibot.output(u"Page %s not saved" % link,
                                  level=pywikibot.WARNING)
+                raise pywikibot.PageNotSaved(link)
             else:
-                pywikibot.output("Page %s saved" % self.title(asLink=True))
+                pywikibot.output(u"Page %s saved" % link)
+        except pywikibot.LockedPage, err:
+            # re-raise the LockedPage exception so that calling program
+            # can re-try if appropriate
+            if not callback:
+                raise
+        # TODO: other "expected" error types to catch?
         except pywikibot.Error, err:
-            logger.exception("Error saving page %s\n" % self.title(asLink=True))
+            logger.exception(u"Error saving page %s\n" % link)
+            pywikibot.output(u"")
         if callback:
             callback(self, err)
 

Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py	2009-02-09 14:41:27 UTC (rev 6339)
+++ branches/rewrite/pywikibot/site.py	2009-02-10 16:02:13 UTC (rev 6340)
@@ -2194,6 +2194,8 @@
 
                 if err.code == "editconflict":
                     raise EditConflict(self._ep_errors[err.code] % errdata)
+                if err.code == "protectedpage":
+                    raise LockedPage(errdata['title'])
                 if err.code in self._ep_errors:
                     raise Error(self._ep_errors[err.code] % errdata)
                 logger.debug("editpage: Unexpected error code '%s' received."





More information about the Pywikipedia-l mailing list