本文整理汇总了Python中Sycamore.Page.Page.get_raw_body方法的典型用法代码示例。如果您正苦于以下问题:Python Page.get_raw_body方法的具体用法?Python Page.get_raw_body怎么用?Python Page.get_raw_body使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sycamore.Page.Page
的用法示例。
在下文中一共展示了Page.get_raw_body方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import get_raw_body [as 别名]
def execute(macro, args, formatter=None):
if not formatter:
formatter = macro.formatter
_ = macro.request.getText
pagename = args or 'Fortune Cookies'
page = Page(pagename, macro.request)
raw = page.get_raw_body(fresh=macro.request.set_cache)
if not macro.request.user.may.read(page):
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)
if quote.lower().find("randomquote") == -1:
quote = wikiutil.wikifyString(quote, macro.request, page, strong=True)
quote = wikiutil.stripOuterParagraph(quote)
return quote
示例2: process
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import get_raw_body [as 别名]
def process(self):
if not self.query:
return
# processes the search
enquire = xapian.Enquire(self.text_database)
enquire.set_query(self.query)
t0 = time.time()
matches = self._get_matchset(enquire, self.text_database,
self.p_start_loc, self.num_results+1)
self.estimated_results = matches.get_matches_estimated()
t1 = time.time()
for match in matches:
id = match[xapian.MSET_DOCUMENT].get_value(0)
wiki_name = self.request.config.wiki_name
if config.wiki_farm:
title, wiki_name = get_id(id)
# xapian uses utf-8
title = title.decode('utf-8')
wiki_name = wiki_name.decode('utf-8')
else:
title = get_id(id).decode('utf-8')
page = Page(title, self.request, wiki_name=wiki_name)
if not page.exists():
continue
percentage = match[xapian.MSET_PERCENT]
data = page.get_raw_body()
search_item = searchResult(title, data, percentage,
page.page_name, wiki_name)
self.text_results.append(search_item)
enquire = xapian.Enquire(self.title_database)
enquire.set_query(self.query)
matches = self._get_matchset(enquire, self.text_database,
self.t_start_loc, self.num_results+1)
self.estimated_results += matches.get_matches_estimated()
for match in matches:
id = match[xapian.MSET_DOCUMENT].get_value(0)
wiki_name = self.request.config.wiki_name
if config.wiki_farm:
title, wiki_name = get_id(id)
# xapian uses utf-8
title = title.decode('utf-8')
wiki_name = wiki_name.decode('utf-8')
else:
title = get_id(id).decode('utf-8')
page = Page(title, self.request, wiki_name=wiki_name)
if not page.exists():
continue
percentage = match[xapian.MSET_PERCENT]
data = page.page_name
search_item = searchResult(title, data, percentage,
page.page_name, wiki_name)
self.title_results.append(search_item)
示例3: sendEditor
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import get_raw_body [as 别名]
#.........这里部分代码省略.........
if self.request.user.valid:
text_rows = int(self.request.user.edit_rows)
if form.has_key('cols'):
text_cols = int(form['cols'][0])
if self.request.user.valid:
# possibly update user's pref
if text_rows != self.request.user.edit_rows:
self.request.user.edit_rows = text_rows
self.request.user.save()
else:
text_cols = 80
if self.request.user.valid:
text_cols = int(self.request.user.edit_cols)
# check datestamp (version) of the page our edit is based on
if preview is not None:
# propagate original datestamp
mtime = float(form['datestamp'][0])
# did someone else change the page while we were editing?
conflict_msg = None
if not self.exists():
# page does not exist, are we creating it?
if mtime:
conflict_msg = _('<p>Someone else <b>deleted</b> this '
'page while you were editing!')
elif mtime != self.mtime():
conflict_msg = _('<p>Someone else changed this page while '
'you were editing.')
# merge conflicting versions
allow_conflicts = 1
from Sycamore.util import diff3
savetext = self.get_raw_body()
oldpg = Page(self.page_name, self.request, prev_date=mtime)
original_text = oldpg.get_raw_body()
saved_text = Page(self.page_name, self.request).get_raw_body()
verynewtext, had_conflict = diff3.text_merge(
original_text, saved_text, savetext,
marker1='----- /!\ Edit conflict! Your version: -----\n',
marker2='----- /!\ Edit conflict! Other version: -----\n',
marker3='----- /!\ End of edit conflict -----\n')
if had_conflict and self.request.user.valid and (
self.request.user.id == self.last_edit_info()[1]):
# user pressed back button or did something weird
conflict_msg =None
elif had_conflict:
conflict_msg = _(conflict_msg +
'There was an <b>edit conflict between '
'your changes!</b></p>'
'<p>Please review the conflicts and '
'merge the changes.</p>')
mtime = self.mtime()
self.set_raw_body(verynewtext, 1)
else:
conflict_msg = _(conflict_msg +
'Your changes were sucessfully merged!')
mtime = self.mtime()
self.set_raw_body(verynewtext)
if conflict_msg:
self.request.write('<div id="message"><div>%s'
'</div></div>'% conflict_msg)
emit_anchor = 0 # make this msg visible!
elif self.exists():
# datestamp of existing page
示例4: checkSpelling
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import get_raw_body [as 别名]
def checkSpelling(page, request, own_form=1):
"""
Do spell checking, return a tuple with the result.
"""
_ = request.getText
# first check to see if we we're called with a "newwords" parameter
if request.form.has_key('button_newwords'):
_addLocalWords(request)
# load words
wordsdict = _loadDict(request)
localwords = {}
lsw_page = Page(request.config.page_local_spelling_words, request)
if lsw_page.exists():
_loadWordsString(request, localwords, lsw_page.get_raw_body())
# init status vars & load page
badwords = {}
text = page.get_raw_body()
# checker regex and matching substitute function
word_re = re.compile(r'([%s]?[%s]+)' % (
config.upperletters, config.lowerletters))
def checkword(match, wordsdict=wordsdict, badwords=badwords,
localwords=localwords, num_re=re.compile(r'^\d+$')):
word = match.group(1)
if len(word) == 1:
return ""
if not (wordsdict.has_key(word) or
wordsdict.has_key(word.lower()) or
localwords.has_key(word) or
localwords.has_key(word.lower()) ):
if not num_re.match(word):
badwords[word] = 1
return ""
# do the checking
for line in text.encode('utf-8').split('\n'):
if line == '' or line[0] == '#': continue
word_re.sub(checkword, line)
if badwords:
badwords = badwords.keys()
badwords.sort(lambda x,y: cmp(x.lower(), y.lower()))
# build regex recognizing the bad words
badwords_re = r'(^|(?<!\w))(%s)(?!\w)'
badwords_re = badwords_re % ("|".join(map(re.escape, badwords)),)
# XXX UNICODE re.UNICODE !?
badwords_re = re.compile(badwords_re)
lsw_msg = ''
if localwords:
lsw_msg = ' ' + _('(including %(localwords)d %(pagelink)s)') % {
'localwords': len(localwords), 'pagelink': lsw_page.link_to()}
msg = _('The following %(badwords)d words could not be found '
'in the dictionary of '
'%(totalwords)d words%(localwords)s and are '
'highlighted below:') % {
'badwords': len(badwords),
'totalwords': len(wordsdict)+len(localwords),
'localwords': lsw_msg} + "<br>"
# figure out what this action is called
action_name = os.path.splitext(os.path.basename(__file__))[0]
# add a form containing the bad words
if own_form:
msg = msg + (
'<form method="POST" action="%s">'
'<input type="hidden" name="action" value="%s">'
% (page.url(request), action_name,))
checkbox = ('<input type="checkbox" name="newwords" '
'value="%(word)s">%(word)s ')
msg = msg + (
" ".join(map(
lambda w, cb=checkbox: cb % {'word': wikiutil.escape(w),},
badwords)) +
'<p><input type="submit" name="button_newwords" value="%s"></p>' %
_('Add checked words to dictionary')
)
if own_form:
msg = msg + '</form>'
else:
badwords_re = None
msg = _("No spelling errors found!")
return badwords, badwords_re, msg
示例5: execute
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import get_raw_body [as 别名]
def execute(macro, args, formatter=None):
if not formatter:
if hasattr(macro.parser, 'formatter'):
formatter = macro.parser.formatter
else:
formatter = macro.formatter
_ = macro.request.getText
inline_edit_state = formatter.inline_edit
formatter.inline_edit = False
# included page will already have paragraphs. no need to print another.
macro.parser.inhibit_p = 1
if line_has_just_macro(macro, args, formatter):
macro.parser.inhibit_br = 2
request = macro.request
# parse and check arguments
if not args:
return (_sysmsg % ('error',
_('You did not give a pagename of a page to '
'include!')))
# prepare including page
result = []
this_page = formatter.page
# if we're in a paragraph, let's close it.
if macro.formatter.in_p:
result.append(macro.formatter.paragraph(0))
if not hasattr(this_page, '_macroInclude_pagelist'):
this_page._macroInclude_pagelist = {}
re_args = re.match('('
'('
'(?P<name1>.+?)(\s*,\s*)((".*")|(left|right)|([0-9]{1,2}%)))|'
'(?P<name2>.+))', args)
if not re_args:
return (_sysmsg % ('error', _('Invalid arguments to Include.')))
have_more_args = re_args.group('name1')
page_name = re_args.group('name1') or re_args.group('name2')
if have_more_args:
args = args[re_args.end('name1'):]
else:
args = ''
re_args = re.search('"(?P<heading>.*)"', args)
if re_args:
heading = re_args.group('heading')
else:
heading = None
if heading:
before_heading = args[:re_args.start('heading')-1].strip()
after_heading = args[re_args.end('heading')+1:].strip()
args = before_heading + after_heading[1:]
args_elements = args.split(',')
align = None
was_given_width = False
width = '50%'
for arg in args_elements:
arg = arg.strip()
if arg == 'left' or arg == 'right':
align = arg
elif arg.endswith('%'):
try:
arg = str(int(arg[:-1])) + '%'
except:
continue
width = arg
was_given_width = True
inc_name = wikiutil.AbsPageName(this_page.page_name, page_name)
inc_page = Page(inc_name, macro.request)
if not macro.request.user.may.read(inc_page):
return ''
if this_page.page_name.lower() == inc_name.lower():
result.append('<p><strong class="error">'
'Recursive include of "%s" forbidden</strong></p>' %
inc_name)
return ''.join(result)
# check for "from" and "to" arguments (allowing partial includes)
body = inc_page.get_raw_body(fresh=True) + '\n'
edit_icon = ''
# do headings
level = 1
if heading:
result.append(formatter.heading(level, heading, action_link="edit",
link_to_heading=True,
pagename=inc_page.proper_name(),
backto=this_page.page_name))
if this_page._macroInclude_pagelist.has_key(inc_name):
if (this_page._macroInclude_pagelist[inc_name] >
#.........这里部分代码省略.........
示例6: execute
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import get_raw_body [as 别名]
def execute(macro, args, formatter=None):
if not formatter:
formatter = macro.formatter
_ = macro.request.getText
re_args = re.search('(?P<caption>.+)\,\s(?P<the_rest>.*)', args)
pagename = re_args.group('caption')
items = re_args.group('the_rest')
page = Page(pagename, macro.request)
try:
links = max(int(items), 1)
except StandardError:
links = 1
raw = page.get_raw_body(fresh=macro.request.set_cache)
if not macro.request.user.may.read(page):
raw = ""
# this selects lines looking like a list item
# !!! TODO: make multi-line quotes possible
# (optionally split by "----" or something)
quotes = raw.splitlines()
if links > 1:
quotes = [quote for quote in quotes if quote.startswith(' *')]
random.shuffle(quotes)
while len(quotes) > links:
quotes = quotes[:-1]
quote = ''
for name in quotes:
quote = quote + name + '\n'
page.set_raw_body(quote, 1)
out = cStringIO.StringIO()
macro.request.redirect(out)
page.send_page(content_only=1,
content_id="randomquote_%s" %
wikiutil.quoteWikiname(page.page_name) )
quote = out.getvalue()
macro.request.redirect()
else:
quotes = [quote.strip() for quote in quotes]
quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
if quotes:
quote = random.choice(quotes)
else:
quote = ''
page.set_raw_body(quote, 1)
out = cStringIO.StringIO()
macro.request.redirect(out)
page.send_page(content_only=1,
content_id="randomquote_%s" %
wikiutil.quoteWikiname(page.page_name) )
quote = out.getvalue()
macro.request.redirect()
if not quotes:
return (macro.formatter.highlight(1) +
_('No quotes on %(pagename)s.') % {'pagename': pagename} +
macro.formatter.highlight(0))
return quote.decode(config.charset)
示例7: get_group_members
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import get_raw_body [as 别名]
group = wikiacl.Group(groupname, req)
groupdict = get_group_members(groupname, req)
group.update(groupdict)
group.save()
print " ", admin_group, "->", 'Admin'
group = wikiacl.Group('Admin', req)
groupdict = get_group_members(admin_group, req)
group.update(groupdict)
group.save()
print " ", banned_group, "->", 'Banned'
group = wikiacl.Group('Banned', req)
groupdict = get_group_members(banned_group, req)
group.update(groupdict)
group.save()
# note on group page that this is not how it's defined any more
for groupname in defined_user_groups + [admin_group, banned_group]:
p = Page(groupname, req)
if p.exists():
new_body = p.get_raw_body() + '\n\n' + group_changed_message
p.set_raw_body(new_body)
req.cursor.execute("UPDATE curPages set text=%(new_body)s where name=%(pagename)s and wiki_id=%(wiki_id)s", {'new_body':new_body, 'pagename':p.page_name, 'wiki_id':req.config.wiki_id}, isWrite=True)
req.cursor.execute("UPDATE allPages set text=%(new_body)s where name=%(pagename)s and editTime=%(mtime)s and wiki_id=%(wiki_id)s", {'new_body':new_body, 'pagename':p.page_name, 'mtime':p.mtime(), 'wiki_id':req.config.wiki_id}, isWrite=True)
p.buildCache()
req.db_disconnect()
print "..Done!"