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

Python uparser.parseString函数代码示例

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

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



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


示例16: getXHTML

def getXHTML(wikitext, title, language):
    db = DummyDB()
    db.normalize_and_get_page = noop
    r = parseString(title=title, raw=wikitext, wikidb=db, lang=language)
    if not r:
        return None
    preprocess(r)
    removeLangLinks(r)
    dbw = MWXHTMLWriter()
    dbw.writeBook(r)
    return dbw.asstring()
开发者ID:lazycrazyowl,项目名称:arwiki_parser,代码行数:11,代码来源:arwiki_parser.py


示例17: parse

	def parse(self, title, text):
		out = StringIO.StringIO()
		metadata = defaultdict(list)		

		parsed = parseString(title, raw=text, wikidb = self.db)
		w = htmlwriter.HTMLWriter(out, metadata ,  self.options)
		print metadata
		w.write(parsed)
#		meta_data = [ ('key-word', ['first']), ("category", ['pierwsza', 'druga', 'trzecia']) ]
		
		return (metadata, out.getvalue())
开发者ID:konryd,项目名称:rw-projekt,代码行数:11,代码来源:parser.py


示例18: getXML

def getXML(wikitext):
    db = DummyDB()
    r = parseString(title="test", raw=wikitext, wikidb=db)
    advtree.buildAdvancedTree(r)
    preprocess(r)
    mwlib.parser.show(sys.stdout, r)
    odfw = ODFWriter()
    odfw.writeTest(r)
    validate(odfw)
    xml = odfw.asstring()
    # print xml # usefull to inspect generateded xml
    return xml
开发者ID:pediapress,项目名称:mwlib,代码行数:12,代码来源:test_odfwriter.py


示例19: convert_pagecontent

def convert_pagecontent(title, content):
    """
    Convert a string in Mediawiki content format to a string in
    Dokuwiki content format.
    """
    # wrap the "magic" marker tag <__mw_nowiki> around <nowiki>, as
    # as mwlib just discards it otherwise and we can't detect it within the parser.
    # We keep the inner <nowiki> so the mwlib parser still skips that content
    content = re.sub(r"<nowiki>.+</nowiki>", lambda e: "<__mw_nowiki>"+e.group(0)+"</__mw_nowiki>", content)

    root = uparser.parseString(title, content) # create parse tree
    return convert(root, False)
开发者ID:krichter722,项目名称:yamdwe,代码行数:12,代码来源:wikicontent.py


示例20: parse

def parse():
    parser = optparse.OptionParser(usage="%prog [-a|--all] --config CONFIG [ARTICLE1 ...]")
    parser.add_option("-a", "--all", action="store_true", help="parse all articles")
    parser.add_option("--tb", action="store_true", help="show traceback on error")

    parser.add_option("-c", "--config", help="configuration file/URL/shortcut")

    options, args = parser.parse_args()
                                   
    if not args and not options.all:
        parser.error("missing option.")
        
    if not options.config:
        parser.error("missing --config argument")

    articles = [unicode(x, 'utf-8') for x in args]

    conf = options.config
    
    import traceback
    from mwlib import wiki, uparser
    
    w = wiki.makewiki(conf)
    
    db = w.wiki

    if options.all:
        if not hasattr(db, "articles"):
            raise RuntimeError("%s does not support iterating over all articles" % (db, ))
        articles = db.articles()


    import time
    for x in articles:
        try:
            page = db.normalize_and_get_page(x, 0)
            if page:
                raw = page.rawtext
            else:
                raw = None
                
            # yes, raw can be None, when we have a redirect to a non-existing article.
            if raw is None: 
                continue
            stime=time.time()
            a=uparser.parseString(x, raw=raw, wikidb=db)
        except Exception, err:
            print "F", repr(x), err
            if options.tb:
                traceback.print_exc()
        else:
            print "G", time.time()-stime, repr(x)
开发者ID:UltraNurd,项目名称:mwlib,代码行数:52,代码来源:__init__.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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