本文整理汇总了Python中twisted.web.microdom.parse函数的典型用法代码示例。如果您正苦于以下问题:Python parse函数的具体用法?Python parse怎么用?Python parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_munge
def test_munge(self):
indexer.setIndexFilename("lore_index_file.html")
doc = microdom.parse(open(self.file))
templ = microdom.parse(open(d['template']))
node = templ.cloneNode(1)
tree.munge(doc, node, self.linkrel,
os.path.dirname(self.file),
self.file,
d['ext'], d['baseurl'], d)
self.assertEqualsFile('good_internal.xhtml', node.toprettyxml())
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:10,代码来源:test_lore.py
示例2: doFile
def doFile(infile, outfile):
dom = microdom.parse(open(infile))
dir = os.path.dirname(infile)
makeBook(dom, dir)
outfile = open(outfile, 'w')
dom.writexml(outfile)
outfile.close()
开发者ID:fxia22,项目名称:ASM_xf,代码行数:7,代码来源:book.py
示例3: get
def get(self, url):
tree = microdom.parse(self.filename, beExtremelyLenient=True)
for dl in tree.getElementsByTagName('dl'):
for a in dl.getElementsByTagName('a'):
if a.getAttribute('href') == url:
if a.parentNode.nodeName == 'dt':
return self._nodeToBookmark(a.parentNode)
开发者ID:tv42,项目名称:delicate,代码行数:7,代码来源:fromdelicious.py
示例4: __init__
def __init__(self, path, registry, *a, **kw):
self.path = path
self.registry = registry
doc = microdom.parse(self.path)
self.content = doc.getElementsByTagName('body')[0].childNodes
# we will get title out of the original's <head> so we can replace it
# with a default when necessary.
_title = doc.getElementsByTagName('title')
if len(_title) >= 1:
title = _title[0]
self.titleNodes = title.childNodes
else:
self.titleNodes = None
title = None
# then, everything else in original's head
_head = doc.getElementsByTagName('head')
if len(_head) >= 1:
head = _head[0]
self.originalHead = [n for n in head.childNodes if n is not title]
else:
self.originalHead = []
rend.Page.__init__(self, *a, **kw)
开发者ID:corydodt,项目名称:Personal,代码行数:25,代码来源:web.py
示例5: unjellyFromXML
def unjellyFromXML(stringOrFile):
"""I convert a string or the contents of an XML file into a Python object.
"""
if hasattr(stringOrFile, "read"):
document = parse(stringOrFile)
else:
document = parseString(stringOrFile)
return unjellyFromDOM(document)
开发者ID:adozenlines,项目名称:freevo1,代码行数:8,代码来源:marmalade.py
示例6: test_setIndexLink
def test_setIndexLink(self):
"""
Tests to make sure that index links are processed when an index page
exists and removed when there is not.
"""
templ = microdom.parse(open(d['template']))
indexFilename = 'theIndexFile'
numLinks = len(domhelpers.findElementsWithAttribute(templ,
"class",
"index-link"))
# if our testing template has no index-link nodes, complain about it
self.assertNotEquals(
[],
domhelpers.findElementsWithAttribute(templ,
"class",
"index-link"))
tree.setIndexLink(templ, indexFilename)
self.assertEquals(
[],
domhelpers.findElementsWithAttribute(templ,
"class",
"index-link"))
indexLinks = domhelpers.findElementsWithAttribute(templ,
"href",
indexFilename)
self.assertTrue(len(indexLinks) >= numLinks)
templ = microdom.parse(open(d['template']))
self.assertNotEquals(
[],
domhelpers.findElementsWithAttribute(templ,
"class",
"index-link"))
indexFilename = None
tree.setIndexLink(templ, indexFilename)
self.assertEquals(
[],
domhelpers.findElementsWithAttribute(templ,
"class",
"index-link"))
开发者ID:axray,项目名称:dataware.dreamplug,代码行数:46,代码来源:test_lore.py
示例7: generate_html
def generate_html(self, d):
n = htmlDefault.copy()
n.update(d)
d = n
try:
fp = open(d['template'])
templ = microdom.parse(fp)
except IOError, e:
raise process.NoProcessorError(e.filename+": "+e.strerror)
开发者ID:fxia22,项目名称:ASM_xf,代码行数:9,代码来源:default.py
示例8: generate_html
def generate_html(self, options, filenameGenerator=tree.getOutputFileName):
n = default.htmlDefault.copy()
n.update(options)
options = n
try:
fp = open(options['template'])
templ = microdom.parse(fp)
except IOError, e:
raise process.NoProcessorError(e.filename+": "+e.strerror)
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:9,代码来源:nevowlore.py
示例9: lowerDocument
def lowerDocument(href, d, nodeLevel):
newNode = microdom.parse(open(os.path.join(d, href)))
newNode = domhelpers.findNodesNamed(newNode, 'body')[0]
headers = domhelpers.findElements(newNode,
lambda x: len(x.tagName)==2 and x.tagName[0]=='h' and
x.tagName[1] in '123456')
for header in headers:
header.tagName = 'h'+str(int(header.tagName[1])+nodeLevel)
return newNode
开发者ID:fxia22,项目名称:ASM_xf,代码行数:9,代码来源:book.py
示例10: parseFileAndReport
def parseFileAndReport(filename):
try:
return microdom.parse(open(filename))
except microdom.MismatchedTags, e:
raise process.ProcessingFailure(
"%s:%s: begin mismatched tags <%s>/</%s>" %
(e.begLine, e.begCol, e.got, e.expect),
"%s:%s: end mismatched tags <%s>/</%s>" %
(e.endLine, e.endCol, e.got, e.expect))
开发者ID:galaxysd,项目名称:BitTorrent,代码行数:9,代码来源:tree.py
示例11: test_indexAnchorsAdded
def test_indexAnchorsAdded(self):
indexer.setIndexFilename('theIndexFile.html')
# generate the output file
templ = microdom.parse(open(d['template']))
tmp = self.makeTemp('lore_index_test.xhtml')
tree.doFile(os.path.join(tmp, 'lore_index_test.xhtml'),
self.linkrel, '.html', d['baseurl'], templ, d)
self.assertEqualFiles1("lore_index_test_out.html",
os.path.join(tmp, "lore_index_test.html"))
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:10,代码来源:test_lore.py
示例12: fontifyPythonNode
def fontifyPythonNode(node):
oldio = cStringIO.StringIO()
latex.getLatexText(node, oldio.write,
entities={'lt': '<', 'gt': '>', 'amp': '&'})
oldio = cStringIO.StringIO(oldio.getvalue().strip()+'\n')
newio = cStringIO.StringIO()
htmlizer.filter(oldio, newio, writer=htmlizer.SmallerHTMLWriter)
newio.seek(0)
newel = microdom.parse(newio).documentElement
newel.setAttribute("class", "python")
node.parentNode.replaceChild(newel, node)
开发者ID:galaxysd,项目名称:BitTorrent,代码行数:11,代码来源:tree.py
示例13: load
def load(self, xmlfile, element):
"""Load from XML
@param xmlfile file name
@param element """
self.xmlfile = xmlfile
self.element = element
tree = microdom.parse(xmlfile)
nodes = tree.getElementsByTagName(element)
for node in nodes:
self.parse_element(node)
del tree
开发者ID:DavidDaniels,项目名称:UpStage2013,代码行数:11,代码来源:misc.py
示例14: _getAllBookmarks
def _getAllBookmarks(self):
# workaround for http://twistedmatrix.com/bugs/issue1358
laterClosers = {}
laterClosers.update(microdom.MicroDOMParser.laterClosers)
laterClosers['p'] = microdom.MicroDOMParser.laterClosers.get('p', []) + ['DT']
laterClosers['dt'] = microdom.MicroDOMParser.laterClosers.get('dt', []) + ['DD']
laterClosers['dd'] = microdom.MicroDOMParser.laterClosers.get('dd', []) + ['DT']
tree = microdom.parse(self.filename, beExtremelyLenient=True, laterClosers=laterClosers)
for dl in tree.getElementsByTagName('dl'):
for dt in dl.getElementsByTagName('dt'):
yield self._nodeToBookmark(dt)
开发者ID:tv42,项目名称:delicate,代码行数:12,代码来源:fromdelicious.py
示例15: __init__
def __init__(self, templateDirectory, viewFactory=None, metaTemplate=None):
"""
Create a tapestry with a specified template directory.
"""
Resource.__init__(self)
self.templateDirectory = templateDirectory
if viewFactory is not None:
self.viewFactory = viewFactory
if metaTemplate:
self.metaTemplate = microdom.parse(open(
os.path.join(templateDirectory, metaTemplate)))
else:
self.metaTemplate = None
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:13,代码来源:tapestry.py
示例16: load
def load(self, config_file=None):
""" Loads an xml configuration file, which says what avatars,
props etc are avaiable to this stage"""
config_file = config_file or self.config_file
tree = microdom.parse(config_file)
self.created = tree.documentElement.getAttribute('created') or str(datetime.now())
self.clear()
#Heath Behrens 10/08/2011 - Moved so this is done correctly, they where in the if statements but that was horrible
# and buggy
splashnodes = tree.getElementsByTagName('splash')
propBgColornodes = tree.getElementsByTagName('bgpropbgcolour')
toolsBgColorNodes = tree.getElementsByTagName('toolsbgcolour')
chatBgColorNodes = tree.getElementsByTagName('chatbgcolour')
pageBgColorNodes = tree.getElementsByTagName('pagebgcolour')
accessOneNodes = tree.getElementsByTagName('access_one')
accessTwoNodes = tree.getElementsByTagName('access_two')
accessThreeNodes = tree.getElementsByTagName('access_three')
debugScreenNodes = tree.getElementsByTagName('showDebugScreen')
try:
#Heath Behrens 10/08/2011 - changed the if statements so they now check for none and process each
# node correctly.
if splashnodes and splashnodes[0].firstChild() is not None:
self.splash_message = splashnodes[0].firstChild().toxml()
if propBgColornodes and propBgColornodes[0].firstChild() is not None:
self.backgroundPropBgColour = propBgColornodes[0].firstChild().toxml()
if chatBgColorNodes and chatBgColorNodes[0].firstChild() is not None:
self.chatBgColour = chatBgColorNodes[0].firstChild().toxml()
if toolsBgColorNodes and toolsBgColorNodes[0].firstChild() is not None:
self.toolsBgColour = toolsBgColorNodes[0].firstChild().toxml()
if pageBgColorNodes and pageBgColorNodes[0].firstChild() is not None:
self.pageBgColour = pageBgColorNodes[0].firstChild().toxml()
if accessOneNodes and accessOneNodes[0].firstChild() is not None:
#Heath Behrens 10/08/2011 - loop over the items in the node and split by comma
for x in accessOneNodes[0].firstChild().toxml().split(','):
self.access_level_one.append(x) # Heath Behrens 10/08/2011 - append the item to the list
if accessTwoNodes and accessTwoNodes[0].firstChild() is not None:
#Heath Behrens 10/08/2011 - loop over the items in the node and split by comma
for x in accessTwoNodes[0].firstChild().toxml().split(','):
self.access_level_two.append(x) # Heath Behrens 10/08/2011 - append the item to the list
if accessThreeNodes and accessThreeNodes[0].firstChild() is not None:
#Heath Behrens 10/08/2011 - loop over the items in the node and split by comma
for x in accessThreeNodes[0].firstChild().toxml().split(','):
self.access_level_three.append(x) # Heath Behrens 10/08/2011 - append the item to the list
if debugScreenNodes and debugScreenNodes[0].firstChild() is not None:
self.debugMessages = debugScreenNodes[0].firstChild().toxml()
except Exception, e:
print "Couldn't set splash message for '%s', because '%s'" % (self, e)
开发者ID:foobarlab,项目名称:UpStage-Video-Hack,代码行数:49,代码来源:stage.py
示例17: fontifyPythonNode
def fontifyPythonNode(node):
"""
Syntax color the given node containing Python source code.
@return: C{None}
"""
oldio = cStringIO.StringIO()
latex.getLatexText(node, oldio.write, entities={"lt": "<", "gt": ">", "amp": "&"})
oldio = cStringIO.StringIO(oldio.getvalue().strip() + "\n")
newio = cStringIO.StringIO()
htmlizer.filter(oldio, newio, writer=htmlizer.SmallerHTMLWriter)
newio.seek(0)
newel = microdom.parse(newio).documentElement
newel.setAttribute("class", "python")
node.parentNode.replaceChild(newel, node)
开发者ID:radical-software,项目名称:radicalspam,代码行数:15,代码来源:tree.py
示例18: parseFileAndReport
def parseFileAndReport(filename):
"""
Parse and return the contents of the given lore XHTML document.
@type filename: C{str}
@param filename: The name of a file containing a lore XHTML document to
load.
@raise process.ProcessingFailure: When the contents of the specified file
cannot be parsed.
@rtype: A DOM Document
@return: The document contained in C{filename}.
"""
try:
return microdom.parse(open(filename))
except microdom.MismatchedTags, e:
raise process.ProcessingFailure(
"%s:%s: begin mismatched tags <%s>/</%s>" % (e.begLine, e.begCol, e.got, e.expect),
"%s:%s: end mismatched tags <%s>/</%s>" % (e.endLine, e.endCol, e.got, e.expect),
)
开发者ID:radical-software,项目名称:radicalspam,代码行数:21,代码来源:tree.py
示例19: _reallyLoad
def _reallyLoad(self, path, ctx):
doc = microdom.parse(path, beExtremelyLenient=self.beExtremelyLenient)
doc = flat.precompile(doc, ctx)
if self.pattern is not None:
doc = inevow.IQ(doc).onePattern(self.pattern)
return doc
开发者ID:jonathanj,项目名称:nevow,代码行数:6,代码来源:loaders.py
示例20: parseXBEL
def parseXBEL(filename=None):
if filename is None:
filename = os.path.expanduser("~/.galeon/bookmarks.xbel")
bookmarks = file(filename)
dom = microdom.parse(bookmarks)
return dom
开发者ID:tv42,项目名称:toursst,代码行数:6,代码来源:xbel.py
注:本文中的twisted.web.microdom.parse函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论