本文整理汇总了Python中mwtemplates.TemplateEditor.wikitext方法的典型用法代码示例。如果您正苦于以下问题:Python TemplateEditor.wikitext方法的具体用法?Python TemplateEditor.wikitext怎么用?Python TemplateEditor.wikitext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mwtemplates.TemplateEditor
的用法示例。
在下文中一共展示了TemplateEditor.wikitext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_edit_anonymous_parameter2
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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)
示例2: test_alter_anonymous_param1
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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)
示例3: test_add_parameter2
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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)
示例4: test_add_parameter3
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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)
示例5: test_delete_template
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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)
示例6: test_edit_parameter_using_value_that_needs_xml_escape
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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¤tPage=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¤tPage=83'
self.assertEqual(dp.wikitext(), result)
示例7: test_edit_nonempty_parameter_alternative
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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)
示例8: test_edit_empty_parameter_with_linebreak
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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)
示例9: test_change_template_name
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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)
示例10: test_edit_parameter_using_integer_alternative
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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)
示例11: check_randompage
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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
示例12: test_delete_parameter_alternative
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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)
示例13: test_delete_parameter
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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)
示例14: __init__
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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']))
示例15: test_nowiki_roundtrip
# 需要导入模块: from mwtemplates import TemplateEditor [as 别名]
# 或者: from mwtemplates.TemplateEditor import wikitext [as 别名]
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)