本文整理汇总了Python中MoinMoin.Page.Page.get_raw_body方法的典型用法代码示例。如果您正苦于以下问题:Python Page.get_raw_body方法的具体用法?Python Page.get_raw_body怎么用?Python Page.get_raw_body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoinMoin.Page.Page
的用法示例。
在下文中一共展示了Page.get_raw_body方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: xmlrpc_getPageVersion
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def xmlrpc_getPageVersion(self, pagename, rev):
""" Get raw text from specific revision of pagename
@param pagename: pagename (utf-8)
@param rev: revision number (int)
@rtype: str
@return: utf-8 encoded page data
"""
pagename = self._instr(pagename)
# User may read page?
if not self.request.user.may.read(pagename):
return self.notAllowedFault()
if rev != None:
page = Page(self.request, pagename, rev=rev)
else:
page = Page(self.request, pagename)
# Non existing page?
if not page.exists():
return self.noSuchPageFault()
# Return page raw text
if self.version == 2:
return self._outstr(page.get_raw_body())
elif self.version == 1:
return self._outlob(page.get_raw_body())
示例2: retrain
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def retrain(self, request):
self.close_spamdb()
if os.path.exists(self.spam_db):
os.unlink(self.spam_db)
self.open_spamdb(request)
nham = nspam = 0
for url in Group(request, "HamPages").members():
scheme, netloc, path, params, query, frag = urlparse.urlparse(url)
rev = 0
for pair in query.split("&"):
key, val = pair.split("=")
if key == "rev":
raw = int(val)
break
pg = Page(request, path[1:], rev=rev)
self.sbayes.train_ham(pg.get_raw_body())
nham += 1
for url in Group(request, "SpamPages").members():
scheme, netloc, path, params, query, frag = urlparse.urlparse(url)
rev = 0
for pair in query.split("&"):
key, val = pair.split("=")
if key == "rev":
raw = int(val)
break
pg = Page(request, path[1:], rev=rev)
self.sbayes.train_spam(pg.get_raw_body())
nspam += 1
self.close_spamdb()
return (nham, nspam)
示例3: execute
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def execute(macro, args):
_ = macro.request.getText
pagename = args or 'FortuneCookies'
if macro.request.user.may.read(pagename):
page = Page(macro.request, pagename)
raw = page.get_raw_body()
else:
raw = ""
# this selects lines looking like a list item
# !!! TODO: make multi-line quotes possible (optionally split by "----" or something)
quotes = raw.splitlines()
quotes = [quote.strip() for quote in quotes]
quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
if not quotes:
return (macro.formatter.highlight(1) +
_('No quotes on %(pagename)s.') % {'pagename': pagename} +
macro.formatter.highlight(0))
quote = random.choice(quotes)
page.set_raw_body(quote, 1)
out = StringIO.StringIO()
macro.request.redirect(out)
page.send_page(macro.request, content_only=1, content_id="RandomQuote_%s" % wikiutil.quoteWikinameFS(page.page_name) )
quote = out.getvalue()
macro.request.redirect()
return quote
示例4: include
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def include(self, name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
# content contains the included file name
_ = self.request.getText
# Limit the number of documents that can be included
if self.num_includes < self.max_includes:
self.num_includes += 1
else:
lines = [_("**Maximum number of allowed includes exceeded**")]
state_machine.insert_input(lines, 'MoinDirectives')
return
if len(content):
pagename = content[0]
page = Page(page_name=pagename, request=self.request)
if not self.request.user.may.read(pagename):
lines = [_("**You are not allowed to read the page: %s**") % (pagename, )]
else:
if page.exists():
text = page.get_raw_body()
lines = text.split('\n')
# Remove the "#format rst" line
if lines[0].startswith("#format"):
del lines[0]
else:
lines = [_("**Could not find the referenced page: %s**") % (pagename, )]
# Insert the text from the included document and then continue parsing
state_machine.insert_input(lines, 'MoinDirectives')
return
示例5: copypage
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def copypage(self, request, rootdir, pagename):
""" quick and dirty! """
pagedir = os.path.join(rootdir, 'pages', wikiutil.quoteWikinameFS(pagename))
os.makedirs(pagedir)
# write a "current" file with content "00000001"
revstr = '%08d' % 1
cf = os.path.join(pagedir, 'current')
file(cf, 'w').write(revstr+'\n')
# create a single revision 00000001
revdir = os.path.join(pagedir, 'revisions')
os.makedirs(revdir)
tf = os.path.join(revdir, revstr)
p = Page(request, pagename)
text = p.get_raw_body().replace("\n", "\r\n")
codecs.open(tf, 'wb', config.charset).write(text)
source_dir = AttachFile.getAttachDir(request, pagename)
if os.path.exists(source_dir):
dest_dir = os.path.join(pagedir, "attachments")
os.makedirs(dest_dir)
for filename in os.listdir(source_dir):
source_file = os.path.join(source_dir, filename)
dest_file = os.path.join(dest_dir, filename)
shutil.copyfile(source_file, dest_file)
示例6: include
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def include(self, name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
# content contains the included file name
_ = self.request.getText
if len(content):
if content[0] in self.included_documents:
lines = [_("**Duplicate included files are not permitted**")]
state_machine.insert_input(lines, 'MoinDirectives')
return
self.included_documents.append(content[0])
page = Page(page_name = content[0], request = self.request)
if page.exists():
text = page.get_raw_body()
lines = text.split('\n')
# Remove the "#format rst" line
if lines[0].startswith("#format"):
del lines[0]
else:
lines = [_("**Could not find the referenced page: %s**") % (content[0],)]
# Insert the text from the included document and then continue
# parsing
state_machine.insert_input(lines, 'MoinDirectives')
return
示例7: packagePages
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def packagePages(self, pagelist, filename, function):
""" Puts pages from pagelist into filename and calls function on them on installation. """
request = self.request
try:
os.remove(filename)
except OSError:
pass
zf = zipfile.ZipFile(filename, "w", COMPRESSION_LEVEL)
cnt = 0
script = [packLine(['MoinMoinPackage', '1']), ]
for pagename in pagelist:
pagename = pagename.strip()
page = Page(request, pagename)
if page.exists():
cnt += 1
script.append(packLine([function, str(cnt), pagename]))
timestamp = wikiutil.version2timestamp(page.mtime_usecs())
zi = zipfile.ZipInfo(filename=str(cnt), date_time=datetime.fromtimestamp(timestamp).timetuple()[:6])
zi.compress_type = COMPRESSION_LEVEL
zf.writestr(zi, page.get_raw_body().encode("utf-8"))
else:
#import sys
#print >>sys.stderr, "Could not find the page %s." % pagename.encode("utf-8")
pass
script += [packLine(['Print', 'Installed MoinMaster page bundle %s.' % os.path.basename(filename)])]
zf.writestr(MOIN_PACKAGE_FILE, u"\n".join(script).encode("utf-8"))
zf.close()
示例8: macro_RandomQuote
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def macro_RandomQuote(macro, pagename=u'FortuneCookies'):
_ = macro.request.getText
if macro.request.user.may.read(pagename):
page = Page(macro.request, pagename)
raw = page.get_raw_body()
else:
raw = ""
# this selects lines looking like a list item
# !!! TODO: make multi-line quotes possible (optionally split by "----" or something)
quotes = raw.splitlines()
quotes = [quote.strip() for quote in quotes]
quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
if not quotes:
return (macro.formatter.highlight(1) +
_('No quotes on %(pagename)s.') % {'pagename': pagename} +
macro.formatter.highlight(0))
quote = random.choice(quotes)
page.set_raw_body(quote, 1)
quote = macro.request.redirectedOutput(page.send_page,
content_only=1, content_id="RandomQuote")
return quote
示例9: collectpackage
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def collectpackage(self, pagelist, fileobject, pkgname="", include_attachments=False):
""" Expects a list of pages as an argument, and fileobject to be an open
file object, which a zipfile will get written to.
@param pagelist: pages to package
@param fileobject: open file object to write to
@param pkgname: optional file name, to prevent self packaging
@rtype: string or None
@return: error message, if one happened
@rtype: boolean
@param include_attachments: True if you want attachments collected
"""
_ = self.request.getText
COMPRESSION_LEVEL = zipfile.ZIP_DEFLATED
pages = []
for pagename in pagelist:
pagename = wikiutil.normalize_pagename(pagename, self.request.cfg)
if pagename:
page = Page(self.request, pagename)
if page.exists() and self.request.user.may.read(pagename):
pages.append(page)
if not pages:
return (_('No pages like "%s"!') % wikiutil.escape(pagelist))
# Set zipfile output
zf = zipfile.ZipFile(fileobject, "w", COMPRESSION_LEVEL)
cnt = 0
userid = user.getUserIdentification(self.request)
script = [packLine(['MoinMoinPackage', '1']), ]
for page in pages:
cnt += 1
files = _get_files(self.request, page.page_name)
script.append(packLine(["AddRevision", str(cnt), page.page_name, userid, "Created by the PackagePages action."]))
timestamp = wikiutil.version2timestamp(page.mtime_usecs())
# avoid getting strange exceptions from zipfile in case of pre-1980 timestamps
nineteeneighty = (10 * 365 + 3) * 24 * 3600 # 1970 + 10y + 3d
timestamp = max(nineteeneighty, timestamp) # zip can not store timestamps before 1980
zi = zipfile.ZipInfo(filename=str(cnt), date_time=datetime.fromtimestamp(timestamp).timetuple()[:6])
zi.compress_type = COMPRESSION_LEVEL
zf.writestr(zi, page.get_raw_body().encode("utf-8"))
if include_attachments:
for attname in files:
if attname != pkgname:
cnt += 1
zipname = "%d_attachment" % cnt
script.append(packLine(["AddAttachment", zipname, attname, page.page_name, userid, "Created by the PackagePages action."]))
filename = AttachFile.getFilename(self.request, page.page_name, attname)
zf.write(filename, zipname)
script += [packLine(['Print', 'Thank you for using PackagePages!'])]
zf.writestr(MOIN_PACKAGE_FILE, u"\n".join(script).encode("utf-8"))
zf.close()
示例10: load_template
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def load_template(request, name):
if not request.user.may.read(name):
raise InviteException("You are not allowed to read template page '%s'." % name)
page = Page(request, name)
if not page.exists():
raise InviteException("Template page '%s' does not exist." % name)
return page.get_raw_body()
示例11: save
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def save(self, editor, newtext, rev, **kw):
BLACKLISTPAGES = ["BadContent", "LocalBadContent"]
if not editor.page_name in BLACKLISTPAGES:
request = editor.request
# Start timing of antispam operation
request.clock.start('antispam')
blacklist = []
latest_mtime = 0
for pn in BLACKLISTPAGES:
do_update = (pn != "LocalBadContent" and
request.cfg.interwikiname != 'MoinMaster') # MoinMaster wiki shall not fetch updates from itself
blacklist_mtime, blacklist_entries = getblacklist(request, pn, do_update)
blacklist += blacklist_entries
latest_mtime = max(latest_mtime, blacklist_mtime)
if blacklist:
invalid_cache = not getattr(request.cfg.cache, "antispam_blacklist", None)
if invalid_cache or request.cfg.cache.antispam_blacklist[0] < latest_mtime:
mmblcache = []
for blacklist_re in blacklist:
try:
mmblcache.append(re.compile(blacklist_re, re.I))
except re.error, err:
logging.error("Error in regex '%s': %s. Please check the pages %s." % (
blacklist_re,
str(err),
', '.join(BLACKLISTPAGES)))
request.cfg.cache.antispam_blacklist = (latest_mtime, mmblcache)
from MoinMoin.Page import Page
oldtext = ""
if rev > 0: # rev is the revision of the old page
page = Page(request, editor.page_name, rev=rev)
oldtext = page.get_raw_body()
newset = frozenset(newtext.splitlines(1))
oldset = frozenset(oldtext.splitlines(1))
difference = newset - oldset
addedtext = kw.get('comment', u'') + u''.join(difference)
for blacklist_re in request.cfg.cache.antispam_blacklist[1]:
match = blacklist_re.search(addedtext)
if match:
# Log error and raise SaveError, PageEditor should handle this.
_ = editor.request.getText
msg = _('Sorry, can not save page because "%(content)s" is not allowed in this wiki.') % {
'content': wikiutil.escape(match.group())
}
logging.info(msg)
raise editor.SaveError(msg)
request.clock.stop('antispam')
示例12: _retrieve_items
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def _retrieve_items(self, dict_name):
# XXX in Moin 2.0 regex should not be used instead use DOM
# tree to extract dict values. Also it should be possible to
# convert dict values to different markups (wiki-markup,
# creole...).
#
# Note that formatter which extracts dictionary from a
# page was developed. See
# http://hg.moinmo.in/moin/1.9-groups-dmilajevs/file/982f706482e7/MoinMoin/formatter/dicts.py
page = Page(self.request, dict_name)
text = page.get_raw_body()
return dict([match.groups() for match in self._dict_page_parse_regex.finditer(text)])
示例13: save
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def save(self, editor, newtext, rev, **kw):
BLACKLISTPAGES = ["BadContent", "LocalBadContent"]
if not editor.page_name in BLACKLISTPAGES:
request = editor.request
# Start timing of antispam operation
request.clock.start('antispam')
blacklist = []
invalidate_cache = not getattr(request.cfg, "_mmblcache", None)
for pn in BLACKLISTPAGES:
do_update = (pn != "LocalBadContent")
invalidate_cache_necessary, blacklist_entries = getblacklist(request, pn, do_update)
blacklist += blacklist_entries
invalidate_cache |= invalidate_cache_necessary
if blacklist:
if invalidate_cache:
mmblcache = []
for blacklist_re in blacklist:
try:
mmblcache.append(re.compile(blacklist_re, re.I))
except re.error, err:
dprint("Error in regex '%s': %s. Please check the pages %s." % (blacklist_re, str(err), ', '.join(BLACKLISTPAGES)))
continue
request.cfg._mmblcache = mmblcache
from MoinMoin.Page import Page
oldtext = ""
if rev > 0: # rev is the revision of the old page
page = Page(request, editor.page_name, rev=rev)
oldtext = page.get_raw_body()
newset = sets.ImmutableSet(newtext.splitlines(1))
oldset = sets.ImmutableSet(oldtext.splitlines(1))
difference = newset.difference(oldset)
addedtext = ''.join(difference)
for blacklist_re in request.cfg._mmblcache:
match = blacklist_re.search(addedtext)
if match:
# Log error and raise SaveError, PageEditor
# should handle this.
_ = editor.request.getText
msg = _('Sorry, can not save page because "%(content)s"'
' is not allowed in this wiki.') % {
'content': match.group()
}
dprint(msg)
raise editor.SaveError(msg)
request.clock.stop('antispam')
示例14: prepend_to_wiki_page
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def prepend_to_wiki_page(self, page_uri, heading, content):
old_content = ''
wiki_page = Page(self.request, page_uri)
#if exists, get old page content
if(wiki_page.exists()):
old_content = wiki_page.get_raw_body()
pagecontent = """\
== %(heading)s ==
%(content)s
%(old_content)s
""" % {'heading': heading, 'content': content, 'old_content': old_content }
return(PageEditor(self.request, page_uri).saveText(pagecontent, 0))
示例15: force_revert
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import get_raw_body [as 别名]
def force_revert(self, pagename, request):
rev = int(request.form['rev'][0])
revstr = '%08d' % rev
oldpg = Page(request, pagename, rev=rev)
pg = PageEditor(request, pagename)
_ = request.getText
msg = _("Thank you for your changes. Your attention to detail is appreciated.")
try:
pg._write_file(oldpg.get_raw_body(),
action="SAVE/REVERT",
extra=revstr)
pg.clean_acl_cache()
except pg.SaveError, msg:
pass