当前位置: 首页>>代码示例>>Python>>正文


Python uparser.parseString函数代码示例

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


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

示例1: test_colspan

def test_colspan():
    raw = '''<table><tr><td colspan="bogus">no colspan </td></tr></table>'''
    r = parseString(title='t', raw=raw)
    buildAdvancedTree(r)
    assert r.getChildNodesByClass(Cell)[0].colspan is 1

    raw = '''<table><tr><td colspan="-1">no colspan </td></tr></table>'''
    r = parseString(title='t', raw=raw)
    buildAdvancedTree(r)
    assert r.getChildNodesByClass(Cell)[0].colspan is 1

    raw = '''<table><tr><td colspan="2">colspan1</td></tr></table>'''
    r = parseString(title='t', raw=raw)
    buildAdvancedTree(r)
    assert r.getChildNodesByClass(Cell)[0].colspan is 2
开发者ID:UltraNurd,项目名称:mwlib,代码行数:15,代码来源:test_advtree.py

示例2: test_identity

def test_identity():
    raw = """
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
""".decode("utf8")

    db = DummyDB()
    r = parseString(title="X33", raw=raw, wikidb=db)
    buildAdvancedTree(r)
    _treesanity(r)

    brs = r.getChildNodesByClass(BreakingReturn)
    for i, br in enumerate(brs):
        assert br in br.siblings
        assert i == _idIndex(br.parent.children, br)
        assert len([x for x in br.parent.children if x is not br]) == len(brs) - 1
        for bbr in brs:
            if br is bbr:
                continue
            assert br == bbr
            assert br is not bbr
开发者ID:UltraNurd,项目名称:mwlib,代码行数:27,代码来源:test_advtree.py

示例3: test_copy

def test_copy():
    raw = """
===[[Leuchtturm|Leuchttürme]] auf Fehmarn===
*[[Leuchtturm Flügge]] super da
*[[Leuchtturm Marienleuchte]] da auch
*[[Leuchtturm Strukkamphuk]] spitze
*[[Leuchtturm Staberhuk]] supi
*[[Leuchtturm Westermarkelsdorf]]
""".decode(
        "utf8"
    )

    db = DummyDB()
    r = parseString(title="X33", raw=raw, wikidb=db)
    buildAdvancedTree(r)
    c = r.copy()
    _treesanity(c)

    def _check(n1, n2):
        assert n1.caption == n2.caption
        assert n1.__class__ == n2.__class__
        assert len(n1.children) == len(n2.children)
        for i, c1 in enumerate(n1):
            _check(c1, n2.children[i])

    _check(r, c)
开发者ID:aarddict,项目名称:mwlib,代码行数:26,代码来源:test_advtree.py

示例4: convert_pagecontent

def convert_pagecontent(title, content):
    """
    Convert a string in Mediawiki content format to a string in
    Dokuwiki content format.
    """

    # this is a hack for mwlib discarding the content of <nowiki> tags
    # and replacing them with plaintext parsed HTML versions of the
    # content (pragmatic, but not what we want)
    nowiki_plaintext = []

    # Instead we save the content here, replace it with the "magic" placeholder
    # tag <__yamdwe_nowiki> and the index where the content was saved, then pass
    # the list of nowiki content into the parser as context.
    def add_nowiki_block(match):
        nowiki_plaintext.append(match.group(0))
        return "<__yamdwe_nowiki>%d</__yamdwe_nowiki>" % (len(nowiki_plaintext)-1,)
    content = re.sub(r"<nowiki>.+?</nowiki>", add_nowiki_block, content)

    root = uparser.parseString(title, content) # create parse tree
    context = {}
    context["list_stack"] = []
    context["nowiki_plaintext"] = nowiki_plaintext # hacky way of attaching to child nodes
    result = convert(root, context, False)

    # mwlib doesn't parse NOTOC, so check for it manually
    if re.match(r"^\s*__NOTOC__\s*$", content, re.MULTILINE):
        result = "~~NOTOC~~"+("\n" if not result.startswith("\n") else "")+result
    return result
开发者ID:lordofbikes,项目名称:yamdwe,代码行数:29,代码来源:wikicontent.py

示例5: getUserLinks

    def getUserLinks(raw):
        def isUserLink(node):
            return isinstance(node, parser.NamespaceLink) and node.namespace == 2  # NS_USER

        result = list(set([u.target for u in uparser.parseString(title, raw=raw, wikidb=wikidb).filter(isUserLink)]))
        result.sort()
        return result
开发者ID:hexmode,项目名称:mwlib,代码行数:7,代码来源:nuwiki.py

示例6: getXHTML

