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

Python nodes.Tag类代码示例

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

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



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

示例1: test_contents

 def test_contents(self):
     """test getter/setter for the contents attribute"""
     contents = wraptext("text")
     node = Tag(wraptext("ref"), contents)
     self.assertIs(contents, node.contents)
     node.contents = "text and a {{template}}"
     parsed = wrap([Text("text and a "), Template(wraptext("template"))])
     self.assertWikicodeEqual(parsed, node.contents)
     self.assertEqual("<ref>text and a {{template}}</ref>", node)
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:9,代码来源:test_tag.py


示例2: test_closing_tag

 def test_closing_tag(self):
     """test getter/setter for the closing_tag attribute"""
     tag = wraptext("ref")
     node = Tag(tag, wraptext("foobar"))
     self.assertIs(tag, node.closing_tag)
     node.closing_tag = "ref {{ignore me}}"
     parsed = wrap([Text("ref "), Template(wraptext("ignore me"))])
     self.assertWikicodeEqual(parsed, node.closing_tag)
     self.assertEqual("<ref>foobar</ref {{ignore me}}>", node)
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:9,代码来源:test_tag.py


示例3: test_implicit

 def test_implicit(self):
     """test getter/setter for the implicit attribute"""
     node = Tag(wraptext("br"), self_closing=True)
     self.assertFalse(node.implicit)
     node.implicit = True
     self.assertTrue(node.implicit)
     self.assertEqual("<br>", node)
     node.implicit = 0
     self.assertFalse(node.implicit)
     self.assertEqual("<br/>", node)
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:10,代码来源:test_tag.py


示例4: test_invalid

 def test_invalid(self):
     """test getter/setter for the invalid attribute"""
     node = Tag(wraptext("br"), self_closing=True, implicit=True)
     self.assertFalse(node.invalid)
     node.invalid = True
     self.assertTrue(node.invalid)
     self.assertEqual("</br>", node)
     node.invalid = 0
     self.assertFalse(node.invalid)
     self.assertEqual("<br>", node)
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:10,代码来源:test_tag.py


示例5: test_self_closing

 def test_self_closing(self):
     """test getter/setter for the self_closing attribute"""
     node = Tag(wraptext("ref"), wraptext("foobar"))
     self.assertFalse(node.self_closing)
     node.self_closing = True
     self.assertTrue(node.self_closing)
     self.assertEqual("<ref/>", node)
     node.self_closing = 0
     self.assertFalse(node.self_closing)
     self.assertEqual("<ref>foobar</ref>", node)
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:10,代码来源:test_tag.py


示例6: test_wiki_markup

 def test_wiki_markup(self):
     """test getter/setter for the wiki_markup attribute"""
     node = Tag(wraptext("i"), wraptext("italic text"))
     self.assertIs(None, node.wiki_markup)
     node.wiki_markup = "''"
     self.assertEqual("''", node.wiki_markup)
     self.assertEqual("''italic text''", node)
     node.wiki_markup = False
     self.assertFalse(node.wiki_markup)
     self.assertEqual("<i>italic text</i>", node)
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:10,代码来源:test_tag.py


示例7: test_tag

 def test_tag(self):
     """test getter/setter for the tag attribute"""
     tag = wraptext("ref")
     node = Tag(tag, wraptext("text"))
     self.assertIs(tag, node.tag)
     self.assertIs(tag, node.closing_tag)
     node.tag = "span"
     self.assertWikicodeEqual(wraptext("span"), node.tag)
     self.assertWikicodeEqual(wraptext("span"), node.closing_tag)
     self.assertEqual("<span>text</span>", node)
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:10,代码来源:test_tag.py


示例8: test_wiki_style_separator

 def test_wiki_style_separator(self):
     """test getter/setter for wiki_style_separator attribute"""
     node = Tag(wraptext("table"), wraptext("\n"))
     self.assertIs(None, node.wiki_style_separator)
     node.wiki_style_separator = "|"
     self.assertEqual("|", node.wiki_style_separator)
     node.wiki_markup = "{"
     self.assertEqual("{|\n{", node)
     node2 = Tag(wraptext("table"), wraptext("\n"), wiki_style_separator="|")
     self.assertEqual("|", node.wiki_style_separator)
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:10,代码来源:test_tag.py


