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

Python core.walknodel函数代码示例

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

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



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

示例1: test_references_with_paragraphs

def test_references_with_paragraphs():
    s = "<references>\n\n<ref>bla</ref>\n\n</references>"
    r = core.parse_txt(s)
    core.show(r)
    references = core.walknodel(r, lambda x: x.tagname == "references")
    assert len(references) == 1, "expected exactly one references node, got %s" % len(references)
    refs = core.walknodel(references, lambda x: x.tagname == "ref")
    assert len(refs) == 1, "expected exactly one ref node inside the references node, got %s" % len(refs)
开发者ID:pediapress,项目名称:mwlib,代码行数:8,代码来源:test_refine.py


示例2: test_urllink_in_link

def test_urllink_in_link():
    """http://code.pediapress.com/wiki/ticket/602"""
    r = parse_txt("[[foo|[http://baz.com baz]]]")
    li = core.walknodel(r, lambda x: x.type == T.t_complex_link)
    assert len(li) == 1, "expected one link"
    nu = core.walknodel(r, lambda x: x.type == T.t_complex_named_url)
    show(r)
    assert len(nu) == 1, "expected exactly one named url"
开发者ID:pediapress,项目名称:mwlib,代码行数:8,代码来源:test_refine.py


示例3: test_ref_inside_caption

def test_ref_inside_caption():
    s = """
{|
|+ table capshun <ref>references fun</ref>
| hey || ho
|}"""
    r = core.parse_txt(s)
    core.show(r)
    cap = core.walknodel(r, lambda x: x.type == T.t_complex_caption)[0]
    print "caption:"
    core.show(cap)
    refs = core.walknodel(cap, lambda x: x.tagname == "ref")
    assert refs
开发者ID:pediapress,项目名称:mwlib,代码行数:13,代码来源:test_refine.py


示例4: test_urllink_in_brackets

def test_urllink_in_brackets():
    """http://code.pediapress.com/wiki/ticket/556"""
    r = parse_txt("[[http://example.com bla]]")
    show(r)
    nu = core.walknodel(r, lambda x: x.type == T.t_complex_named_url)
    print nu
    assert len(nu) == 1, "expected exactly one named url"
开发者ID:pediapress,项目名称:mwlib,代码行数:7,代码来源:test_refine.py


示例5: test_combine_preformatted

def test_combine_preformatted():
    """http://code.pediapress.com/wiki/ticket/569"""
    s = " preformatted\n and more preformatted\n"
    r = parse_txt(s)
    core.show(r)
    pre = core.walknodel(r, lambda x: x.type == T.t_complex_preformatted)
    assert len(pre) == 1, "expected exactly one preformatted node"
开发者ID:pediapress,项目名称:mwlib,代码行数:7,代码来源:test_refine.py


示例6: test_newline_in_link_text

def test_newline_in_link_text():
    """http://code.pediapress.com/wiki/ticket/906"""
    s = "[[Albert Einstein | Albert\nEinstein]]"
    r = core.parse_txt(s)
    core.show(r)
    links = core.walknodel(r, lambda x: x.type == T.t_complex_link)
    assert links, "no links found"
开发者ID:pediapress,项目名称:mwlib,代码行数:7,代码来源:test_refine.py


示例7: test_ul_inside_star

def test_ul_inside_star():
    """http://code.pediapress.com/wiki/ticket/735"""
    r=core.parse_txt("""
* foo
* bar </ul> baz
""")
    core.show(r)
    ul = core.walknodel(r, lambda x: x.tagname=="ul")
    def baz(x):
        if x.text and "baz" in x.text:
            return True
        
    b1 = core.walknodel(ul, baz)
    b2 = core.walknodel(r, baz)
    
    assert not b1, "baz should not be inside ul"
    assert b2,  "baz missing"
开发者ID:aarddict,项目名称:mwlib,代码行数:17,代码来源:test_refine.py


示例8: test_span_vs_lines

def test_span_vs_lines():
    r = core.parse_txt("""* foo <span> bar
* baz
""")
    core.show(r)

    ul = core.walknodel(r, lambda x: x.tagname == "ul")
    assert len(ul) == 1, "expected one list"
开发者ID:pediapress,项目名称:mwlib,代码行数:8,代码来源:test_refine.py


示例9: test_style_tag_closes_same

def test_style_tag_closes_same():
    r = core.parse_txt("foo<u>bar<u>baz")
    core.show(r)
    utags = core.walknodel(r, lambda x: x.tagname == "u")

    print "utags:", utags
    txt = "".join([T.join_as_text(x.children) for x in utags])
    print "txt:", txt
    assert txt == u"bar"
开发者ID:pediapress,项目名称:mwlib,代码行数:9,代码来源:test_refine.py


示例10: test_tr_inside_caption

def test_tr_inside_caption():
    """http://code.pediapress.com/wiki/ticket/709"""
    s = """
{|
|+ table capshun <tr><td>bla</td></tr>
|}"""
    r = core.parse_txt(s)
    core.show(r)
    cap = core.walknodel(r, lambda x: x.type == T.t_complex_caption)[0]
    print "caption:"
    core.show(cap)

    rows = core.walknodel(r, lambda x: x.type == T.t_complex_table_row)
    print "ROWS:", rows
    assert len(rows) == 1, "no rows found"

    rows = core.walknodel(cap, lambda x: x.type == T.t_complex_table_row)
    print "ROWS:", rows
    assert len(rows) == 0, "row in table caption found"
开发者ID:pediapress,项目名称:mwlib,代码行数:19,代码来源:test_refine.py


