本文整理汇总了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
示例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
示例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)
示例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
示例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
示例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()
示例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()
示例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"
示例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
示例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
示例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()
示例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
示例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
示例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)
示例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()