def getXHTML(wikitext):
    db = DummyDB()
    r = parseString(title="test", raw=wikitext, wikidb=db)
    preprocess(r)
    show(sys.stdout, r)
    dbw = MWXHTMLWriter()
    dbw.writeBook(r)
    return dbw.asstring()
开发者ID:aarddict,项目名称:mwlib.xhtml,代码行数:8,代码来源:test_xhtmlwriter.py

示例7: getXHTML

def getXHTML(wikitext):
    db = DummyDB()
    r = parseString(title="", raw=wikitext, wikidb=db)
    preprocess(r)
    dbw = MWXHTMLWriter()
    with SuppressOutput():
        dbw.writeBook(r)
    return dbw.asstring()
开发者ID:michaelmrose,项目名称:dotfiles,代码行数:8,代码来源:wikitext2xhtml.py

示例8: test_tag_expand_vs_uniq

def test_tag_expand_vs_uniq():
    db = DictDB(
        Foo = """{{#tag:pre|inside pre}}"""
        )
    r=uparser.parseString(title="Foo", wikidb=db)
    core.show(r)
    pre = r.find(parser.PreFormatted)
    assert len(pre)==1, "expected a preformatted node"
开发者ID:aarddict,项目名称:mwlib,代码行数:8,代码来源:test_parser.py

示例9: getAdvTree

def getAdvTree(fn):
    from mwlib.dummydb import DummyDB
    from mwlib.uparser import parseString
    db = DummyDB()
    input = unicode(open(fn).read(), 'utf8')
    r = parseString(title=fn, raw=input, wikidb=db)
    buildAdvancedTree(r)
    return r
开发者ID:ASaifM,项目名称:mwlib,代码行数:8,代码来源:advtree.py

示例10: parse_tree

def parse_tree(file_name):
    dp = dumpparser.DumpParser("data/wiki-data.xml")
    data = []
    for recipe in dp:
        data.append( (recipe.pageid,
                      recipe.title,
                      parser.parseString(recipe.text, recipe.text)) )
    return data
开发者ID:jolynch,项目名称:food.op,代码行数:8,代码来源:parse_data.py

示例11: parse_wiki

def parse_wiki(name, wiki, make_math_png=False):
    c = cdbwiki.WikiDB(default_wiki_dir)
    a = uparser.parseString(name, raw=wiki, wikidb=c)
    out = StringIO.StringIO()
    mr = rendermath.Renderer(basedir=default_math_dir,
            lazy=(not make_math_png))
    w = htmlwriter.HTMLWriter(out, images=None, math_renderer=mr)
    w.write(a)
    return out.getvalue()
开发者ID:yindian,项目名称:pyswim,代码行数:9,代码来源:swim.py

示例12: simpleparse

def simpleparse(raw):    # !!! USE FOR DEBUGGING ONLY !!! 
    import sys
    from mwlib import dummydb, parser
    from mwlib.uparser import parseString
    input = raw.decode('utf8')
    r = parseString(title="title", raw=input, wikidb=dummydb.DummyDB())
    buildAdvancedTree(r)
    parser.show(sys.stdout, r, 0)
    return r
开发者ID:ASaifM,项目名称:mwlib,代码行数:9,代码来源:advtree.py

示例13: test_ulist

def test_ulist():
    """http://code.pediapress.com/wiki/ticket/222"""
    raw = u"""
* A item
*: B Previous item continues.
"""
    r = parseString(title='t', raw=raw)
    buildAdvancedTree(r)
#    parser.show(sys.stdout, r)
    assert len(r.getChildNodesByClass(Item)) == 1
开发者ID:UltraNurd,项目名称:mwlib,代码行数:10,代码来源:test_advtree.py

示例14: getParsedArticle

 def getParsedArticle(self, title, revision=None):
     raw = self.getRawArticle(title, revision=revision)
     if raw is None:
         return None
     article = self._getArticle(title, revision=revision)
     lang = None
     source = self.getSource(title, revision=revision)
     if source is not None:
         lang = source.get('language')
     return uparser.parseString(title=title, raw=raw, wikidb=self, lang=lang)
开发者ID:cscott,项目名称:wikiserver,代码行数:10,代码来源:wikidbbase.py

示例15: getXML

def getXML(wikitext):
    db = DummyDB()
    r = parseString(title="test", raw=wikitext, wikidb=db)
    print "before preprocess"
    show(sys.stdout, r)
    preprocess(r)
    print "after preprocess"
    show(sys.stdout, r)
    dbw = DocBookWriter()
    dbw.dbwriteArticle(r)
    return dbw.asstring()
开发者ID:aarddict,项目名称:mwlib,代码行数:11,代码来源:test_docbookwriter.py


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