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


Python PageEditor._expand_variables方法代码示例

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


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

示例1: execute

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import _expand_variables [as 别名]
def execute(pagename, request):
    form = values_to_form(request.values)

    template = form.get('template', [''])[0]

    if template and not request.page.exists():
        template_page = wikiutil.unquoteWikiname(template)
        if request.user.may.read(template_page):
            editor = PageEditor(request, template_page)
            editor.user = request.user
            text = editor.get_raw_body()
            editor.page_name = pagename
            request.page.set_raw_body(editor._expand_variables(text))
            newdata = parse_text(request, request.page,
                                 request.page.get_raw_body())

            # Add prototype metas (^ something::\s*$) as keys
            protokeys = [y for x,y in dl_proto_re.findall(text)]
            for key in protokeys:
                if not (key in newdata[pagename].get('out', dict()) or 
                        key in newdata[pagename].get('meta', dict())):
                    newdata[pagename].setdefault('meta', dict())[key] = list()

            # I'll lie, cheat, do anything to make this work
            newdata[pagename]['saved'] = True

            # Add the template metas to cache so that they'd show
            request.graphdata.cacheset(pagename, newdata.get(pagename, dict()))

    MetaEdit.execute(pagename, request)
开发者ID:graphingwiki,项目名称:graphingwiki,代码行数:32,代码来源:editmeta.py

示例2: TestExpandUserName

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import _expand_variables [as 别名]
class TestExpandUserName(object):
    """ Base class for user name tests

    Set user name during tests.
    """
    pagename = u'AutoCreatedMoinMoinTemporaryTestPage'
    variable = u'@[email protected]'

    def setup_method(self, method):
        self.page = PageEditor(self.request, self.pagename)
        self.savedName = self.request.user.name
        self.request.user.name = self.name

    def teardown_method(self, method):
        self.request.user.name = self.savedName

    def expand(self):
        return self.page._expand_variables(self.variable)
开发者ID:Opngate,项目名称:moinmoin,代码行数:20,代码来源:test_PageEditor.py

示例3: ExpandUserNameTest

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import _expand_variables [as 别名]
class ExpandUserNameTest(unittest.TestCase):
    """ Base class for user name tests
    
    Set user name during tests.
    """
    pagename = u'AutoCreatedMoinMoinTemporaryTestPage'
    variable = u'@[email protected]'
    
    def setUp(self):
        self.page = PageEditor(self.request, self.pagename)
        self.savedName = self.request.user.name
        self.request.user.name = self.name

    def tearDown(self):
        self.request.user.name = self.savedName
    
    def expand(self):
        return self.page._expand_variables(self.variable)
开发者ID:moinwiki,项目名称:moin-legacy,代码行数:20,代码来源:test_PageEditor.py

示例4: TestExpandVars

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import _expand_variables [as 别名]
class TestExpandVars(object):
    """PageEditor: testing page editor"""
    pagename = u'AutoCreatedMoinMoinTemporaryTestPage'

    _tests = (
        # Variable,             Expanded
        ("@[email protected]", pagename),
        ("[email protected]@bedded", "em%sbedded" % pagename),
        ("@[email protected]", "@[email protected]"),
        ("[email protected]@sensitive", "[email protected]@sensitive"),
        )

    def setup_method(self, method):
        self.page = PageEditor(self.request, self.pagename)

    def testExpandVariables(self):
        """ PageEditor: expand general variables """
        for var, expected in self._tests:
            result = self.page._expand_variables(var)
            assert result == expected
开发者ID:Opngate,项目名称:moinmoin,代码行数:22,代码来源:test_PageEditor.py

示例5: ExpandVarsTestCase

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import _expand_variables [as 别名]
class ExpandVarsTestCase(unittest.TestCase):
    """PageEditor: testing page editor"""   

    pagename = u'AutoCreatedMoinMoinTemporaryTestPage'

    _tests = (
        # Variable,             Expanded
        ("@[email protected]",              pagename),
        ("[email protected]@bedded",      "em%sbedded" % pagename),
        ("@[email protected]",             "@[email protected]"),
        ("[email protected]@sensitive", "[email protected]@sensitive"),
        )

    def setUp(self):
        self.page = PageEditor(self.request, self.pagename)

    def testExpandVariables(self):
        """ PageEditor: expand general variables """
        for var, expected in self._tests:
            result = self.page._expand_variables(var)
            self.assertEqual(result, expected,
                'Expected "%(expected)s" but got "%(result)s"' % locals())   
