def move(self, new_title, reason='', move_talk=True, no_redirect=False): """Move (rename) page to new_title. If user account is an administrator, specify no_direct as True to not leave a redirect. If user does not have permission to move page, an InsufficientPermission exception is raised. """ if not self.can('move'): raise errors.InsufficientPermission(self) if not self.site.writeapi: return OldPage.move(self, new_title=new_title, reason=reason, move_talk=move_talk) data = {} if move_talk: data['movetalk'] = '1' if no_redirect: data['noredirect'] = '1' result = self.site.api('move', ('from', self.name), to=new_title, token=self.get_token('move'), reason=reason, **data) return result['move']
def save(self, text = u'', summary = u'', minor = False, bot = True): if not self.site.logged_in and self.site.force_login: # Should we really check for this? raise errors.LoginError(self.site) if self.site.blocked: raise errors.UserBlocked(self.site.blocked) if not self.can('edit'): raise errors.ProtectedPageError(self) if not text: text = self.text if not self.site.writeapi: return OldPage.save(self, text = text, summary = summary, minor = False) data = {} if minor: data['minor'] = '1' if not minor: data['notminor'] = '1' if self.last_rev_time: data['basetimestamp'] = time.strftime('%Y%m%d%H%M%S', self.last_rev_time) if self.edit_time: data['starttimestamp'] = time.strftime('%Y%m%d%H%M%S', self.edit_time) if bot: data['bot'] = '1' try: result = self.site.api('edit', title = self.name, text = text, summary = summary, token = self.get_token('edit'), **data) if result['edit'].get('result').lower() == 'failure': raise errors.EditError(self, result['edit']) except errors.APIError, e: if e.code == 'editconflict': raise errors.EditError(self, text, summary, e.info) elif e.code in ('protectedtitle', 'cantcreate', 'cantcreate-anon', 'noimageredirect-anon', 'noimageredirect', 'noedit-anon', 'noedit'): raise errors.ProtectedPageError(self, e.code, e.info) else: raise
def save(self, text=u'', summary=u'', minor=False, bot=True, **kwargs): if not self.site.logged_in and self.site.force_login: # Should we really check for this? raise errors.LoginError(self.site) if self.site.blocked: raise errors.UserBlocked(self.site.blocked) if not self.can('edit'): raise errors.ProtectedPageError(self) if not text: text = self.text if not self.site.writeapi: return OldPage.save(self, text=text, summary=summary, minor=False) data = {} if minor: data['minor'] = '1' if not minor: data['notminor'] = '1' if self.last_rev_time: data['basetimestamp'] = time.strftime('%Y%m%d%H%M%S', self.last_rev_time) if self.edit_time: data['starttimestamp'] = time.strftime('%Y%m%d%H%M%S', self.edit_time) if bot: data['bot'] = '1' data.update(kwargs) def do_edit(): result = self.site.api('edit', title=self.name, text=text, summary=summary, token=self.get_token('edit'), **data) if result['edit'].get('result').lower() == 'failure': raise errors.EditError(self, result['edit']) return result try: result = do_edit() except errors.APIError as e: if e.code == 'badtoken': # Retry, but only once to avoid an infinite loop self.get_token('edit', force=True) try: result = do_edit() except errors.APIError as e: self.handle_edit_error(e, summary) else: self.handle_edit_error(e, summary) if result['edit'] == 'Success': self.last_rev_time = client.parse_timestamp(result['newtimestamp']) return result['edit']
def move(self, new_title, reason = '', move_talk = True, no_redirect = False): if not self.can('move'): raise errors.InsufficientPermission(self) if not self.site.writeapi: return OldPage.move(self, new_title = new_title, reason = reason, move_talk = move_talk) data = {} if move_talk: data['movetalk'] = '1' if no_redirect: data['noredirect'] = '1' result = self.site.api('move', ('from', self.name), to = new_title, token = self.get_token('move'), reason = reason, **data) return result['move']
def save(self, text=u'', summary=u'', minor=False, bot=True, section=None, **kwargs): """Save text of page.""" if not self.site.logged_in and self.site.force_login: # Should we really check for this? raise errors.LoginError(self.site) if self.site.blocked: raise errors.UserBlocked(self.site.blocked) if not self.can('edit'): raise errors.ProtectedPageError(self) if not text: text = self.text if not section: section = self.section if not self.site.writeapi: return OldPage.save(self, text=text, summary=summary, minor=False) data = {} if minor: data['minor'] = '1' if not minor: data['notminor'] = '1' if self.last_rev_time: data['basetimestamp'] = time.strftime('%Y%m%d%H%M%S', self.last_rev_time) if self.edit_time: data['starttimestamp'] = time.strftime('%Y%m%d%H%M%S', self.edit_time) if bot: data['bot'] = '1' if section: data['section'] = section data.update(kwargs) def do_edit(): result = self.site.api('edit', title=self.name, text=text, summary=summary, token=self.get_token('edit'), **data) if result['edit'].get('result').lower() == 'failure': raise errors.EditError(self, result['edit']) return result try: result = do_edit() except errors.APIError, e: if e.code == 'badtoken': # Retry, but only once to avoid an infinite loop self.get_token('edit', force=True) try: result = do_edit() except errors.APIError, e: self.handle_edit_error(e, summary)
def delete(self, reason = '', watch = False, unwatch = False, oldimage = False): if not self.can('delete'): raise errors.InsufficientPermission(self) if not self.site.writeapi: return OldPage.delete(self, reason = reason) data = {} if watch: data['watch'] = '1' if unwatch: data['unwatch'] = '1' if oldimage: data['oldimage'] = oldimage result = self.site.api('delete', title = self.name, token = self.get_token('delete'), reason = reason, **data) return result['delete']