• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python mwtemplates.TemplateEditor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mwtemplates.TemplateEditor的典型用法代码示例。如果您正苦于以下问题:Python TemplateEditor类的具体用法?Python TemplateEditor怎么用?Python TemplateEditor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_edit_anonymous_parameter2

 def test_edit_anonymous_parameter2(self):
     # Check that an anomyous parameter can be edited, preserving declaration
     text = 'Lorem ipsum {{lang|1=fr}} amet'
     dp = TemplateEditor(text)
     dp.templates['lang'][0].parameters[1] = 'no'
     tmp = text.replace('fr', 'no')
     self.assertEqual(dp.wikitext(), tmp)
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:7,代码来源:templateeditor2_test.py


示例2: test_alter_anonymous_param1

 def test_alter_anonymous_param1(self):
     # Check that an anomyous parameter can be edited correctly
     text = 'Lorem ipsum {{lang|fr}} amet'
     dp = TemplateEditor(text)
     dp.templates['lang'][0].parameters[1] = 'no'
     tmp = text.replace('fr', 'no')
     self.assertEqual(dp.wikitext(), tmp)
开发者ID:jmansilla,项目名称:mwtemplates,代码行数:7,代码来源:templateeditor2_test.py


示例3: test_add_parameter3

 def test_add_parameter3(self):
     # Check that a parameter can be added, and that an existing whitespace pattern is followed
     text = 'Lorem ipsum {{ Infoboks A | a = 2 }} dolor sit amet'
     text2 = 'Lorem ipsum {{ Infoboks A | a = 2 | b = 3 }} dolor sit amet'
     dp = TemplateEditor(text)
     dp.templates['infoboks A'][0].parameters['b'] = '3'
     self.assertEqual(dp.wikitext(), text2)
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:7,代码来源:templateeditor2_test.py


示例4: test_edit_parameter_using_value_that_needs_xml_escape

 def test_edit_parameter_using_value_that_needs_xml_escape(self):
     # Check that "&" in values are properly handled
     text = 'Lorem ipsum {{kilde www}} amet'
     result = 'Lorem ipsum {{kilde www| url=http://www.skulabladid.fo/fo-FO/Tíðindasavn/Eldri-tíðindi.aspx?PID=30&M=NewsV2&Action=1&NewsId=3201&currentPage=83 }} amet'
     dp = TemplateEditor(text)
     dp.templates['kilde www'][0].parameters['url'] = 'http://www.skulabladid.fo/fo-FO/Tíðindasavn/Eldri-tíðindi.aspx?PID=30&M=NewsV2&Action=1&NewsId=3201&currentPage=83'
     self.assertEqual(dp.wikitext(), result)
开发者ID:danmichaelo,项目名称:mwtemplates,代码行数:7,代码来源:templateeditor2_test.py


示例5: test_add_parameter2

 def test_add_parameter2(self):
     # Check that a parameter can be added, and that an existing whitespace pattern is followed
     text = 'Lorem ipsum {{ Infoboks A\n| maks = 2 \n}} dolor sit amet'
     text2 = 'Lorem ipsum {{ Infoboks A\n| maks = 2 \n| dato = TEST \n}} dolor sit amet'
     dp = TemplateEditor(text)
     dp.templates['infoboks A'][0].parameters['dato'] = 'TEST'
     self.assertEqual(dp.wikitext(), text2)
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:7,代码来源:templateeditor2_test.py


示例6: test_delete_template

 def test_delete_template(self):
     # Check that a parameter can be deleted
     text = 'Lorem ipsum {{ Infoboks A | a = 2 | b = 3 | c = 4 }} dolor sit{{lang|fr}} amet'
     text2 = 'Lorem ipsum dolor sit{{lang|fr}} amet'
     dp = TemplateEditor(text)
     dp.templates['Infoboks A'][0].remove()  # Note that 'del dp.templates['Infoboks A'][0]' currently does not work
     self.assertEqual(dp.wikitext(), text2)
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:7,代码来源:templateeditor2_test.py


示例7: check_randompage

def check_randompage(pagename):
    logger.debug('Page: %s', pagename)
    page = site.pages[pagename]
    inputtxt = page.edit(readonly=True)
    dp = TemplateEditor(inputtxt)
    outputtxt = dp.wikitext()

    assert inputtxt == outputtxt
开发者ID:jmansilla,项目名称:mwtemplates,代码行数:8,代码来源:test_randompages.py


