From d709ee00a7ed1ac84e23f5f45f4b21331cd3fb47 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Mon, 3 Sep 2012 22:41:48 -0400 Subject: [PATCH] Better handling when we are blocked from editing . --- earwigbot/exceptions.py | 3 ++- earwigbot/wiki/page.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/earwigbot/exceptions.py b/earwigbot/exceptions.py index 61adf29..c8389aa 100644 --- a/earwigbot/exceptions.py +++ b/earwigbot/exceptions.py @@ -169,7 +169,8 @@ class PermissionsError(EditError): We tried to do something we don't have permission to, like trying to delete a page as a non-admin, or trying to edit a page without login information - and AssertEdit enabled. + and AssertEdit enabled. This will also be raised if we have been blocked + from editing. Raised by :py:meth:`Page.edit ` and :py:meth:`Page.add_section `. diff --git a/earwigbot/wiki/page.py b/earwigbot/wiki/page.py index 7e30cb3..93a881b 100644 --- a/earwigbot/wiki/page.py +++ b/earwigbot/wiki/page.py @@ -400,6 +400,15 @@ class Page(CopyvioMixIn): elif error.code in ["emptypage", "emptynewsection"]: raise exceptions.NoContentError(error.info) + elif error.code == "blocked": + if tries > 0 or not all(self.site._login_info): + raise exceptions.PermissionsError(error.info) + else: + # Perhaps we are blocked from being logged-out? Try to log in: + self.site._login(self.site._login_info) + self._token = None # Need a new token; old one is invalid now + return self._edit(params=params, tries=1) + elif error.code == "contenttoobig": raise exceptions.ContentTooBigError(error.info)