本文整理汇总了Python中twisted.web.domhelpers.getNodeText函数的典型用法代码示例。如果您正苦于以下问题:Python getNodeText函数的具体用法?Python getNodeText怎么用?Python getNodeText使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getNodeText函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: formulaeToImages
def formulaeToImages(document, dir):
# gather all macros
macros = ''
for node in domhelpers.findElementsWithAttribute(document, 'class',
'latexmacros'):
macros += domhelpers.getNodeText(node)
node.parentNode.removeChild(node)
i = 0
for node in domhelpers.findElementsWithAttribute(document, 'class',
'latexformula'):
latexText='''\\documentclass[12pt]{amsart}%s
\\begin{document}\[%s\]
\\end{document}''' % (macros, domhelpers.getNodeText(node))
file = tempfile.mktemp()
open(file+'.tex', 'w').write(latexText)
os.system('latex %s.tex' % file)
os.system('dvips %s.dvi -o %s.ps' % (os.path.basename(file), file))
baseimgname = 'latexformula%d.png' % i
imgname = os.path.join(dir, baseimgname)
i += 1
os.system('pstoimg -type png -crop a -trans -interlace -out '
'%s %s.ps' % (imgname, file))
newNode = microdom.parseString('<span><br /><img src="%s" /><br /></span>' %
baseimgname)
node.parentNode.replaceChild(newNode, node)
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:25,代码来源:lmath.py
示例2: formulaeToImages
def formulaeToImages(document, dir, _system=os.system):
# gather all macros
macros = ''
for node in domhelpers.findElementsWithAttribute(document, 'class',
'latexmacros'):
macros += domhelpers.getNodeText(node)
node.parentNode.removeChild(node)
i = 0
for node in domhelpers.findElementsWithAttribute(document, 'class',
'latexformula'):
latexText='''\\documentclass[12pt]{amsart}%s
\\begin{document}\[%s\]
\\end{document}''' % (macros, domhelpers.getNodeText(node))
# This file really should be cleaned up by this function, or placed
# somewhere such that the calling code can find it and clean it up.
file = tempfile.mktemp()
f = open(file+'.tex', 'w')
f.write(latexText)
f.close()
_system('latex %s.tex' % file)
_system('dvips %s.dvi -o %s.ps' % (os.path.basename(file), file))
baseimgname = 'latexformula%d.png' % i
imgname = os.path.join(dir, baseimgname)
i += 1
_system('pstoimg -type png -crop a -trans -interlace -out '
'%s %s.ps' % (imgname, file))
newNode = dom.parseString(
'<span><br /><img src="%s" /><br /></span>' % (
baseimgname,)).documentElement
node.parentNode.replaceChild(newNode, node)
开发者ID:0004c,项目名称:VTK,代码行数:30,代码来源:lmath.py
示例3: getTitleLink
def getTitleLink(url):
d = client.getPage("http://moshez.org/discuss/rss")
d.addCallback(microdom.parseString)
d.addCallback(lambda d: domhelpers.findNodesNamed(d, 'item')[0])
d.addCallback(lambda d: (
domhelpers.getNodeText(domhelpers.findNodesNamed(d, 'link')[0]),
domhelpers.getNodeText(domhelpers.findNodesNamed(d, 'title')[0]),
))
return d
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:9,代码来源:wovenrss.rpy.py
示例4: check_title
def check_title(self, dom, filename):
doc = dom.documentElement
title = domhelpers.findNodesNamed(dom, 'title')
if len(title)!=1:
return self._reportError(filename, doc, 'not exactly one title')
h1 = domhelpers.findNodesNamed(dom, 'h1')
if len(h1)!=1:
return self._reportError(filename, doc, 'not exactly one h1')
if domhelpers.getNodeText(h1[0]) != domhelpers.getNodeText(title[0]):
self._reportError(filename, h1[0], 'title and h1 text differ')
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:10,代码来源:lint.py
示例5: test_getNodeUnicodeText
def test_getNodeUnicodeText(self):
"""
L{domhelpers.getNodeText} returns a C{unicode} string when text
nodes are represented in the DOM with unicode, whether or not there
are non-ASCII characters present.
"""
node = self.dom.parseString("<foo>bar</foo>")
text = domhelpers.getNodeText(node)
self.assertEqual(text, u"bar")
self.assertIsInstance(text, unicode)
node = self.dom.parseString(u"<foo>\N{SNOWMAN}</foo>".encode('utf-8'))
text = domhelpers.getNodeText(node)
self.assertEqual(text, u"\N{SNOWMAN}")
self.assertIsInstance(text, unicode)
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:15,代码来源:test_domhelpers.py
示例6: visitNode_a_href
def visitNode_a_href(self, node):
supported_schemes=['http', 'https', 'ftp', 'mailto']
href = node.getAttribute('href')
if urlparse.urlparse(href)[0] in supported_schemes:
text = domhelpers.getNodeText(node)
self.visitNodeDefault(node)
if text != href:
self.writer('\\footnote{%s}' % latexEscape(href))
else:
path, fragid = (href.split('#', 1) + [None])[:2]
if path == '':
path = self.filename
else:
path = os.path.join(os.path.dirname(self.filename), path)
#if path == '':
#path = os.path.basename(self.filename)
#else:
# # Hack for linking to man pages from howtos, i.e.
# # ../doc/foo-man.html -> foo-man.html
# path = os.path.basename(path)
path = realpath(path)
if fragid:
ref = path + 'HASH' + fragid
else:
ref = path
self.writer('\\textit{')
self.visitNodeDefault(node)
self.writer('}')
self.writer('\\loreref{%s}' % ref)
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:31,代码来源:latex.py
示例7: getDescription
def getDescription(self):
# http://purl.org/dc/elements/1.1/ description
l = domhelpers.findNodesNamed(self.dom, 'description')
if l:
return domhelpers.getNodeText(l[0])
else:
return None
开发者ID:raamdev,项目名称:toursst,代码行数:7,代码来源:fetch.py
示例8: generateToC
def generateToC(document):
"""
Create a table of contents for the given document.
@type document: A DOM Node or Document
@rtype: A DOM Node
@return: a Node containing a table of contents based on the headers of the
given document.
"""
toc, level, id = "\n<ol>\n", 0, 0
for element in getHeaders(document):
elementLevel = int(element.tagName[1]) - 2
toc += (level - elementLevel) * "</ul>\n"
toc += (elementLevel - level) * "<ul>"
toc += '<li><a href="#auto%d">' % id
toc += domhelpers.getNodeText(element)
toc += "</a></li>\n"
level = elementLevel
anchor = microdom.parseString('<a name="auto%d" />' % id).documentElement
element.childNodes.append(anchor)
id += 1
toc += "</ul>\n" * level
toc += "</ol>\n"
return microdom.parseString(toc).documentElement
开发者ID:radical-software,项目名称:radicalspam,代码行数:25,代码来源:tree.py
示例9: visitNode_body
def visitNode_body(self, node):
# Adapted from tree.generateToC
self.fontStack = [('standard', None)]
# Title slide
self.writer(self.start_h2)
self.writer(self.title)
self.writer(self.end_h2)
self.writer('%center\n\n\n\n\n')
for authorNode in domhelpers.findElementsWithAttribute(node, 'class', 'author'):
getLatexText(authorNode, self.writer, entities=entities)
self.writer('\n')
# Table of contents
self.writer(self.start_h2)
self.writer(self.title)
self.writer(self.end_h2)
for element in getHeaders(node):
level = int(element.tagName[1])-1
self.writer(level * '\t')
self.writer(domhelpers.getNodeText(element))
self.writer('\n')
self.visitNodeDefault(node)
开发者ID:Almad,项目名称:twisted,代码行数:26,代码来源:slides.py
示例10: test_getNodeText
def test_getNodeText(self):
"""
L{getNodeText} returns the concatenation of all the text data at or
beneath the node passed to it.
"""
node = self.dom.parseString('<foo><bar>baz</bar><bar>quux</bar></foo>')
self.assertEqual(domhelpers.getNodeText(node), "bazquux")
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:7,代码来源:test_domhelpers.py
示例11: footnotes
def footnotes(document):
"""
Find footnotes in the given document, move them to the end of the body, and
generate links to them.
A footnote is any node with a C{class} attribute set to C{footnote}.
Footnote links are generated as superscript. Footnotes are collected in a
C{ol} node at the end of the document.
@type document: A DOM Node or Document
@param document: The input document which contains all of the content to be
presented.
@return: C{None}
"""
footnotes = domhelpers.findElementsWithAttribute(document, "class", "footnote")
if not footnotes:
return
footnoteElement = microdom.Element("ol")
id = 1
for footnote in footnotes:
href = microdom.parseString('<a href="#footnote-%(id)d">' "<super>%(id)d</super></a>" % vars()).documentElement
text = " ".join(domhelpers.getNodeText(footnote).split())
href.setAttribute("title", text)
target = microdom.Element("a", attributes={"name": "footnote-%d" % id})
target.childNodes = [footnote]
footnoteContent = microdom.Element("li")
footnoteContent.childNodes = [target]
footnoteElement.childNodes.append(footnoteContent)
footnote.parentNode.replaceChild(href, footnote)
id += 1
body = domhelpers.findNodesNamed(document, "body")[0]
header = microdom.parseString("<h2>Footnotes</h2>").documentElement
body.childNodes.append(header)
body.childNodes.append(footnoteElement)
开发者ID:radical-software,项目名称:radicalspam,代码行数:35,代码来源:tree.py
示例12: _replaceWithListing
def _replaceWithListing(node, val, filename, class_):
captionTitle = domhelpers.getNodeText(node)
if captionTitle == os.path.basename(filename):
captionTitle = 'Source listing'
text = ('<div class="%s">%s<div class="caption">%s - '
'<a href="%s"><span class="filename">%s</span></a></div></div>' %
(class_, val, captionTitle, filename, filename))
newnode = microdom.parseString(text).documentElement
node.parentNode.replaceChild(newnode, node)
开发者ID:galaxysd,项目名称:BitTorrent,代码行数:9,代码来源:tree.py
示例13: render_GET
def render_GET(self, request):
url = urlTemplate % request.args['user'][0]
client.getPage(url).addCallback(
microdom.parseString).addCallback(
lambda t: domhelpers.findNodesNamed(t, 'item')).addCallback(
lambda itms: zip([domhelpers.findNodesNamed(x, 'title')[0]
for x in itms],
[domhelpers.findNodesNamed(x, 'link')[0]
for x in itms]
)).addCallback(
lambda itms: '<html><head></head><body><ul>%s</ul></body></html>' %
'\n'.join(
['<li><a href="%s">%s</a></li>' % (
domhelpers.getNodeText(link), domhelpers.getNodeText(title))
for (title, link) in itms])
).addCallback(lambda s: (request.write(s),request.finish())).addErrback(
lambda e: (request.write('Error: %s' % e),request.finish()))
return server.NOT_DONE_YET
开发者ID:Almad,项目名称:twisted,代码行数:18,代码来源:lj.rpy.py
示例14: check_texturl_matches_href
def check_texturl_matches_href(self, dom, filename):
for node in domhelpers.findNodesNamed(dom, "a"):
if not node.hasAttribute("href"):
continue
text = domhelpers.getNodeText(node)
proto = urlparse.urlparse(text)[0]
if proto and " " not in text:
if text != node.getAttribute("href"):
self._reportError(filename, node, "link text does not match href")
开发者ID:pelluch,项目名称:VTK,代码行数:9,代码来源:lint.py
示例15: findRSSFolder
def findRSSFolder(dom, folderName=None):
if folderName is None:
folderName = "RSS"
if folderName == "":
return dom
for folder in domhelpers.findNodesNamed(dom, "folder"):
for title in domhelpers.findNodesNamed(folder, "title"):
text = domhelpers.getNodeText(title)
if text == folderName:
return folder
return None
开发者ID:tv42,项目名称:toursst,代码行数:11,代码来源:xbel.py
示例16: extractRSSFeeds
def extractRSSFeeds(dom):
for bookmark in domhelpers.findNodesNamed(dom, "bookmark"):
titleNodes = domhelpers.findNodesNamed(bookmark, "title")
if titleNodes:
title = domhelpers.getNodeText(titleNodes[0])
else:
title = None
url = bookmark.getAttribute("href")
url = urllib.unquote(url)
yield title, url
开发者ID:tv42,项目名称:toursst,代码行数:11,代码来源:xbel.py
示例17: addItem
def addItem(headerElement, parent):
anchor = dom.Element('a')
name = 'auto%d' % (auto(),)
anchor.setAttribute('href', '#' + name)
text = dom.Text()
text.data = domhelpers.getNodeText(headerElement)
anchor.appendChild(text)
headerNameItem = dom.Element('li')
headerNameItem.appendChild(anchor)
parent.appendChild(headerNameItem)
anchor = dom.Element('a')
anchor.setAttribute('name', name)
headerElement.appendChild(anchor)
开发者ID:AlexanderHerlan,项目名称:syncpy,代码行数:13,代码来源:tree.py
示例18: render_GET
def render_GET(self, request):
"""
Get an xml feed from LiveJournal and construct a new HTML page using the
'title' and 'link' parsed from the xml document.
"""
url = urlTemplate % request.args['user'][0]
client.getPage(url, timeout=30).addCallback(
microdom.parseString).addCallback(
lambda t: domhelpers.findNodesNamed(t, 'item')).addCallback(
lambda itms: zip([domhelpers.findNodesNamed(x, 'title')[0]
for x in itms],
[domhelpers.findNodesNamed(x, 'link')[0]
for x in itms]
)).addCallback(
lambda itms: '<html><head></head><body><ul>%s</ul></body></html>' %
'\n'.join(
['<li><a href="%s">%s</a></li>' % (
domhelpers.getNodeText(link), domhelpers.getNodeText(title))
for (title, link) in itms])
).addCallback(lambda s: (request.write(s),request.finish())).addErrback(
lambda e: (request.write('Error: %s' % e),request.finish()))
return server.NOT_DONE_YET
开发者ID:BillAndersan,项目名称:twisted,代码行数:22,代码来源:lj.rpy.py
示例19: visitNode_title
def visitNode_title(self, node):
self.writer('@node ')
self.visitNodeDefault(node)
self.writer('\n')
self.writer('@section ')
self.visitNodeDefault(node)
self.writer('\n')
headers = tree.getHeaders(domhelpers.getParents(node)[-1])
if not headers:
return
self.writer('@menu\n')
for header in headers:
self.writer('* %s::\n' % domhelpers.getNodeText(header))
self.writer('@end menu\n')
开发者ID:Almad,项目名称:twisted,代码行数:14,代码来源:texi.py
示例20: splitIntoSlides
def splitIntoSlides(document):
body = domhelpers.findNodesNamed(document, 'body')[0]
slides = []
slide = []
title = '(unset)'
for child in body.childNodes:
if isinstance(child, dom.Element) and child.tagName == 'h2':
if slide:
slides.append((title, slide))
slide = []
title = domhelpers.getNodeText(child)
else:
slide.append(child)
slides.append((title, slide))
return slides
开发者ID:Almad,项目名称:twisted,代码行数:15,代码来源:slides.py
注:本文中的twisted.web.domhelpers.getNodeText函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论