示例11: test_no_preformatted_inside_li

def test_no_preformatted_inside_li():
    """stupid: http://code.pediapress.com/wiki/ticket/676"""
    r = parse_txt("""<ol><li>in li:
  foo
  bar
</li></ol>
""")
    core.show(r)
    pre = core.walknodel(r, lambda x: x.type == T.t_complex_preformatted)
    assert not pre, "should not contain preformatted"
开发者ID:pediapress,项目名称:mwlib,代码行数:10,代码来源:test_refine.py


示例12: test_parserfun_in_gallery

def test_parserfun_in_gallery():
    r = core.parse_txt("""<gallery>
Image:ACDC_logo.gif| capshun {{#if: 1|yes}}

</gallery>
""")
    core.show(r)
    txt = T.join_as_text(core.walknodel(r[0].children, lambda x: True))
    print "TXT:", repr(txt)
    assert "capshun" in txt, "bad text??"
    assert "capshun yes" in txt, "#if failed to expand"
开发者ID:pediapress,项目名称:mwlib,代码行数:11,代码来源:test_refine.py


示例13: test_comment_in_gallery

def test_comment_in_gallery():
    """http://code.pediapress.com/wiki/ticket/741"""
    r = core.parse_txt("""<gallery>
Image:ACDC_logo.gif|capshun<!--comment-->
</gallery>
""")
    core.show(r)
    txt = T.join_as_text(core.walknodel(r[0].children, lambda x: True))
    print "TXT:", repr(txt)
    assert "capshun" in txt, "bad text??"
    assert "comment" not in txt, "comment not stripped"
开发者ID:pediapress,项目名称:mwlib,代码行数:11,代码来源:test_refine.py


示例14: test_named_url_in_double_brackets

def test_named_url_in_double_brackets():
    """http://code.pediapress.com/wiki/ticket/556"""
    r = core.parse_txt("[[http://foo.com baz]]")
    core.show(r)
    named = core.walknodel(r, lambda x: x.type == T.t_complex_named_url)
    assert len(named) == 1, "expected a named url"
    txt = T.join_as_text(r)
    print "TXT:", repr(txt)
    assert "[" in txt, "missing ["
    assert "]" in txt, "missing ]"
    assert "[[" not in txt, "bad text"
    assert "]]" not in txt, "bad text"
开发者ID:pediapress,项目名称:mwlib,代码行数:12,代码来源:test_refine.py


示例15: test_parse_ul_not_preformatted

def test_parse_ul_not_preformatted():
    """http://code.pediapress.com/wiki/ticket/554"""
    s = """
<ul>
   <li>bla blub
   <li>bla bla
 </ul>
"""
    r = parse_txt(s)
    core.show(r)
    pre = core.walknodel(r, lambda x: x.type == T.t_complex_preformatted)
    assert not pre, "should contain no preformatted nodes"
开发者ID:pediapress,项目名称:mwlib,代码行数:12,代码来源:test_refine.py


示例16: test_link_vs_namedurl

def test_link_vs_namedurl():
    r = core.parse_txt("[[acdc [http://web.de bla]]")
    core.show(r)
    txt = T.join_as_text(r)
    print "TXT:", repr(txt)

    assert "[[acdc " in txt, "wrong text"
    assert txt.endswith("]"), "wrong text"

    assert r[0].type != T.t_complex_link, "should not be an article link"

    urls = core.walknodel(r, lambda x: x.type == T.t_complex_named_url)
    assert len(urls) == 1, "no named url found"
开发者ID:pediapress,项目名称:mwlib,代码行数:13,代码来源:test_refine.py


示例17: test_link_in_table_caption

def test_link_in_table_caption():
    """http://code.pediapress.com/wiki/ticket/578"""
    s = """{|
|+ id="CFNP" [[bla | blubb]]
|-
| a || b
|}
"""
    r = parse_txt(s)
    with_vlist = core.walknodel(r, lambda x: bool(x.vlist))
    print with_vlist

    assert not with_vlist, "no node should contain a vlist"
开发者ID:pediapress,项目名称:mwlib,代码行数:13,代码来源:test_refine.py


示例18: test_tab_table

def test_tab_table():
    s = """
\t{|
|-
\t| cell1
| cell2
\t|}after
"""
    r = core.parse_txt(s)
    core.show(r)
    tables = []

    def allowed(node):
        retval = bool(tables)
        if node.type == T.t_complex_table:
            tables.append(node)
        return retval
    nodes = [x for x in r if allowed(x)]
    assert nodes, "bad  or no table"

    cells = core.walknodel(r, lambda x: x.type == T.t_complex_table_cell)
    assert len(cells) == 2, "expected two cells"
开发者ID:pediapress,项目名称:mwlib,代码行数:22,代码来源:test_refine.py


示例19: test_ref_drop_text_newlines

def test_ref_drop_text_newlines():
    """http://code.pediapress.com/wiki/ticket/812"""
    r = core.parse_txt("<ref>bar\n\n</ref>")
    core.show(r)
    txt = T.join_as_text(core.walknodel(r, lambda x: 1))
    assert "bar" in txt, "text dropped"
开发者ID:pediapress,项目名称:mwlib,代码行数:6,代码来源:test_refine.py


示例20: test_var_tag

def test_var_tag():
    r = parse_txt("<var>strike</var>")
    s = core.walknodel(r, lambda x: x.tagname == "var")
    assert len(s) == 1
开发者ID:pediapress,项目名称:mwlib,代码行数:4,代码来源:test_refine.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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