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


Python PageEditor.normalizeText方法代码示例

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


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

示例1: save_page

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import normalizeText [as 别名]
 def save_page(self, output):
     editor = PageEditor(self.macro.request, self.pagename)
     text = self.create_header()
     text += editor.normalizeText(output)
     dummy, revision, exists = editor.get_rev() 
     try:
         res =  editor.saveText(text, revision, comment="updated by MakeList macro.")
         return res
     except editor.Unchanged:
         return "You did not change the page content, not saved!"
     except:
         return "An error occured!"
开发者ID:3100,项目名称:MoinMacro,代码行数:14,代码来源:MakeList.py

示例2: do_savepage

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import normalizeText [as 别名]
def do_savepage(pagename, request):
    from MoinMoin.PageEditor import PageEditor

    _ = request.getText

    if not request.user.may.write(pagename):
        Page(request, pagename).send_page(request,
            msg = _('You are not allowed to edit this page.'))
        return

    pg = PageEditor(request, pagename)
    savetext = request.form.get('savetext', [u''])[0]
    rev = int(request.form.get('rev', ['0'])[0])
    comment = request.form.get('comment', [u''])[0]
    category = request.form.get('category', [None])[0]
    rstrip = int(request.form.get('rstrip', ['0'])[0])
    trivial = int(request.form.get('trivial', ['0'])[0])

    # IMPORTANT: normalize text from the form. This should be done in
    # one place before we manipulate the text.
    savetext = pg.normalizeText(savetext, stripspaces=rstrip)

    # Add category

    # TODO: this code does not work with extended links, and is doing
    # things behind your back, and in general not needed. Either we have
    # a full interface for categories (add, delete) or just add them by
    # markup.
    
    if category:
        # strip trailing whitespace
        savetext = savetext.rstrip()

        # Add category separator if last non-empty line contains
        # non-categories.
        lines = filter(None, savetext.splitlines())
        if lines:
            
            #TODO: this code is broken, will not work for extended links
            #categories, e.g ["category hebrew"]
            categories = lines[-1].split()
            
            if categories:
                confirmed = wikiutil.filterCategoryPages(request, categories)
                if len(confirmed) < len(categories):
                    # This was not a categories line, add separator
                    savetext += u'\n----\n'

        # Add new category
        if savetext and savetext[-1] != u'\n':
            savetext += ' '
        savetext += category + u'\n' # Should end with newline!

    # Clean comment - replace CR, LF, TAB by whitespace, delete control chars
    # TODO: move this to config, create on first call then return cached.
    remap_chars = {
        ord(u'\t'): u' ',
        ord(u'\r'): u' ',
        ord(u'\n'): u' ',
    }
    control_chars = u'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f' \
                    '\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'
    for c in control_chars:
        remap_chars[c] = None
    comment = comment.translate(remap_chars)

    # Preview, spellcheck or spellcheck add new words
    if (request.form.has_key('button_preview') or
        request.form.has_key('button_spellcheck') or
        request.form.has_key('button_newwords')):
        pg.sendEditor(preview=savetext, comment=comment)

    # Edit was canceled
    elif request.form.has_key('button_cancel'):
        pg.sendCancel(savetext, rev)
    
    # Save new text
    else:
        try:
            savemsg = pg.saveText(savetext, rev, trivial=trivial,
                                  comment=comment)
        except pg.EditConflict, msg:
            # Handle conflict and send editor

            # TODO: conflict messages are duplicated from PageEditor,
            # refactor to one place only.
            conflict_msg = _('Someone else changed this page while you were editing!')
            pg.set_raw_body(savetext, modified=1)
            if pg.mergeEditConflict(rev):
                conflict_msg = _("""Someone else saved this page while you were editing!
Please review the page and save then. Do not save this page as it is!
Have a look at the diff of %(difflink)s to see what has been changed.""") % {
                    'difflink': pg.link_to(pg.request,
                                           querystr='action=diff&rev=%d' % rev)
                    }
                # We don't send preview when we do merge conflict
                pg.sendEditor(msg=conflict_msg, comment=comment)
                return
            else:
                savemsg = conflict_msg
#.........这里部分代码省略.........
开发者ID:mikejamesthompson,项目名称:orgsites,代码行数:103,代码来源:wikiaction.py

示例3: ScriptContext

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import normalizeText [as 别名]
# coding: utf-8
import py

from MoinMoin import wikiutil

from MoinMoin.PageEditor import PageEditor
from MoinMoin.web.contexts import ScriptContext

pagename = 'Class_%23AC0'
req = ScriptContext('localhost:8080', pagename)
editor = PageEditor(request, pagename)
text = editor.normalizeText('''= #AC<sup>0</sup> = 

The class of functions from {0,1}<sup>n</sup> to nonnegative integers computed by polynomial-size constant-depth arithmetic circuits, using addition and multiplication gates and the constants 0 and 1.

Contained in GapAC<sup>0</sup>.''')
_, rev, _ = editor.get_rev()
editor.saveText(text, rev)
开发者ID:silky,项目名称:complexityzoo,代码行数:20,代码来源:meh.py


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