本文整理汇总了Python中Sycamore.Page.Page类的典型用法代码示例。如果您正苦于以下问题:Python Page类的具体用法?Python Page怎么用?Python Page使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Page类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
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: testExist
def testExist(self):
"""Tests if Page().exists() is working correctly."""
from Sycamore.Page import Page
cannot_possibly_exist = make_impossible_pages(self.request, 200)
for pagename in cannot_possibly_exist:
page = Page(pagename, self.request)
self.assertFalse(page.exists())
示例3: execute
def execute(pagename, request):
_ = request.getText
request.formatter = Formatter(request)
page = Page(pagename, request)
if not page.page_name.startswith(config.user_page_prefix.lower()):
return page.send_page(msg="Not a user page.")
username = pagename[len(config.user_page_prefix):]
request.http_headers()
wikiutil.simple_send_title(request, pagename,
strict_title="User %s's information" % username)
request.write('<div id="content" class="content">\n\n')
InfoBar(request, page).render()
request.write('<div id="tabPage">')
if config.wiki_farm:
request.write('<h3>Watched Wikis</h3>')
display_watched_wikis(request, username)
request.write('<h3>Bookmarks</h3>\n')
display_bookmarks(request, username)
request.write('<h3>Edits</h3>\n')
display_edits(request, username, pagename)
request.write('</div></div>')
wikiutil.send_footer(request, pagename, showpage=1, noedit=True)
示例4: execute
def execute(macro, args, formatter):
if not formatter:
formatter = macro.formatter
# get number of wanted links
try:
links = max(int(args), 1)
except StandardError:
links = 1
# select the pages from the page list
random_list = wikiutil.getRandomPages(macro.request)
pages = []
while len(pages) < links and random_list:
pagename = random.choice(random_list)
page = Page(pagename, macro.request)
if macro.request.user.may.read(page) and page.exists():
pages.append(page)
# return a single page link
if links == 1:
return pages[0].link_to()
# return a list of page links
pages.sort()
result = [macro.formatter.bullet_list(1)]
for page in pages:
result.append("%s%s%s" %
(macro.formatter.listitem(1), page.link_to(),
macro.formatter.listitem(0)))
result.append(macro.formatter.bullet_list(0))
return ''.join(result)
示例5: get_group_members
def get_group_members(groupname, request):
members = {}
page_text = Page(groupname, request).get_raw_body(fresh=True)
for line in page_text.split('\n'):
if line.startswith(' *'):
username = line[len(' *'):].strip()
members[username.lower()] = None
return members
示例6: execute
def execute(pagename, request):
page = Page(pagename, request)
msg = None
form = request.form
if form.has_key("id"):
id = request.form["id"][0]
return send_human_readable(id, request)
return page.send_page(msg=msg)
示例7: process
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)
示例8: rebuild_page_cache
def rebuild_page_cache():
"""
Rebuilds the page cache.
"""
if not request.generating_cache and not request.previewing_page:
from Sycamore import caching
from Sycamore.Page import Page
page = Page(dict['pagename'], request)
if page.exists():
page.buildCache()
示例9: execute
def execute(pagename, request):
_ = request.getText
page = Page(pagename, request.cursor)
if request.user.may.read(pagename):
badwords, badwords_re, msg = checkSpelling(page, request)
else:
badwords = []
msg = _("You can't check spelling on a page you can't read.")
if badwords:
page.send_page(request, msg=msg, hilite_re=badwords_re)
else:
page.send_page(request, msg=msg)
示例10: __init__
def __init__(self, page_name, request, **keywords):
"""
Create page editor object.
@param page_name: name of the page
@param request: the request object
@keyword do_revision_backup: if 0, suppress making a page backup
per revision
"""
self.request = request
self._ = request.getText
Page.__init__(self, page_name, request, **keywords)
self.do_revision_backup = keywords.get('do_revision_backup', 1)
示例11: build
def build(wiki_name, pname, doprint=False, req=None, super=False):
given_req = True
if not req:
req = request.RequestDummy(wiki_name=wiki_name)
given_req = False
page = Page(pname, req)
page.buildCache()
if super:
wikiutil.macro_delete_checks(page)
if not given_req:
req.db_disconnect()
if doprint:
print " -->", pname.encode(config.charset)
示例12: _consider_talk_link
def _consider_talk_link(self, links):
if not self.request.config.talk_pages:
return links
lower_links = [ link.lower() for link in links ]
from Sycamore.Page import Page
pagename = self.key
page = Page(pagename, self.request)
linkto_name = None
if page.isTalkPage():
article_page = Page(wikiutil.talk_to_article_pagename(pagename),
self.request)
article_pagename = article_page.proper_name()
if article_pagename.lower() not in lower_links:
links.append(article_pagename)
else:
talk_pagename = wikiutil.article_to_talk_pagename(pagename)
talk_page = Page(talk_pagename, self.request)
# add dependency so that editing/creating the talk page
# has an affect on the article page's links
dependency(pagename, talk_pagename.lower(), self.request)
if talk_page.exists():
talk_pagename = talk_page.proper_name()
if talk_pagename.lower() not in lower_links:
links.append(talk_pagename)
return links
示例13: do_user_browser
def do_user_browser(request):
""" Browser for SystemAdmin macro. """
from Sycamore.util.dataset import TupleDataset, Column
from Sycamore.Page import Page
_ = request.getText
data = TupleDataset()
data.columns = [
Column('id', label=('ID'), align='right'),
Column('name', label=('Username')),
Column('email', label=('Email')),
Column('action', label=_('Action')),
]
# Iterate over users
for uid in user.getUserList(self.request.cursor):
account = user.User(request, uid)
userhomepage = Page(account.name, self.request)
if userhomepage.exists():
namelink = userhomepage.link_to()
else:
namelink = account.name
data.addRow((
request.formatter.code(1) + uid + request.formatter.code(0),
request.formatter.rawHTML(namelink),
request.formatter.url('mailto:' + account.email, account.email,
'external', pretty_url=1, unescaped=1),
'',
))
if data:
from Sycamore.widget.browser import DataBrowserWidget
browser = DataBrowserWidget(request)
browser.setData(data)
return browser.toHTML()
# No data
return ''
示例14: execute
def execute(macro, args, formatter=None):
formatter = macro.formatter
if not args:
page = macro.formatter.page
else:
page = Page(args, macro.request)
links_here = page.getPageLinksTo()
pages_deco = [(pagename.lower(), pagename) for pagename in links_here]
pages_deco.sort()
links_here = [word for lower_word, word in pages_deco]
text = []
if links_here:
text.append(formatter.bullet_list(1))
for link in links_here:
text.append(
"%s%s%s" % (formatter.listitem(1), formatter.pagelink(link, generated=True), formatter.listitem(0))
)
text.append(formatter.bullet_list(0))
return "".join(text)
示例15: execute
def execute(macro, args, formatter=None):
if not formatter:
formatter = macro.formatter
cursor = macro.request.cursor
cursor.execute("""
SELECT c.propercased_name, count(c.source_pagename) as cnt
FROM (
SELECT curPages.propercased_name, links.source_pagename
FROM curPages LEFT JOIN links on
(links.source_pagename=curPages.name and
links.wiki_id=%(wiki_id)s and
curPages.wiki_id=%(wiki_id)s)
WHERE curPages.wiki_id=%(wiki_id)s
) as c
GROUP BY c.propercased_name ORDER BY cnt""",
{'wiki_id': macro.request.config.wiki_id})
results = cursor.fetchall()
old_count = -1
for entry in results:
name = entry[0]
lower_name = name.lower()
if skip_page(name):
continue
new_count = entry[1]
page = Page(name, macro.request)
if new_count == 0 and page.isRedirect():
continue
if new_count != old_count:
old_count = new_count
macro.request.write(macro.formatter.heading(2, str(new_count)))
else:
macro.request.write(", ")
macro.request.write(page.link_to(know_status=True,
know_status_exists=True))
return ''