當前位置: 首頁>>代碼示例>>Python>>正文


Python mwtemplates.TemplateEditor類代碼示例

本文整理匯總了Python中mwtemplates.TemplateEditor的典型用法代碼示例。如果您正苦於以下問題:Python TemplateEditor類的具體用法?Python TemplateEditor怎麽用?Python TemplateEditor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TemplateEditor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的mwtemplates.TemplateEditor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。