示例9: test_showtree

 def test_showtree(self):
     """test Tag.__showtree__()"""
     output = []
     getter, marker = object(), object()
     get = lambda code: output.append((getter, code))
     mark = lambda: output.append(marker)
     node1 = Tag(wraptext("ref"), wraptext("text"), [agen("name", "foo")])
     node2 = Tag(wraptext("br"), self_closing=True, padding=" ")
     node3 = Tag(wraptext("br"), self_closing=True, invalid=True, implicit=True, padding=" ")
     node1.__showtree__(output.append, get, mark)
     node2.__showtree__(output.append, get, mark)
     node3.__showtree__(output.append, get, mark)
     valid = [
         "<",
         (getter, node1.tag),
         (getter, node1.attributes[0].name),
         "    = ",
         marker,
         (getter, node1.attributes[0].value),
         ">",
         (getter, node1.contents),
         "</",
         (getter, node1.closing_tag),
         ">",
         "<",
         (getter, node2.tag),
         "/>",
         "</",
         (getter, node3.tag),
         ">",
     ]
     self.assertEqual(valid, output)
开发者ID:vedmaka,项目名称:ipc-parser,代码行数:32,代码来源:test_tag.py


示例10: test_padding

 def test_padding(self):
     """test getter/setter for the padding attribute"""
     node = Tag(wraptext("ref"), wraptext("foobar"))
     self.assertEqual("", node.padding)
     node.padding = "  "
     self.assertEqual("  ", node.padding)
     self.assertEqual("<ref  >foobar</ref>", node)
     node.padding = None
     self.assertEqual("", node.padding)
     self.assertEqual("<ref>foobar</ref>", node)
     self.assertRaises(ValueError, setattr, node, "padding", True)
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:11,代码来源:test_tag.py


示例11: test_closing_wiki_markup

 def test_closing_wiki_markup(self):
     """test getter/setter for closing_wiki_markup attribute"""
     node = Tag(wraptext("table"), wraptext("\n"))
     self.assertIs(None, node.closing_wiki_markup)
     node.wiki_markup = "{|"
     self.assertEqual("{|", node.closing_wiki_markup)
     node.closing_wiki_markup = "|}"
     self.assertEqual("|}", node.closing_wiki_markup)
     self.assertEqual("{|\n|}", node)
     node.wiki_markup = "!!"
     self.assertEqual("|}", node.closing_wiki_markup)
     self.assertEqual("!!\n|}", node)
     node.wiki_markup = False
     self.assertFalse(node.closing_wiki_markup)
     self.assertEqual("<table>\n</table>", node)
     node2 = Tag(wraptext("table"), wraptext("\n"),
                 attrs=[agen("id", "foo")], wiki_markup="{|",
                 closing_wiki_markup="|}")
     self.assertEqual("|}", node2.closing_wiki_markup)
     self.assertEqual('{| id="foo"\n|}', node2)
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:20,代码来源:test_tag.py


示例12: test_children

    def test_children(self):
        """test Tag.__children__()"""
        # <ref>foobar</ref>
        node1 = Tag(wraptext("ref"), wraptext("foobar"))
        # '''bold text'''
        node2 = Tag(wraptext("b"), wraptext("bold text"), wiki_markup="'''")
        # <img id="foo" class="bar" selected />
        node3 = Tag(wraptext("img"),
                    attrs=[agen("id", "foo"), agen("class", "bar"),
                           agennv("selected")],
                    self_closing=True, padding=" ")

        gen1 = node1.__children__()
        gen2 = node2.__children__()
        gen3 = node3.__children__()
        self.assertEqual(node1.tag, next(gen1))
        self.assertEqual(node3.tag, next(gen3))
        self.assertEqual(node3.attributes[0].name, next(gen3))
        self.assertEqual(node3.attributes[0].value, next(gen3))
        self.assertEqual(node3.attributes[1].name, next(gen3))
        self.assertEqual(node3.attributes[1].value, next(gen3))
        self.assertEqual(node3.attributes[2].name, next(gen3))
        self.assertEqual(node1.contents, next(gen1))
        self.assertEqual(node2.contents, next(gen2))
        self.assertEqual(node1.closing_tag, next(gen1))
        self.assertRaises(StopIteration, next, gen1)
        self.assertRaises(StopIteration, next, gen2)
        self.assertRaises(StopIteration, next, gen3)
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:28,代码来源:test_tag.py


