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


Python sax.InputSource类代码示例

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


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

示例1: tmx_import

    def tmx_import(self, file, REQUEST=None, RESPONSE=None):
        """ Imports a TMX level 1 file.
            We use the SAX parser. It has the benefit that it internally
            converts everything to python unicode strings.
        """
        self._v_srclang = self._default_language
        # Create a parser
        parser = make_parser()
        chandler = HandleTMXParsing(self._tmx_tu, self._tmx_header)
        # Tell the parser to use our handler
        parser.setContentHandler(chandler)
        # Don't load the DTD from the Internet
        parser.setFeature(handler.feature_external_ges, 0)
        inputsrc = InputSource()

        if type(file) is StringType:
            inputsrc.setByteStream(StringIO(file))
            parser.parse(inputsrc)
        else:
            content = file.read()
            inputsrc.setByteStream(StringIO(content))
            parser.parse(inputsrc)

        if hasattr(self, '_v_srclang'):
            del self._v_srclang

        if REQUEST is not None:
            RESPONSE.redirect('manage_localPropertiesForm')
开发者ID:eea,项目名称:ALiSS_agents,代码行数:28,代码来源:LocalContent.py

示例2: parseFile

    def parseFile(self, inputFile, stream=None):

        input = InputSource(inputFile)
        if stream is None:
            stream = file(inputFile)
        input.setByteStream(stream)
        self.parseSource(input)
开发者ID:HackLinux,项目名称:chandler,代码行数:7,代码来源:SAX.py

示例3: parse

 def parse(self, file=None, string=None):
     """
     SAX parse XML text.
     @param file: Parse a python I{file-like} object.
     @type file: I{file-like} object.
     @param string: Parse string XML.
     @type string: str
     """
     timer = metrics.Timer()
     timer.start()
     sax, handler = self.saxparser()
     if file is not None:
         sax.parse(file)
         timer.stop()
         metrics.log.debug('sax (%s) duration: %s', file, timer)
         return handler.nodes[0]
     if string is not None:
         if isinstance(string, six.text_type):
             string = string.encode("utf-8")
         source = InputSource(None)
         source.setByteStream(BytesIO(string))
         sax.parse(source)
         timer.stop()
         metrics.log.debug('%s\nsax duration: %s', string, timer)
         return handler.nodes[0]
开发者ID:chatoooo,项目名称:suds-ng,代码行数:25,代码来源:parser.py

示例4: parse

 def parse(self, file=None, string=None):
     """
     SAX parse XML text.
     @param file: Parse a python I{file-like} object.
     @type file: I{file-like} object.
     @param string: Parse string XML.
     @type string: str
     """
     timer = metrics.Timer()
     timer.start()
     sax, handler = self.saxparser()
     if file is not None:
         sax.parse(file)
         timer.stop()
         metrics.log.debug('sax (%s) duration: %s', file, timer)
         return handler.nodes[0]
     if string is not None:
         source = InputSource(None)
         try:
             source.setByteStream(StringIO(string.encode('utf8')))
         except UnicodeDecodeError:
             source.setByteStream(StringIO(string))
         sax.parse(source)
         timer.stop()
         metrics.log.debug('%s\nsax duration: %s', string, timer)
         return handler.nodes[0]
开发者ID:dvska,项目名称:suds-htj,代码行数:26,代码来源:parser.py

示例5: parse

    def parse(self, file=None, string=None):
        """
        SAX parse XML text.

        @param file: Parse a python I{file-like} object.
        @type file: I{file-like} object
        @param string: Parse string XML.
        @type string: str
        @return: Parsed XML document.
        @rtype: L{Document}

        """
        if file is None and string is None:
            return
        timer = suds.metrics.Timer()
        timer.start()
        source = file
        if file is None:
            source = InputSource(None)
            source.setByteStream(suds.BytesIO(string))
        sax, handler = self.saxparser()
        sax.parse(source)
        timer.stop()
        if file is None:
            suds.metrics.log.debug("%s\nsax duration: %s", string, timer)
        else:
            suds.metrics.log.debug("sax (%s) duration: %s", file, timer)
        return handler.nodes[0]
开发者ID:IvarsKarpics,项目名称:edna-mx,代码行数:28,代码来源:parser.py

示例6: test_ignorable

def test_ignorable():
    p = XMLValParserFactory.make_parser()
    i = InputSource("doc3.xml")
    i.setByteStream(StringIO(doc3))
    h = H()
    p.setContentHandler(h)
    p.parse(i)
    return h.passed
开发者ID:Birdbird,项目名称:StartPage,代码行数:8,代码来源:test_sax_xmlproc.py

示例7: resolveEntity

 def resolveEntity(self, publicId, systemId):
     if systemId:
         name = os.path.join(self._path, systemId)
         if os.path.isfile(name):
             source = InputSource()
             source.setByteStream(open(name, "rb"))
             return source
     # Using default resolution
     return EntityResolver.resolveEntity(self, publicId, systemId)
开发者ID:fluxer,项目名称:warmux,代码行数:9,代码来源:bodycheck.py

示例8: test_illformed

def test_illformed():
    p = XMLValParserFactory.make_parser()
    i = InputSource("doc2.xml")
    i.setByteStream(StringIO(doc2))
    try:
        p.parse(i)
    except SAXException,e:
        print "PASS:",e
        return 1
开发者ID:Birdbird,项目名称:StartPage,代码行数:9,代码来源:test_sax_xmlproc.py

