本文整理汇总了Python中mwlib.expander.expandstr函数的典型用法代码示例。如果您正苦于以下问题:Python expandstr函数的具体用法?Python expandstr怎么用?Python expandstr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了expandstr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parse_comment
def test_parse_comment():
ex = """foo
<!-- comment --->
bar"""
expanded = expander.expandstr(ex)
print "EXPANDED:", expanded
assert "\n\n" not in expanded
示例2: test_comment_inside_nowiki
def test_comment_inside_nowiki():
comment = 'this is a comment'
s=expander.expandstr('<pre><!-- this is a comment --></pre>')
assert comment in s
r=parse(s)
txt = r.asText()
assert 'this is a comment' in txt
示例3: test_comment_inside_nowiki
def test_comment_inside_nowiki():
comment = "this is a comment"
s = expander.expandstr("<pre><!-- this is a comment --></pre>")
assert comment in s
r = parse(s)
txt = r.asText()
assert "this is a comment" in txt
示例4: ee
def ee(s, expected=None):
s = expandstr("{{#expr:%s}}" % (s,))
if isinstance(expected, (float, int, long)):
assert math.fabs(float(s) - expected) < 1e-5
elif expected is not None:
assert s == expected, "expected %r, got %r" % (expected, s)
return s
示例5: test_parmpart
def test_parmpart():
parmpart = """{{#ifeq:/{{{2|}}}
|{{#titleparts:/{{{2|}}}|1|{{#expr:1+{{{1|1}}}}}}}
|
|{{#titleparts:/{{{2|}}}|1|{{#expr:1+{{{1|1}}}}}}}
}}"""
expandstr("{{ParmPart|0|a/b}}", "", wikidb=DictDB(ParmPart=parmpart))
expandstr("{{ParmPart|1|a/b}}", "a", wikidb=DictDB(ParmPart=parmpart))
expandstr("{{ParmPart|2|a/b}}", "b", wikidb=DictDB(ParmPart=parmpart))
expandstr("{{ParmPart|3|a/b}}", "", wikidb=DictDB(ParmPart=parmpart))
示例6: get_article
def get_article(self, topic):
global usejsoncache
global threaded
cacheDir = "./json_cache/{}".format(self.wiki_version)
try:
os.mkdir(cacheDir)
except:
pass
filename = "{}/{}".format(cacheDir, topic)
if usejsoncache is True and os.path.isfile(filename):
print "cache hit for " + topic
js = open(filename).read()
else:
markup = self.get_markup_for_topic(topic)
templParser = mwlib.templ.parser.Parser(markup)
templates = templParser.parse()
print "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
markup = ""
for t in templates:
# print "==>{} {}<==".format(type(t), t)
if isinstance(t, unicode):
markup+= t
elif isinstance(t, mwlib.templ.nodes.Template):
print "==>{}<==".format(t[0])
if t[0] == "Wide image":
print " -->{}<--".format(t[1][0])
markup+= " [[File:{}]] ".format(t[1][0])
# print article
print "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
markup = expandstr(markup)
# print markup
article = compat.parse_txt(markup)
self.reset()
if threaded:
self.build_related_media(article)
else:
print "Not performing threaded processing"
self.depth_first(article)
obj = {"content":self.content, "title":topic, "url":"https://{}.wikipedia.org/wiki/{}".format(self.wiki_version, topic), "url":"https://{}.wikipedia.org/wiki/{}".format(self.wiki_version, topic)}
js = json.dumps(obj, indent=2)
open(filename, "w").write(js)
return js
示例7: test_birth_date_and_age
def test_birth_date_and_age():
db = DictDB({
"birth date and age": '[[ {{{3|{{{day|{{{3}}}}}}}}}]] [[{{{1|{{{year|{{{1}}}}}}}}}]]<font class="noprint"> (age {{age | {{{1|{{{year|{{{1}}}}}}}}} | {{{2|{{{month|{{{2}}}}}}}}} | {{{3|{{{day|{{{3}}}}}}}}} }})</font>',
"age": '<includeonly>{{#expr:({{{4|{{CURRENTYEAR}}}}})-({{{1}}})-(({{{5|{{CURRENTMONTH}}}}})<({{{2}}})or({{{5|{{CURRENTMONTH}}}}})=({{{2}}})and({{{6|{{CURRENTDAY}}}}})<({{{3}}}))}}</includeonly>',
})
res = expandstr('{{birth date and age|1960|02|8}}', wikidb=db)
print "EXPANDED:", repr(res)
import datetime
now = datetime.datetime.now()
b = datetime.datetime(1960, 2, 8)
age = now.year - b.year
if now.month * 32 + now.day < b.month * 32 + b.day:
age -= 1
expected = u"age %s" % age
assert expected in res
示例8: test_pipe_inside_imagemap
def test_pipe_inside_imagemap():
"""pipes inside image maps should not separate template arguments
well, they do not separate arguments with the version running on en.wikipedia.org.
they do separate arguments with the version running on pediapress.com:8080.
(which is hopefully a newer version)
"""
db = DictDB(
sp="""{{#ifeq: {{{1}}} | 1
| <imagemap>
Image:Padlock-silver-medium.svg|20px
rect 0 0 1000 1000 [[Wikipedia:Protection policy|This page has been semi-protected from editing]]
desc none
</imagemap>
|bla
}}
""")
result = expandstr("{{sp|1}}", wikidb=db)
assert "</imagemap>" in result
示例9: test_convert_ft_in_m_int
def test_convert_ft_in_m_int():
expandstr("{{convert|12|ft|m}}", "12 feet (3.7 m)\n", wikidb=getdb())
示例10: test_precision_plus_1
def test_precision_plus_1():
expandstr("{{precision/+|0.77}}", "2", wikidb=getdb())
示例11: test_round_plus_2
def test_round_plus_2():
expandstr("{{rnd/+|1.056|2|5}}", "5", wikidb=getdb())
示例12: test_round
def test_round():
expandstr("{{rnd|2.0004|3}}", "2.000", wikidb=getdb())
expandstr("{{rnd|0.000020004|8}}", "2.0E-5000", wikidb=getdb())
expandstr("{{rnd|0|8}}", "0.00000000", wikidb=getdb())
示例13: test_switch_numeric_comparison
def test_switch_numeric_comparison():
expandstr("{{ #switch: +07 | 7 = Yes | 007 = Bond | No }}", "Yes")
示例14: expand_talk
def expand_talk(tpl, expected):
return expandstr('{{%s:%s}}' % (tpl, 'Benutzer Diskussion:Anonymous user!/sandbox/my page'),
expected, pagename='Help:Irrelevant')
示例15: e
def e(a, b):
return expandstr(a, b, pagename=u'L\xe9onie s')