当前位置: 首页>>代码示例>>Python>>正文


Python Page.set_raw_body方法代码示例

本文整理汇总了Python中Sycamore.Page.Page.set_raw_body方法的典型用法代码示例。如果您正苦于以下问题:Python Page.set_raw_body方法的具体用法?Python Page.set_raw_body怎么用?Python Page.set_raw_body使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sycamore.Page.Page的用法示例。


在下文中一共展示了Page.set_raw_body方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import set_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)
开发者ID:ivanov,项目名称:sycamore,代码行数:66,代码来源:randomitem.py

示例2: loadLanguage

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import set_raw_body [as 别名]
def loadLanguage(request, lang):
    """
    Load text dictionary for a specific language.

    Note that while ISO language coded use a dash, like 'en-us', our
    languages files use '_' like 'en_us' because they are saved as
    Python source files.

    """
    from Sycamore.util import pysupport
    lang_module = "Sycamore.i18n." + filename(lang)
    texts = pysupport.importName(lang_module, "text") 
    meta = pysupport.importName(lang_module, "meta") 

    # FIXME this doesnt work, leads to &amp;amp;amp;...
    # maybe parser.wiki._do_ent_repl is the problem?
    
    # please help finding this bug. I want to get rid of html in i18n texts
    # and a nice way to do is to replace them by wiki markup. so we wont have
    # to change them every time we go to a new html standard (like html 4.01
    # now and soon maybe xhtml).
    
    # use the wiki parser now to replace some wiki markup with html
    # maybe this is the better implementation, less overhead
    if 0:
        from Sycamore.Page import Page
        from Sycamore.parser.wiki import Parser
        from Sycamore.formatter.text_html import Formatter
        import cStringIO
        for key in texts:
            text = texts[key]
            out = cStringIO.StringIO()
            request.redirect(out)
            print "making parser ..."
            parser = Parser(text, request)
            formatter = Formatter(request)
            p = Page("$$$$i18n$$$$")
            formatter.setPage(p)
            print "formatting ..."
            parser.format(formatter)
            print "formatting finished ..."
            text = out.getvalue()
            request.redirect()
            #if text.startswith("<p>\n"):
            #    text = text[4:]
            #if text.endswith("</p>\n"):
            #    text = text[:-5]
            #print text
            
            # XXX catch problem early:
            if "&amp;amp;" in text:
                raise str(key)+str(text)
            
            texts[key] = text
        
    #alternative implementation, also doesnt work:
    if 0:
        import cStringIO
        from Sycamore.Page import Page
        page = Page("$$$i18n$$$")
        #key = "xxx"
        for key in texts:
            text = texts[key]
            page.set_raw_body(text, 1)
            out = cStringIO.StringIO()
            request.redirect(out)
            page.send_page(request, content_only=1)
            text = out.getvalue()
            if text.startswith("<p>\n"):
                text = text[4:]
            if text.endswith("</p>\n"):
                text = text[:-5]
            #print text
            request.redirect()
            texts[key] = text
        
    # TODO caching for CGI or performance will suck
    # pickle texts dict to caching area

    # XXX UNICODE
    # convert to unicode
    #encoding = meta['encoding']
    #for t in texts:
    #    texts[t] = texts[t].decode(encoding)
    return texts
开发者ID:ivanov,项目名称:sycamore,代码行数:87,代码来源:__init__.py

示例3: get_group_members

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import set_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!"
开发者ID:ivanov,项目名称:sycamore,代码行数:32,代码来源:2006_08_30_acl.py


注:本文中的Sycamore.Page.Page.set_raw_body方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。