示例8: test_edit_nonempty_parameter_alternative

 def test_edit_nonempty_parameter_alternative(self):
     # Check that a parameter can be renamed using 'parameter.value='
     text = 'Lorem ipsum {{ Infoboks A\n| maks = 2 \n}} dolor sit amet'
     dp = TemplateEditor(text)
     templ = dp.templates['infoboks A'][0]
     templ.parameters['maks'].value = '3'
     tmp = text.replace('2', '3')
     self.assertEqual(dp.wikitext(), tmp)
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:8,代码来源:templateeditor2_test.py


示例9: test_edit_empty_parameter_with_linebreak

 def test_edit_empty_parameter_with_linebreak(self):
     # Check that an empty parameter can be edited, with linebreak preserved
     text = 'Lorem ipsum {{ Infoboks A \n| date= \n| title= \n}} dolor sit amet'
     dp = TemplateEditor(text)
     templ = dp.templates['infoboks A'][0]
     templ.parameters['date'] = 'test'
     tmp = text.replace('date= ', 'date= test')
     self.assertEqual(dp.wikitext(), tmp)
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:8,代码来源:templateeditor2_test.py


示例10: test_change_template_name

 def test_change_template_name(self):
     # Check that a template can be renamed, with whitespace preserved
     text = 'Lorem ipsum {{ Infoboks A\n| maks=2\n}} dolor sit amet'
     dp = TemplateEditor(text)
     templ = dp.templates['infoboks A'][0]
     templ.name = 'Mal B'
     tmp = text.replace('Infoboks A', 'Mal B')
     self.assertEqual(dp.wikitext(), tmp)
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:8,代码来源:templateeditor2_test.py


示例11: test_delete_parameter_alternative

 def test_delete_parameter_alternative(self):
     # Check that a parameter can be deleted
     text = 'Lorem ipsum {{ Infoboks A | a = 2 | b = 3 | c = 4 }} dolor sit amet'
     text2 = 'Lorem ipsum {{ Infoboks A | a = 2 | c = 4 }} dolor sit amet'
     dp = TemplateEditor(text)
     templ = dp.templates['infoboks A'][0]
     templ.parameters.remove('b')
     self.assertEqual(dp.wikitext(), text2)
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:8,代码来源:templateeditor2_test.py


示例12: test_delete_parameter

 def test_delete_parameter(self):
     # Check that a parameter can be renamed, with whitespace preserved
     text = 'Lorem ipsum {{ Infoboks A\n| maks = 2 \n}} dolor sit amet'
     text2 = 'Lorem ipsum {{ Infoboks A\n}} dolor sit amet'
     dp = TemplateEditor(text)
     templ = dp.templates['infoboks A'][0]
     del templ.parameters['maks']
     self.assertEqual(dp.wikitext(), text2)
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:8,代码来源:templateeditor2_test.py


示例13: test_edit_parameter_using_integer_alternative

 def test_edit_parameter_using_integer_alternative(self):
     # Check that a parameter can be renamed, with whitespace preserved
     text = 'Lorem ipsum {{ Infoboks A\n| maks = 2 \n}} dolor sit amet'
     dp = TemplateEditor(text)
     templ = dp.templates['infoboks A'][0]
     templ.parameters['maks'].edit(3)
     tmp = text.replace('2', '3')
     self.assertEqual(dp.wikitext(), tmp)
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:8,代码来源:templateeditor2_test.py


示例14: __init__

    def __init__(self, page, interactive_mode):

        logger.info('Checking page: %s', page.name)

        self.checked = 0
        self.modified = []
        self.unresolved = []

        # te = page.text()
        txt = page.text()

        # Due to <https://github.com/danmichaelo/mwtemplates/issues/3>
        if re.search('<nowiki ?/>', txt, re.I) is not None:
            return

        te = TemplateEditor(txt)

        modified = False
        for k, v in te.templates.iteritems():
            if k in ['Kilde www', 'Kilde bok', 'Kilde artikkel', 'Kilde avhandling', 'Kilde avis', 'Cite web', 'Citeweb', 'Cite news', 'Cite journal', 'Cite book', 'Tidningsref', 'Webbref', 'Bokref']:
                for tpl in v:
                    t = Template(tpl, interactive_mode)
                    self.checked += t.checked
                    self.modified.extend(t.modified)
                    self.unresolved.extend(t.unresolved)

        for u in self.unresolved:
            u['page'] = page.name

        if len(self.modified) != 0:
            if len(self.modified) == 1:
                summary = 'CS1-kompatible datoer: %s' % (self.format_entry(self.modified[0]))
            elif len(self.modified) == 2:
                summary = 'CS1-kompatible datoer: %s, %s' % (self.format_entry(self.modified[0]), self.format_entry(self.modified[1]))
            else:
                summary = 'CS1-kompatible datoer: Fikset %d datoer' % (len(self.modified))

            logger.info('Saving %d fixed date(s)', len(self.modified))
            time.sleep(1)

            try:
                res = page.save(te.wikitext(), summary=summary)
            except mwclient.errors.ProtectedPageError:
                logger.error('ERROR: Page protected, could not save')

            if res.get('newrevid') is not None:
                with codecs.open('modified.txt', 'a', 'utf8') as f:
                    for x in self.modified:
                        ti = quote(page.name.replace(' ', '_').encode('utf8'))
                        difflink = '//no.wikipedia.org/w/index.php?title=%s&diff=%s&oldid=%s' % (ti, res['newrevid'], res['oldrevid'])
                        f.write('| [[%s]] ([%s diff]) || Endret %s fra %s til %s || %s\n|-\n' % (page.name, difflink, x['key'], x['old'], x['new'], 'kompleks' if x['complex'] else ''))

                with codecs.open('modified-simple.txt', 'a', 'utf8') as f:
                    for x in self.modified:
                        ti = quote(page.name.replace(' ', '_').encode('utf8'))
                        f.write('%s\t%s\t%s\n' % (page.name, x['old'], x['new']))
