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

Python expander.expandstr函数代码示例

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

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



在下文中一共展示了expandstr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:aarddict,项目名称:mwlib,代码行数:7,代码来源:test_parser.py


示例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
开发者ID:aarddict,项目名称:mwlib,代码行数:7,代码来源:test_parser.py


示例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
开发者ID:hpschry,项目名称:mwlib,代码行数:7,代码来源:test_parser.py


示例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
开发者ID:hexmode,项目名称:mwlib,代码行数:8,代码来源:test_expr.py


示例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))
开发者ID:pediapress,项目名称:mwlib,代码行数:10,代码来源:test_expander.py


示例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
开发者ID:sdetwiler,项目名称:primer,代码行数:51,代码来源:primer.py


示例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&nbsp;{{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&nbsp;%s" % age
    assert expected in res
开发者ID:pediapress,项目名称:mwlib,代码行数:18,代码来源:test_expander.py


示例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
开发者ID:pediapress,项目名称:mwlib,代码行数:19,代码来源:test_expander.py


示例9: test_convert_ft_in_m_int

def test_convert_ft_in_m_int():
    expandstr("{{convert|12|ft|m}}", "12&nbsp;feet (3.7&nbsp;m)\n", wikidb=getdb())
开发者ID:ASaifM,项目名称:mwlib,代码行数:2,代码来源:test_convert_templates.py


示例10: test_precision_plus_1

def test_precision_plus_1():
    expandstr("{{precision/+|0.77}}", "2", wikidb=getdb())
开发者ID:ASaifM,项目名称:mwlib,代码行数:2,代码来源:test_convert_templates.py


示例11: test_round_plus_2

def test_round_plus_2():
    expandstr("{{rnd/+|1.056|2|5}}", "5", wikidb=getdb())
开发者ID:ASaifM,项目名称:mwlib,代码行数:2,代码来源:test_convert_templates.py


示例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())
开发者ID:ASaifM,项目名称:mwlib,代码行数:4,代码来源:test_convert_templates.py


示例13: test_switch_numeric_comparison

def test_switch_numeric_comparison():
    expandstr("{{ #switch: +07 | 7 = Yes | 007 = Bond | No }}", "Yes")
开发者ID:pediapress,项目名称:mwlib,代码行数:2,代码来源:test_expander.py


示例14: expand_talk

 def expand_talk(tpl, expected):
     return expandstr('{{%s:%s}}' % (tpl, 'Benutzer Diskussion:Anonymous user!/sandbox/my page'),
                      expected, pagename='Help:Irrelevant')
开发者ID:pediapress,项目名称:mwlib,代码行数:3,代码来源:test_expander.py


示例15: e

 def e(a, b):
     return expandstr(a, b, pagename=u'L\xe9onie s')
开发者ID:pediapress,项目名称:mwlib,代码行数:2,代码来源:test_expander.py


示例16: expand_page

 def expand_page(tpl, expected):
     return expandstr('{{%s}}' % tpl, expected,
                      pagename='Benutzer:Anonymous user!/sandbox/my page')
开发者ID:pediapress,项目名称:mwlib,代码行数:3,代码来源:test_expander.py


示例17: test_noinclude_end

def test_noinclude_end():
    expandstr("{{foo}}", "foo", wikidb=DictDB(foo="foo<noinclude>bar should not be in expansion"))
开发者ID:pediapress,项目名称:mwlib,代码行数:2,代码来源:test_expander.py


示例18: test_switch_empty_fallback

def test_switch_empty_fallback():
    expandstr("{{#switch:||foo=good}}", "good")
开发者ID:pediapress,项目名称:mwlib,代码行数:2,代码来源:test_expander.py


示例19: test_monthnumber

def test_monthnumber():
    wikidb = DictDB(MONTHNUMBER="{{#if:{{{1|}}}|{{#switch:{{lc:{{{1}}}}}|january|jan=1|february|feb=2|march|mar=3|apr|april=4|may=5|june|jun=6|july|jul=7|august|aug=8|september|sep=9|october|oct=10|november|nov=11|december|dec=12|{{#ifexpr:{{{1}}}<0|{{#ifexpr:(({{{1}}})round 0)!=({{{1}}})|{{#expr:12-(((0.5-({{{1}}}))round 0)mod 12)}}|{{#expr:12-(((11.5-({{{1}}}))round 0)mod 12)}}}}|{{#expr:(((10.5+{{{1}}})round 0)mod 12)+1}}}}}}|Missing required parameter 1=''month''!}}")

    expandstr("{{MONTHNUMBER|12}}", "12", wikidb=wikidb)
开发者ID:pediapress,项目名称:mwlib,代码行数:4,代码来源:test_expander.py


示例20: test_switch_case_sensitive2

def test_switch_case_sensitive2():
    expandstr("{{ #switch: A | a=lower | UPPER }}", "UPPER")
开发者ID:pediapress,项目名称:mwlib,代码行数:2,代码来源:test_expander.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python core.parse_txt函数代码示例发布时间:2022-05-27
下一篇:
Python advtree.buildAdvancedTree函数代码示例发布时间: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