示例13: test_remove

 def test_remove(self):
     """test Tag.remove()"""
     attrs = [agen("id", "foo"), agenp("class", "bar", "  ", "\n", "\n"),
              agen("foo", "bar"), agenpnv("foo", " ", "  \n ", " \t")]
     node = Tag(wraptext("div"), attrs=attrs, self_closing=True)
     node.remove("class")
     self.assertEqual('<div id="foo" foo="bar" foo  \n />', node)
     node.remove("foo")
     self.assertEqual('<div id="foo"/>', node)
     self.assertRaises(ValueError, node.remove, "foo")
     node.remove("id")
     self.assertEqual('<div/>', node)
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:12,代码来源:test_tag.py


示例14: test_strip

    def test_strip(self):
        """test Tag.__strip__()"""
        node1 = Tag(wraptext("i"), wraptext("foobar"))
        node2 = Tag(wraptext("math"), wraptext("foobar"))
        node3 = Tag(wraptext("br"), self_closing=True)

        self.assertEqual("foobar", node1.__strip__())
        self.assertEqual(None, node2.__strip__())
        self.assertEqual(None, node3.__strip__())
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:9,代码来源:test_tag.py


示例15: test_iternodes

    def test_iternodes(self):
        """test Tag.__iternodes__()"""
        node1n1, node1n2 = Text("ref"), Text("foobar")
        node2n1, node3n1, node3n2 = Text("bold text"), Text("img"), Text("id")
        node3n3, node3n4, node3n5 = Text("foo"), Text("class"), Text("bar")

        # <ref>foobar</ref>
        node1 = Tag(wrap([node1n1]), wrap([node1n2]))
        # '''bold text'''
        node2 = Tag(wraptext("b"), wrap([node2n1]), wiki_markup="'''")
        # <img id="foo" class="bar" />
        node3 = Tag(
            wrap([node3n1]),
            attrs=[Attribute(wrap([node3n2]), wrap([node3n3])), Attribute(wrap([node3n4]), wrap([node3n5]))],
            self_closing=True,
            padding=" ",
        )

        gen1 = node1.__iternodes__(getnodes)
        gen2 = node2.__iternodes__(getnodes)
        gen3 = node3.__iternodes__(getnodes)
        self.assertEqual((None, node1), next(gen1))
        self.assertEqual((None, node2), next(gen2))
        self.assertEqual((None, node3), next(gen3))
        self.assertEqual((node1.tag, node1n1), next(gen1))
        self.assertEqual((node3.tag, node3n1), next(gen3))
        self.assertEqual((node3.attributes[0].name, node3n2), next(gen3))
        self.assertEqual((node3.attributes[0].value, node3n3), next(gen3))
        self.assertEqual((node3.attributes[1].name, node3n4), next(gen3))
        self.assertEqual((node3.attributes[1].value, node3n5), next(gen3))
        self.assertEqual((node1.contents, node1n2), next(gen1))
        self.assertEqual((node2.contents, node2n1), next(gen2))
        self.assertEqual((node1.closing_tag, node1n1), next(gen1))
        self.assertRaises(StopIteration, next, gen1)
        self.assertRaises(StopIteration, next, gen2)
        self.assertRaises(StopIteration, next, gen3)
开发者ID:vedmaka,项目名称:ipc-parser,代码行数:36,代码来源:test_tag.py


示例16: test_add

 def test_add(self):
     """test Tag.add()"""
     node = Tag(wraptext("ref"), wraptext("cite"))
     node.add("name", "value")
     node.add("name", "value", quotes=None)
     node.add("name", "value", quotes="'")
     node.add("name")
     node.add(1, False)
     node.add("style", "{{foobar}}")
     node.add("name", "value", '"', "\n", " ", "   ")
     attr1 = ' name="value"'
     attr2 = " name=value"
     attr3 = " name='value'"
     attr4 = " name"
     attr5 = ' 1="False"'
     attr6 = ' style="{{foobar}}"'
     attr7 = '\nname =   "value"'
     self.assertEqual(attr1, node.attributes[0])
     self.assertEqual(attr2, node.attributes[1])
     self.assertEqual(attr3, node.attributes[2])
     self.assertEqual(attr4, node.attributes[3])
     self.assertEqual(attr5, node.attributes[4])
     self.assertEqual(attr6, node.attributes[5])
     self.assertEqual(attr7, node.attributes[6])
     self.assertEqual(attr7, node.get("name"))
     self.assertWikicodeEqual(wrap([Template(wraptext("foobar"))]),
                              node.attributes[5].value)
     self.assertEqual("".join(("<ref", attr1, attr2, attr3, attr4, attr5,
                               attr6, attr7, ">cite</ref>")), node)
     self.assertRaises(ValueError, node.add, "name", "foo", quotes="bar")
     self.assertRaises(ValueError, node.add, "name", "a bc d", quotes=None)
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:31,代码来源:test_tag.py