开发者ID:danmichaelo,项目名称:wikipedia-datofeil,代码行数:56,代码来源:cs1cleanup.py


示例15: remove_template

    def remove_template(self, name, page_nom, page_subject):

        backlinks = page_nom.backlinks(generator = False, redirect = True)
        if page_subject.name in backlinks:
            logger.info('   Fjerner {{Sletting}} fra %s' % page_subject.name)

            text = page_subject.text()
            try:
                dp = TemplateEditor(text)
                if 'Sletting' in dp.templates:
                    dp.templates['Sletting'][0].remove()
                elif 'Slett' in dp.templates:
                    dp.templates['Slett'][0].remove()
                elif 'Slettingfordi' in dp.templates:
                    dp.templates['slettingfordi'][0].remove()
                else:
                    logger.info('  Fant ingen slettemal')
                    return
                text = dp.get_wikitext()
                text = text.strip()
                logger.info('  vha. TemplateEditor')
            except:
                text = re.sub(r'\{\{[Ss]lett.+?\}\}', '', text) # this may fail if template contains subtemplates
                logger.info('  vha. regexp')

            sleeper = sleepers.make()
            while True:
                try:
                    summary = 'Beholdt etter [[%s|slettediskusjon]]' % name
                    if self.simulate:
                        print "--------" + page_subject.name + ": " + summary + "------------"
                        print text
                    else:
                        page_subject.save(text, summary = summary)
                except mwclient.EditError, e:
                    try:
                        sleeper.sleep()
                    except mwclient.MaximumRetriesExceeded:
                        return logger.error('Unable to save page')
                else:
                    return True
开发者ID:icaas,项目名称:SDBot,代码行数:41,代码来源:sdbot.py


示例16: test_find_param_3

 def test_find_param_3(self):
     # Check using get_anonymous_parameters method
     text = 'Lorem ipsum {{lang|fr}} dolor sit amet'
     tpl = TemplateEditor(text).templates['lang'][0]
     params = tpl.get_anonymous_parameters()
     self.assertEqual(params[1], 'fr')
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:6,代码来源:templateeditor2_test.py


示例17: test_blank_template_roundtrip

 def test_blank_template_roundtrip(self):
     # Check that a parameter can be deleted
     text = 'Lorem ipsum {{ }} dolor sit amet'
     dp = TemplateEditor(text)
     self.assertEqual(dp.wikitext(), text)
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:5,代码来源:templateeditor2_test.py


示例18: test_nowiki_roundtrip

 def test_nowiki_roundtrip(self):
     # Check that <nowiki/> is not changed to <nowiki>
     text = 'Lorem ipsum <nowiki/> dolor sit amet'
     dp = TemplateEditor(text)
     self.assertEqual(dp.wikitext(), text)
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:5,代码来源:templateeditor2_test.py


示例19: test_arabic

 def test_arabic(self):
     # Check handling of multibyte chars, unicode level 2
     text = 'Lorem ipsum {{Infoboks العربية}} dolor sit amet'
     dp = TemplateEditor(text)
     self.assertEqual(text, dp.wikitext())
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:5,代码来源:templateeditor2_test.py


示例20: test_onlywhitespace

 def test_onlywhitespace(self):
     # Check that the parser doesn't strip off empty parameters:
     text = '{{some template |   | someval=true}}'
     dp = TemplateEditor(text)
     self.assertEqual(text, dp.wikitext())
开发者ID:edgarskos,项目名称:mwtemplates,代码行数:5,代码来源:templateeditor2_test.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mx.abort函数代码示例发布时间:2022-05-27
下一篇:
Python nodes.Tag类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap