jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/840269 )
Change subject: [IMPR] Simplify APISite.page_can_be_edited ......................................................................
[IMPR] Simplify APISite.page_can_be_edited
Also update documentation and add doctests.
Change-Id: I480393cf2e41a2ed72a31de53d655635dbf34a84 --- M pywikibot/page/_page.py M pywikibot/site/_apisite.py 2 files changed, 21 insertions(+), 6 deletions(-)
Approvals: JJMC89: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page/_page.py b/pywikibot/page/_page.py index 94239b8..065f439 100644 --- a/pywikibot/page/_page.py +++ b/pywikibot/page/_page.py @@ -1056,9 +1056,25 @@ """Determine whether the page can be modified.
Return True if the bot has the permission of needed restriction level - for the given action type. + for the given action type:
- :param action: a valid restriction type like 'edit', 'move' + >>> site = pywikibot.Site('test') + >>> page = pywikibot.Page(site, 'Main Page') + >>> page.has_permission() + False + >>> page.has_permission('move') + False + >>> page.has_permission('invalid') + Traceback (most recent call last): + ... + ValueError: APISite.page_can_be_edited(): Invalid value "invalid" ... + + .. seealso:: :meth:`APISite.page_can_be_edited() + <pywikibot.site._apisite.APISite.page_can_be_edited>` + + + :param action: a valid restriction type like 'edit', 'move'; + default is ``edit``. :raises ValueError: invalid action parameter """ return self.site.page_can_be_edited(self, action) diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py index 2050db3..b5c457f 100644 --- a/pywikibot/site/_apisite.py +++ b/pywikibot/site/_apisite.py @@ -1365,6 +1365,8 @@ Return True if the bot has the permission of needed restriction level for the given action type.
+ .. seealso:: :meth:`page.BasePage.has_permission` (should be preferred) + :param page: a pywikibot.page.BasePage object :param action: a valid restriction type like 'edit', 'move'
@@ -1381,10 +1383,7 @@ 'steward': 'editprotected' } restriction = self.page_restrictions(page).get(action, ('', None))[0] - user_rights = self.userinfo['rights'] - if prot_rights.get(restriction, restriction) in user_rights: - return True - return False + return self.has_right(prot_rights.get(restriction, restriction))
def page_isredirect(self, page: 'pywikibot.page.BasePage') -> bool: """Return True if and only if page is a redirect."""