示例17: test_get

    def test_get(self):
        """test Tag.get()"""
        attrs = [agen("name", "foo")]
        node = Tag(wraptext("ref"), wraptext("cite"), attrs)
        self.assertIs(attrs[0], node.get("name"))
        self.assertIs(attrs[0], node.get("  name  "))
        self.assertIs(attrs[0], node.get(wraptext("name")))
        self.assertRaises(ValueError, node.get, "Name")
        self.assertRaises(ValueError, node.get, "foo")

        attrs = [agen("id", "foo"), agenp("class", "bar", "  ", "\n", "\n"),
                 agen("foo", "bar"), agenpnv("foo", " ", "  \n ", " \t")]
        node2 = Tag(wraptext("div"), attrs=attrs, self_closing=True)
        self.assertIs(attrs[0], node2.get("id"))
        self.assertIs(attrs[1], node2.get("class"))
        self.assertIs(attrs[1], node2.get(
            attrs[1].pad_first + str(attrs[1].name) + attrs[1].pad_before_eq))
        self.assertIs(attrs[3], node2.get(attrs[3]))
        self.assertIs(attrs[3], node2.get(str(attrs[3])))
        self.assertIs(attrs[3], node2.get(" foo"))
        self.assertRaises(ValueError, node2.get, "idclass")
        self.assertRaises(ValueError, node2.get, "id class")
        self.assertRaises(ValueError, node2.get, "id=foo")
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:23,代码来源:test_tag.py


示例18: test_has

    def test_has(self):
        """test Tag.has()"""
        node = Tag(wraptext("ref"), wraptext("cite"), [agen("name", "foo")])
        self.assertTrue(node.has("name"))
        self.assertTrue(node.has("  name  "))
        self.assertTrue(node.has(wraptext("name")))
        self.assertFalse(node.has("Name"))
        self.assertFalse(node.has("foo"))

        attrs = [agen("id", "foo"), agenp("class", "bar", "  ", "\n", "\n"),
                 agen("foo", "bar"), agenpnv("foo", " ", "  \n ", " \t")]
        node2 = Tag(wraptext("div"), attrs=attrs, self_closing=True)
        self.assertTrue(node2.has("id"))
        self.assertTrue(node2.has("class"))
        self.assertTrue(node2.has(attrs[1].pad_first + str(attrs[1].name) +
                                  attrs[1].pad_before_eq))
        self.assertTrue(node2.has(attrs[3]))
        self.assertTrue(node2.has(str(attrs[3])))
        self.assertFalse(node2.has("idclass"))
        self.assertFalse(node2.has("id class"))
        self.assertFalse(node2.has("id=foo"))
开发者ID:earwig,项目名称:mwparserfromhell,代码行数:21,代码来源:test_tag.py


示例19: test_add

 def test_add(self):
     """test Tag.add()"""
     node = Tag(wraptext("ref"), wraptext("cite"))
     node.add("name", "value")
     node.add("name", "value", quoted=False)
     node.add("name")
     node.add(1, False)
     node.add("style", "{{foobar}}")
     node.add("name", "value", True, "\n", " ", "   ")
     attr1 = ' name="value"'
     attr2 = " name=value"
     attr3 = " name"
     attr4 = ' 1="False"'
     attr5 = ' style="{{foobar}}"'
     attr6 = '\nname =   "value"'
     self.assertEqual(attr1, node.attributes[0])
     self.assertEqual(attr2, node.attributes[1])
     self.assertEqual(attr3, node.attributes[2])
     self.assertEqual(attr4, node.attributes[3])
     self.assertEqual(attr5, node.attributes[4])
     self.assertEqual(attr6, node.attributes[5])
     self.assertEqual(attr6, node.get("name"))
     self.assertWikicodeEqual(wrap([Template(wraptext("foobar"))]), node.attributes[4].value)
     self.assertEqual("".join(("<ref", attr1, attr2, attr3, attr4, attr5, attr6, ">cite</ref>")), node)
开发者ID:vedmaka,项目名称:ipc-parser,代码行数:24,代码来源:test_tag.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python mwtemplates.TemplateEditor类代码示例发布时间:2022-05-27
下一篇:
Python compat.str函数代码示例发布时间: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