示例9: parseXLIFFSTring

 def parseXLIFFSTring(self, xml_string):
     """ """
     chandler = XLIFFHandler()
     parser = make_parser()
     # Tell the parser to use our handler
     parser.setContentHandler(chandler)
     # Don't load the DTD from the Internet
     parser.setFeature(handler.feature_external_ges, 0)
     inpsrc = InputSource()
     inpsrc.setByteStream(StringIO(xml_string))
     try:
         parser.parse(inpsrc)
         return chandler
     except:
         return None
开发者ID:eea,项目名称:odfpy,代码行数:15,代码来源:xliff_parser.py

示例10: parseContent

    def parseContent(self, file):
        # Create a parser
        try:
            parser = make_parser()
            chandler = GBoxHandler()
            # Tell the parser to use our handler
            parser.setContentHandler(chandler)
            # Don't load the DTD from the Internet
            parser.setFeature(handler.feature_external_ges, 0)
            inputsrc = InputSource()

            gbox_content = utils.utRead(file)
            inputsrc.setByteStream(StringIO(gbox_content))
            parser.parse(inputsrc)
        except:
            return 'err'
        return chandler
开发者ID:eea,项目名称:ALiSS_agents,代码行数:17,代码来源:google_box_manager.py

示例11: tmx_import

    def tmx_import(self, howmuch, file, REQUEST=None, RESPONSE=None):
        """ Imports a TMX level 1 file.
            We use the SAX parser. It has the benefit that it internally
            converts everything to python unicode strings.
        """
        if howmuch == 'clear':
            # Clear the message catalogue prior to import
            self._messages = {}
            self._languages = ()

        self._v_howmuch = howmuch
        self._v_srclang = self._default_language
        self._v_num_translations = 0
        self._v_num_notes = 0
        # Create a parser
        parser = make_parser()
        chandler = HandleTMXParsing(self._tmx_tu, self._tmx_header)
        # Tell the parser to use our handler
        parser.setContentHandler(chandler)
        # Don't load the DTD from the Internet
        parser.setFeature(handler.feature_external_ges, 0)
        inputsrc = InputSource()

        if type(file) is StringType:
            inputsrc.setByteStream(StringIO(file))
        else:
            content = file.read()
            inputsrc.setByteStream(StringIO(content))
        parser.parse(inputsrc)

        num_translations = self._v_num_translations
        num_notes = self._v_num_notes
        del self._v_srclang
        del self._v_howmuch
        del self._v_num_translations
        del self._v_num_notes

        if REQUEST is not None:
            return MessageDialog(
                title = _('Messages imported'),
                message = _('Imported %d messages and %d notes')
                          % (num_translations, num_notes),
                action = 'manage_messages')
开发者ID:eaudeweb,项目名称:naaya,代码行数:43,代码来源:MessageCatalog.py

示例12: parseXLIFFFile

    def parseXLIFFFile(self, file):
        # Create a parser
        parser = make_parser()
        chandler = XLIFFHandler()
        # Tell the parser to use our handler
        parser.setContentHandler(chandler)
        # Don't load the DTD from the Internet
        parser.setFeature(handler.feature_external_ges, 0)
        inputsrc = InputSource()

        try:
            if type(file) is StringType:
                inputsrc.setByteStream(StringIO(file))
            else:
                filecontent = file.read()
                inputsrc.setByteStream(StringIO(filecontent))
            parser.parse(inputsrc)
            return chandler
        except:
            return None
开发者ID:eea,项目名称:odfpy,代码行数:20,代码来源:xliff_parser.py

示例13: parse

 def parse(self, file=None, url=None, string=None):
     timer = metrics.Timer()
     timer.start()
     sax, handler = self.saxparser()
     if file is not None:
         sax.parse(file)
         timer.stop()
         metrics.log.debug('sax (%s) duration: %s', file, timer)
         return handler.nodes[0]
     if url is not None:
         fp = self.transport.open(Request(url))
         sax.parse(fp)
         timer.stop()
         metrics.log.debug('sax (%s) duration: %s', url, timer)
         return handler.nodes[0]
     if string is not None:
         source = InputSource(None)
         source.setByteStream(StringIO(string))
         sax.parse(source)
         timer.stop()
         metrics.log.debug('%s\nsax duration: %s', string, timer)
         return handler.nodes[0]
开发者ID:tic-ull,项目名称:defensatfc-proto,代码行数:22,代码来源:parser.py

示例14: addSectionTags

def addSectionTags(content):

    from cStringIO import StringIO
    src = InputSource()
    src.setByteStream(StringIO(content))

    # Create an XML parser
    parser = make_parser() #("xml.sax.drivers2.drv_xmlproc")
    
    dh = docHandler()
    parser.setContentHandler(dh)

    er = EntityResolver()
    parser.setEntityResolver(er)

    # Allow external entities
    parser.setFeature(feature_external_ges, True)
    
    # Parse the file; your handler's methods will get called
    parser.parse(src)

    return dh.document.encode('UTF-8')
开发者ID:Rhaptos,项目名称:Products.CNXMLTransforms,代码行数:22,代码来源:html2cnxml.py

示例15: parse

    def parse(self, xml):

        input = InputSource()
        input.setByteStream(StringIO(xml))
        self.parseSource(input)
开发者ID:HackLinux,项目名称:chandler,代码行数:5,代码来源:SAX.py


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