本文整理汇总了Python中MoinMoin.PageEditor.PageEditor.saveText方法的典型用法代码示例。如果您正苦于以下问题:Python PageEditor.saveText方法的具体用法?Python PageEditor.saveText怎么用?Python PageEditor.saveText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoinMoin.PageEditor.PageEditor
的用法示例。
在下文中一共展示了PageEditor.saveText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mainloop
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def mainloop(self):
self.init_request()
request = self.request
request.user.may = IAmRoot()
request.cfg.mail_enabled = False
for root, dirs, files in os.walk(self.options.file_dir):
files.sort()
for filename in files:
pagename = self.options.page + filename_function(filename)
#print "Pushing %r as %r" % (filename, pagename)
p = PageEditor(request, pagename, do_editor_backup=0, uid_override=self.options.author, do_revision_backup=0)
if p.exists():
if filename != files[-1]:
continue
else:
p = PageEditor(request, pagename, do_editor_backup=0, uid_override=self.options.author)
fileObj = open(os.path.join(root, filename), 'rb')
try:
acl = ""
if self.options.acl:
acl = "#acl %s\n" % (self.options.acl, )
p.saveText(acl + "#format irc\n" + decodeLinewise(fileObj.read()), 0)
except PageEditor.Unchanged, e:
pass
except PageEditor.SaveError, e:
print "Got %r" % (e, )
fileObj.close()
示例2: group_del
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def group_del(request, grouppage, accounts):
_ = request.getText
success, msg = check_grouppage(request, grouppage)
if not success:
raise GroupException(msg + "(%s)" % (grouppage))
members = request.groups[grouppage].members | request.groups[grouppage].member_groups
for name in accounts:
if name not in members:
raise GroupException(name + _(' not in group: ') + grouppage)
page = PageEditor(request, grouppage)
pagetext = page.get_raw_body()
newtext = _group_del(request, pagetext, accounts)
msg = page.saveText(newtext, 0,
comment="Deleted from group: " +
', '.join(accounts))
newmembers = request.groups[grouppage].members | request.groups[grouppage].member_groups
if not newmembers == members - set(accounts):
msg = page.saveText(pagetext, 0,
comment="Reverting due to problems in group operation.")
raise GroupException(_('Delete unsuccessful for unknown reasons.'))
return True, msg
示例3: create_page
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def create_page(request, pagename, content, do_editor_backup=False):
""" create a page with some content """
# make sure there is nothing already there:
nuke_page(request, pagename)
# now create from scratch:
page = PageEditor(request, pagename, do_editor_backup=do_editor_backup)
page.saveText(content, 0)
return page
示例4: append_page
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def append_page(request, pagename, content, do_editor_backup=False):
""" appends some conetent to an existing page """
# reads the raw text of the existing page
raw = Page(request, pagename).get_raw_body()
# adds the new content to the old
content = "%s\n%s\n"% (raw, content)
page = PageEditor(request, pagename, do_editor_backup=do_editor_backup)
page.saveText(content, 0)
return page
示例5: rename
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def rename(self):
""" Rename pagename and return the new page """
_ = self.request.getText
form = self.request.form
# Require a valid ticket. Make outside attacks harder by
# requiring two full HTTP transactions
if not wikiutil.checkTicket(form['ticket'][0]):
self.error = _('Please use the interactive user interface to rename pages!')
return
# Get new name from form and normalize.
comment = form.get('comment', [u''])[0]
newpagename = form.get('newpagename')[0]
newpagename = self.request.normalizePagename(newpagename)
# Name might be empty after normalization. To save translation
# work for this extreme case, we just use "EmptyName".
if not newpagename:
newpagename = "EmptyName"
# Valid new name
newpage = PageEditor(self.request, newpagename)
# Check whether a page with the new name already exists
if newpage.exists(includeDeleted=1):
return self.pageExistsError(newpagename)
# Get old page text
savetext = self.page.get_raw_body()
oldpath = self.page.getPagePath(check_create=0)
newpath = newpage.getPagePath(check_create=0)
# Rename page
# NOTE: might fail if another process created newpagename just
# NOW, while you read this comment. Rename is atomic for files -
# but for directories, rename will fail if the directory
# exists. We should have global edit-lock to avoid this.
# See http://docs.python.org/lib/os-file-dir.html
try:
os.rename(oldpath, newpath)
self.newpage = newpage
self.error = None
# Save page text with a comment about the old name
savetext = u"## page was renamed from %s\n%s" % (self.pagename, savetext)
newpage.saveText(savetext, 0, comment=comment)
except OSError, err:
# Try to understand what happened. Maybe its better to check
# the error code, but I just reused the available code above...
if newpage.exists(includeDeleted=1):
return self.pageExistsError(newpagename)
else:
self.error = _('Could not rename page because of file system'
' error: %s.') % unicode(err)
示例6: execute
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def execute(pagename, request):
"""
Handle action=IntraFarmCopy
"""
if not request.user.may.read(pagename):
Page(request, pagename).send_page()
return
# Which local farm wiki - assume team for now
to_wiki_url = COPY_TO_WIKI_URL
# New page name
to_wiki_pagename = '%s%s' % (COPY_TO_PREFIX, pagename)
# create page at local wiki if it doesn't exist
to_request = ScriptContext(to_wiki_url)
# login this user remotely
to_uid = user.getUserId(to_request, request.user.name)
to_user = user.User(to_request, id=to_uid, name=request.user.name, password=request.user.password, auth_method="moin")
to_request.user = to_user
try:
page = Page(to_request, to_wiki_pagename)
except:
return action_error(u'Error accessing destination page')
if not page.exists():
pe = PageEditor(to_request, to_wiki_pagename)
# make initial revision pointer to original
try:
pe.saveText(u'[[%s:%s]]' % (request.cfg.interwikiname, pagename), 0, comment="Automated IntraFarmCopy pointing to original page")
except pe.Unchanged:
return action_error(u'Could not save initial page')
except pe.AccessDenied:
return action_error(u'Could not acquire credentials')
# make next revision content of this page
try:
pe.saveText(Page(request, pagename).get_raw_body(), 0, comment="Automated IntraFarmCopy importing contents from original page at [[%s:%s]]" % (request.cfg.interwikiname, pagename))
except pe.Unchanged:
return action_error(u'Could not save destination page text')
# send attachments over
attachments = AttachFile._get_files(request, pagename)
for attachname in attachments:
filename = AttachFile.getFilename(request, pagename, attachname)
if not os.path.isfile(filename):
continue
to_filename = AttachFile.getFilename(to_request, to_wiki_pagename, attachname)
shutil.copyfile(filename, to_filename)
AttachFile._addLogEntry(to_request, 'ATTNEW', to_wiki_pagename, attachname)
# redirect user to view new page in other wiki
request.http_redirect('%s%s' % (to_wiki_url, to_wiki_pagename))
return
else:
return action_error(u'Destination page already exists!')
示例7: write_homepage
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def write_homepage(self, account, homepage_text):
# writes the homepage
if account.exists() and not account.disabled and not Page(self.request, account.name).exists():
userhomepage = PageEditor(self.request, account.name)
try:
userhomepage.saveText(homepage_text, 0)
print "INFO homepage for %s created." % account.name
except userhomepage.Unchanged:
print "You did not change the page content, not saved!"
except userhomepage.NoAdmin:
print "You don't have enough rights to create the %s page" % account.name
else:
print "INFO homepage for %s already exists or account is disabled or user does not exist." % account.name
示例8: _remove_user_from_team
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def _remove_user_from_team(u, team, cfg):
acl_request = u._request
acl_request.user = user.User(acl_request, None, cfg.openidrp_acl_admin)
pe = PageEditor(acl_request, team + cfg.openidrp_acl_page_postfix)
acl_text = pe.get_raw_body()
logging.log(logging.INFO, "ACL Page content: " + acl_text)
# does ACL want uid, name, username, auth_username?
p = re.compile(ur"^ \* %s" % u.name, re.MULTILINE)
if p.search(acl_text):
logging.log(logging.INFO, "found user %s in acl, removing..." % u.name)
acl_text = acl_text.replace(" * %s\n" % u.name, "")
try:
pe.saveText(acl_text, 0)
except PageEditor.EmptyPage:
pe.deletePage()
示例9: testCreateDictAndDeleteDictPage
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def testCreateDictAndDeleteDictPage(self):
"""
simple test if it is possible to delete a Dict page after creation
"""
become_trusted(self.request)
pagename = u'SomeDict'
page = PageEditor(self.request, pagename, do_editor_backup=0)
body = u"This is an example text"
page.saveText(body, 0)
success_i, result = page.deletePage()
expected = u'Page "SomeDict" was successfully deleted!'
assert result == expected
示例10: xmlrpc_putPage
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def xmlrpc_putPage(self, pagename, pagetext):
"""
save a page / change a page to a new text
@param pagename: the page name (unicode or utf-8)
@param pagetext: the new page text (content, unicode or utf-8)
@rtype: bool
@return: True on success
"""
pagename = self._instr(pagename)
pagename = wikiutil.normalize_pagename(pagename, self.cfg)
if not pagename:
return xmlrpclib.Fault("INVALID", "pagename can't be empty")
# check ACLs
if not self.request.user.may.write(pagename):
return xmlrpclib.Fault(1, "You are not allowed to edit this page")
page = PageEditor(self.request, pagename, do_editor_backup=0)
try:
if self.version == 2:
newtext = self._instr(pagetext)
elif self.version == 1:
newtext = self._inlob(pagetext)
msg = page.saveText(newtext, 0)
except page.SaveError, msg:
logging.error("SaveError: %s" % msg)
return xmlrpclib.Fault(1, "%s" % msg)
示例11: execute
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def execute(pagename, request):
request.headers["Content-Type"] = "text/plain; charset=ascii"
if request.environ['REQUEST_METHOD'] != 'POST':
return
form = values_to_form(request.values)
content = form.get('content', [None])[0]
if not content:
sendfault(request, "Missing page content")
return
pagename = normalize_pagename(pagename, request.cfg)
if not pagename:
sendfault(request, "No page name entered")
return
if not request.user.may.write(pagename):
sendfault(request, "You are not allowed to edit this page")
return
page = PageEditor(request, pagename)
if page.exists():
sendfault(request, "Page already exists.")
return
msg = ""
try:
msg = page.saveText(content, 0)
except page.SaveError, msg:
sendfault(request, "Failed to save page: %s" % pagename)
return
示例12: do_action
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def do_action(self):
""" Load """
status = False
_ = self._
form = self.form
request = self.request
comment = form.get('comment', [u''])[0]
comment = wikiutil.clean_input(comment)
filename = form.get('file__filename__')
rename = form.get('rename', [''])[0].strip()
if rename:
target = rename
else:
target = filename
target = AttachFile.preprocess_filename(target)
target = wikiutil.clean_input(target)
if target:
filecontent = form['file'][0]
if hasattr(filecontent, 'read'): # a file-like object
filecontent = filecontent.read() # XXX reads complete file into memory!
filecontent = wikiutil.decodeUnknownInput(filecontent)
self.pagename = target
pg = PageEditor(request, self.pagename)
try:
msg = pg.saveText(filecontent, 0, comment=comment)
status = True
except pg.EditConflict, e:
msg = e.message
except pg.SaveError, msg:
msg = unicode(msg)
示例13: ownPutPage
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def ownPutPage(request, pagename, pagetext):
if not request.user.may.write(pagename):
return False
page = PageEditor(request, pagename)
try:
msg = page.saveText(pagetext, 0)
except page.SaveError, msg:
pass
示例14: savetext
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def savetext(request, pagename, newtext, **kw):
page = PageEditor(request, pagename)
try:
msg = page.saveText(newtext, 0, **kw)
except page.Unchanged:
msg = u'Unchanged'
return msg
示例15: _addLocalWords
# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import saveText [as 别名]
def _addLocalWords(request):
from MoinMoin.PageEditor import PageEditor
# get the new words as a string (if any are marked at all)
try:
newwords = request.form.getlist('newwords')
except KeyError:
# no new words checked
return
newwords = u' '.join(newwords)
# get the page contents
lsw_page = PageEditor(request, request.cfg.page_local_spelling_words)
words = lsw_page.get_raw_body()
# add the words to the page and save it
if words and words[-1] != '\n':
words = words + '\n'
lsw_page.saveText(words + '\n' + newwords, 0)