本文整理汇总了Python中MoinMoin.PageEditor.PageEditor类的典型用法代码示例。如果您正苦于以下问题:Python PageEditor类的具体用法?Python PageEditor怎么用?Python PageEditor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PageEditor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: xmlrpc_revertPage
def xmlrpc_revertPage(self, pagename, revision):
"""
Revert a page to previous revision
This is mainly intended to be used by the jabber bot.
@param pagename: the page name (unicode or utf-8)
@param revision: revision to revert to
@rtype: bool
@return: True on success
"""
pagename = self._instr(pagename)
if not self.request.user.may.write(pagename):
return xmlrpclib.Fault(1, "You are not allowed to edit this page")
rev = int(self._instr(revision))
editor = PageEditor(self.request, pagename, do_editor_backup=0)
try:
editor.revertPage(rev)
except PageEditor.SaveError, error:
return xmlrpclib.Fault(1, "Revert failed: %s" % (str(error), ))
示例2: do_action
def do_action(self):
""" Rename this page to "pagename" """
_ = self._
form = self.form
newpagename = form.get('newpagename', [u''])[0]
newpagename = self.request.normalizePagename(newpagename)
comment = form.get('comment', [u''])[0]
comment = wikiutil.clean_input(comment)
self.page = PageEditor(self.request, self.pagename)
success, msgs = self.page.renamePage(newpagename, comment)
rename_subpages = 0
if 'rename_subpages' in form:
try:
rename_subpages = int(form['rename_subpages'][0])
except:
pass
if rename_subpages and self.subpages:
for name in self.subpages:
self.page = PageEditor(self.request, name)
new_subpagename = name.replace(self.pagename, newpagename, 1)
success_i, msg = self.page.renamePage(new_subpagename, comment)
msgs = "%s %s" % (msgs, msg)
self.newpagename = newpagename # keep there for finish
return success, msgs
示例3: do_addattachment
def do_addattachment(self, zipname, filename, pagename, author=u"Scripting Subsystem", comment=u""):
"""
Installs an attachment
@param pagename: Page where the file is attached. Or in 2.0, the file itself.
@param zipname: Filename of the attachment from the zip file
@param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
"""
if self.request.user.may.write(pagename):
_ = self.request.getText
attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1)
filename = wikiutil.taintfilename(filename)
zipname = wikiutil.taintfilename(zipname)
target = os.path.join(attachments, filename)
page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
rev = page.current_rev()
path = page.getPagePath(check_create=0)
if not os.path.exists(target):
self._extractToFile(zipname, target)
if os.path.exists(target):
os.chmod(target, config.umask )
action = 'ATTNEW'
edit_logfile_append(self, pagename, path, rev, action, logname='edit-log',
comment=u'%(filename)s' % {"filename": filename}, author=author)
self.msg += u"%(filename)s attached \n" % {"filename": filename}
else:
self.msg += u"%(filename)s not attached \n" % {"filename": filename}
else:
self.msg += u"action add attachment: not enough rights - nothing done \n"
示例4: xmlrpc_putPage
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)
示例5: execute
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
示例6: do_action
def do_action(self):
""" Delete pagename """
form = self.form
comment = form.get('comment', [u''])[0]
comment = wikiutil.clean_input(comment)
# Create a page editor that does not do editor backups, because
# delete generates a "deleted" version of the page.
self.page = PageEditor(self.request, self.pagename, do_editor_backup=0)
success, msgs = self.page.deletePage(comment)
delete_subpages = 0
if 'delete_subpages' in form:
try:
delete_subpages = int(form['delete_subpages'][0])
except:
pass
if delete_subpages and self.subpages:
for name in self.subpages:
self.page = PageEditor(self.request, name, do_editor_backup=0)
success_i, msg = self.page.deletePage(comment)
msgs = "%s %s" % (msgs, msg)
return success, msgs
示例7: do_delattachment
def do_delattachment(self, filename, pagename, author=u"Scripting Subsystem", comment=u""):
"""
Removes an attachment
@param pagename: Page where the file is attached. Or in 2.0, the file itself.
@param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
"""
if self.request.user.may.write(pagename):
_ = self.request.getText
attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1)
filename = wikiutil.taintfilename(filename)
target = os.path.join(attachments, filename)
page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
rev = page.current_rev()
path = page.getPagePath(check_create=0)
if os.path.exists(target):
os.remove(target)
action = 'ATTDEL'
edit_logfile_append(self, pagename, path, rev, action, logname='edit-log',
comment=u'%(filename)s' % {"filename": filename}, author=author)
self.msg += u"%(filename)s removed \n" % {"filename": filename}
else:
self.msg += u"%(filename)s does not exist \n" % {"filename": filename}
else:
self.msg += u"action delete attachment: not enough rights - nothing done \n"
示例8: mainloop
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()
示例9: save
def save(self, editor, newtext, rev, **kw):
request = self.request
username = request.user.name
pagename = editor.page_name
if grouppage_autocreate and username == pagename:
# create group pages when a user saves his own homepage
for page in grouppages:
grouppagename = "%s/%s" % (username, page)
grouppage = Page(request, grouppagename)
if not grouppage.exists():
text = """\
#acl %(username)s:read,write,delete,revert
* %(username)s
""" % locals()
editor = PageEditor(request, grouppagename)
editor._write_file(text)
parts = pagename.split('/')
if len(parts) == 2:
subpage = parts[1]
if subpage in grouppages and not self.admin(pagename):
return False
# No problem to save if my base class agrees
return Permissions.save(self, editor, newtext, rev, **kw)
示例10: do_action
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)
示例11: do_action
def do_action(self):
""" copy this page to "pagename" """
_ = self._
# Currently we only check TextCha for upload (this is what spammers ususally do),
# but it could be extended to more/all attachment write access
if not TextCha(self.request).check_answer_from_form():
return status, _('TextCha: Wrong answer! Go back and try again...')
form = self.form
newpagename = form.get('newpagename', u'')
newpagename = wikiutil.normalize_pagename(newpagename, self.cfg)
comment = form.get('comment', u'')
comment = wikiutil.clean_input(comment)
self.page = PageEditor(self.request, self.pagename)
success, msgs = self.page.copyPage(newpagename, comment)
copy_subpages = 0
try:
copy_subpages = int(form['copy_subpages'])
except:
pass
if copy_subpages and self.subpages or (not self.users_subpages and self.subpages):
for name in self.subpages:
self.page = PageEditor(self.request, name)
new_subpagename = name.replace(self.pagename, newpagename, 1)
success_i, msg = self.page.copyPage(new_subpagename, comment)
msgs = "%s %s" % (msgs, msg)
self.newpagename = newpagename # keep there for finish
return success, msgs
示例12: execute
def execute(pagename, request):
form = values_to_form(request.values)
template = form.get('template', [''])[0]
if template and not request.page.exists():
template_page = wikiutil.unquoteWikiname(template)
if request.user.may.read(template_page):
editor = PageEditor(request, template_page)
editor.user = request.user
text = editor.get_raw_body()
editor.page_name = pagename
request.page.set_raw_body(editor._expand_variables(text))
newdata = parse_text(request, request.page,
request.page.get_raw_body())
# Add prototype metas (^ something::\s*$) as keys
protokeys = [y for x,y in dl_proto_re.findall(text)]
for key in protokeys:
if not (key in newdata[pagename].get('out', dict()) or
key in newdata[pagename].get('meta', dict())):
newdata[pagename].setdefault('meta', dict())[key] = list()
# I'll lie, cheat, do anything to make this work
newdata[pagename]['saved'] = True
# Add the template metas to cache so that they'd show
request.graphdata.cacheset(pagename, newdata.get(pagename, dict()))
MetaEdit.execute(pagename, request)
示例13: group_del
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
示例14: test_acls
def test_acls(self):
p = PageEditor(self.request, self.pagename)
oldacl = p.getACL(self.request).acl
assert not self.request.user.may.admin(p.page_name)
newacl = parseACL(self.request, self.newtext).acl
assert newacl != oldacl
py.test.raises(PageEditor.NoAdmin, p.saveText, self.newtext, 0)
示例15: nuke_page
def nuke_page(request, pagename):
""" completely delete a page, everything in the pagedir """
page = PageEditor(request, pagename, do_editor_backup=False)
page.deletePage()
# really get rid of everything there:
fpath = page.getPagePath(check_create=0)
shutil.rmtree(fpath, True)