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


Python microdom.parse函数代码示例

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


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


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