开发者ID:moinwiki,项目名称:moin-legacy,代码行数:24,代码来源:test_PageEditor.py

示例6: execute

# 需要导入模块: from MoinMoin.PageEditor import PageEditor [as 别名]
# 或者: from MoinMoin.PageEditor.PageEditor import _expand_variables [as 别名]
def execute(pagename, request):
    _ = request.getText

    form = values_to_form(request.values)

    if not request.user.may.write(pagename):
        request.reset()
        backto = form.get('backto', [None])[0]
        if backto:
            request.page = Page(request, backto)

        request.theme.add_msg(_('You are not allowed to edit this page.'),
                              "error")
        request.page.send_page()
        return

    frm = wr(
        u'<form id="metaformedit" method="POST" enctype="multipart/form-data" action="%s">\n',
             actionname(request))+\
          wr(u'<input form="metaformedit" type="hidden" name="action" value="MetaEdit">\n')+\
          wr(u'<input form="metaformedit" type="hidden" name="gwikiseparator" value="%s">\n',
             SEPARATOR)

    btn = '<div class="saveform"><p class="savemessage">' + \
          wr('<input type=submit name=saveform form="metaformedit" value="%s">',
             _(form.get('saveBtnText', ['Save Changes'])[0])) + \
             wr('<input form="metaformedit" type=submit name=cancel value="%s">',
                _('Cancel')) +'</p></div>'

    # Template to use for any new pages
    template = form.get('template', [''])[0]
    if template:
        frm += wr('<input form="metaformedit" type="hidden" name="template" value="%s">', template)
    # Where to after saving page
    backto = form.get('backto', [''])[0]
    if backto:
        frm += wr('<input form="metaformedit" type="hidden" name="backto" value="%s">', backto)

    old_header = request.cfg.page_header2
    old_footer = request.cfg.page_footer1
    # The post-header and pre-footer texts seem to be implemented in themes.
    # Using post-header instead of page msg to avoid breaking header forms.
    request.cfg.page_header2 += frm + btn
    request.cfg.page_footer1 += btn + '</form>'

    old_page = request.page
    request.page = FormPage(request, pagename)

    error = ''
    newpage = False
    template_text = ''
    # If the page does not exist but we'd know how to construct it,
    # replace the Page content with template and pretend it exists
    if template and not request.page.exists():
        template_page = wikiutil.unquoteWikiname(template)
        if request.user.may.read(template_page):
            editor = PageEditor(request, template_page)
            editor.user = request.user
            text = editor.get_raw_body()
            editor.page_name = pagename
            template_text = editor._expand_variables(text)
            request.page.set_raw_body(template_text)
            request.page.exists = lambda **kw: True
            request.page.lastEditInfo = lambda: {}
            newpage = True
        else:
            error = '<div class="saveform"><p class="savemessage">' + \
                    _("Cannot read template") + '</p></div>'

    elif not template and not request.page.exists():
        error = '<div class="saveform"><p class="savemessage">' + \
                _("No template specified, cannot edit") + '</p></div>'


    if error:
        request.cfg.page_header2 = request.cfg.page_header2 + error
        request.cfg.page_footer1 = request.cfg.page_footer1

    # Extra spaces from formatter need to be removed, that's why the
    # page is not sent as it is
    out = StringIO.StringIO()
    request.redirect(out)
    request.sent_headers = True
    request.page.send_page()
    request.redirect()

    graphdata = request.graphdata
    vals_on_keys = graphdata.get_vals_on_keys()

    # If we're making a new page based on a template, make sure that
    # the values from the evaluated template are included in the form editor
    if newpage:
        templatePage = Page(request, template)
        data = parse_text(request, templatePage, template_text)
        for page in data:
            for key in data[page].get('meta', list()):
                for val in data[page]['meta'][key]:
                    vals_on_keys.setdefault(key, set()).add(val)
            for key in data[page].get('out', list()):
                for val in data[page]['out'][key]:
#.........这里部分代码省略.........
开发者ID:graphingwiki,项目名称:gwiki-with-moin,代码行数:103,代码来源:MetaFormEdit.py


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