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


Python handler.ErrorHandler方法代码示例

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


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

示例1: load

# 需要导入模块: from xml.sax import handler [as 别名]
# 或者: from xml.sax.handler import ErrorHandler [as 别名]
def load(self, filename=None):
        self.filename = filename
        if fsutils.exists(filename):
            content_handler = XMLPrefReader(pref=self)
            error_handler = ErrorHandler()
            entity_resolver = EntityResolver()
            dtd_handler = DTDHandler()
            try:
                input_file = get_fileptr(filename)
                input_source = InputSource()
                input_source.setByteStream(input_file)
                xml_reader = xml.sax.make_parser()
                xml_reader.setContentHandler(content_handler)
                xml_reader.setErrorHandler(error_handler)
                xml_reader.setEntityResolver(entity_resolver)
                xml_reader.setDTDHandler(dtd_handler)
                xml_reader.parse(input_source)
                input_file.close()
            except Exception as e:
                LOG.error('Cannot read preferences from %s %s', filename, e) 
开发者ID:sk1project,项目名称:uniconvertor,代码行数:22,代码来源:config.py

示例2: filter_rdf

# 需要导入模块: from xml.sax import handler [as 别名]
# 或者: from xml.sax.handler import ErrorHandler [as 别名]
def filter_rdf (input, output):
    """filter_rdf(input:file, output:file)

    Parses the XML input from the input stream, filtering out all
    elements and attributes that are in the RDF namespace.
    """

    output_gen = saxutils.XMLGenerator(output)
    parser = sax.make_parser()
    filter = RDFFilter(parser)
    filter.setFeature(handler.feature_namespaces, True)
    filter.setContentHandler(output_gen)
    filter.setErrorHandler(handler.ErrorHandler())
    filter.parse(input) 
开发者ID:ActiveState,项目名称:code,代码行数:16,代码来源:recipe-149284.py

示例3: xml_parse

# 需要导入模块: from xml.sax import handler [as 别名]
# 或者: from xml.sax.handler import ErrorHandler [as 别名]
def xml_parse(filename, path=()):
  source = "file://%s" % os.path.abspath(filename)
  h = parsers.XMLParser()
  p = xml.sax.make_parser()
  p.setContentHandler(h)
  p.setErrorHandler(ErrorHandler())
  p.setEntityResolver(Resolver(path))
  p.parse(source)
  return h.parser.tree 
开发者ID:apache,项目名称:qpid-python,代码行数:11,代码来源:__init__.py

示例4: manifestlist

# 需要导入模块: from xml.sax import handler [as 别名]
# 或者: from xml.sax.handler import ErrorHandler [as 别名]
def manifestlist(manifestxml):
    odhandler = ODFManifestHandler()
    parser = make_parser()
    parser.setFeature(handler.feature_namespaces, 1)
    parser.setContentHandler(odhandler)
    parser.setErrorHandler(handler.ErrorHandler())

    inpsrc = InputSource()
    if not isinstance(manifestxml, str):
        manifestxml=manifestxml.decode("utf-8")
    inpsrc.setByteStream(StringIO(manifestxml))
    parser.parse(inpsrc)

    return odhandler.manifest 
开发者ID:skylander86,项目名称:lambda-text-extractor,代码行数:16,代码来源:odfmanifest.py

示例5: init_load

# 需要导入模块: from xml.sax import handler [as 别名]
# 或者: from xml.sax.handler import ErrorHandler [as 别名]
def init_load(self):
        self.input_source = InputSource()
        self.input_source.setByteStream(self.fileptr)
        self.xml_reader = xml.sax.make_parser()
        self.xml_reader.setContentHandler(self)
        self.xml_reader.setErrorHandler(handler.ErrorHandler())
        self.xml_reader.setEntityResolver(handler.EntityResolver())
        self.xml_reader.setDTDHandler(handler.DTDHandler())
        self.xml_reader.setFeature(handler.feature_external_ges, False)
        self.do_load() 
开发者ID:sk1project,项目名称:uniconvertor,代码行数:12,代码来源:generic_filters.py

示例6: _build_model

# 需要导入模块: from xml.sax import handler [as 别名]
# 或者: from xml.sax.handler import ErrorHandler [as 别名]
def _build_model(self):
        content_handler = XMLDocReader(self.presenter)
        error_handler = ErrorHandler()
        entity_resolver = EntityResolver()
        dtd_handler = DTDHandler()
        try:
            filename = os.path.join(self.presenter.doc_dir, 'content.xml')
            handler = open(filename, 'r')
            lines = float(sum(1 for l in handler))
            handler.close()
            self.file_handler = open(filename, "r")
            input_source = InputSource()
            input_source.setByteStream(self.file_handler)
            content_handler.lines = lines
            xml_reader = xml.sax.make_parser()
            xml_reader.setContentHandler(content_handler)
            xml_reader.setErrorHandler(error_handler)
            xml_reader.setEntityResolver(entity_resolver)
            xml_reader.setDTDHandler(dtd_handler)
            xml_reader.parse(input_source)
            self.file_handler.close()
            content_handler.file = None
        except:
            errtype, value, traceback = sys.exc_info()
            msg = 'It seems content.xml is corrupted' + '\n' + value
            events.emit(events.MESSAGES, msgconst.ERROR, msg)
            raise IOError(errtype, msg, traceback)
        self.model = content_handler.model

        msg = 'Content.xml is parsed successfully'
        events.emit(events.MESSAGES, msgconst.OK, msg) 
开发者ID:sk1project,项目名称:uniconvertor,代码行数:33,代码来源:pdxf_filters.py

示例7: __loadxmlparts

# 需要导入模块: from xml.sax import handler [as 别名]
# 或者: from xml.sax.handler import ErrorHandler [as 别名]
def __loadxmlparts(z, manifest, doc, objectpath):
    """
    Parses a document from its zipfile
    @param z an instance of zipfile.ZipFile
    @param manifest Manifest data structured in a dictionary
    @param doc instance of OpenDocument to feed in
    @param objectpath unicode string: path to an object
    """
    assert(isinstance(z, zipfile.ZipFile))
    assert(type(manifest)==type(dict()))
    assert(isinstance(doc, OpenDocument))
    assert(type(objectpath)==type(u""))

    from load import LoadParser
    from xml.sax import make_parser, handler

    for xmlfile in (objectpath+u'settings.xml', objectpath+u'meta.xml', objectpath+u'content.xml', objectpath+u'styles.xml'):
        if xmlfile not in manifest:
            continue
        ##########################################################
        # this one is added to debug the bad behavior with Python2
        # which raises exceptions of type SAXParseException
        from xml.sax._exceptions import SAXParseException
        ##########################################################
        try:
            xmlpart = z.read(xmlfile).decode("utf-8")
            doc._parsing = xmlfile

            parser = make_parser()
            parser.setFeature(handler.feature_namespaces, 1)
            parser.setFeature(handler.feature_external_ges, 0)
            parser.setContentHandler(LoadParser(doc))
            parser.setErrorHandler(handler.ErrorHandler())

            inpsrc = InputSource()
            #################
            # There may be a SAXParseException triggered because of
            # a missing xmlns prefix like meta, config, etc.
            # So i add such declarations when needed (GK, 2014/10/21).
            # Is there any option to prevent xmlns checks by SAX?
            xmlpart=__fixXmlPart(xmlpart)

            inpsrc.setByteStream(BytesIO(xmlpart.encode("utf-8")))
            parser.parse(inpsrc)
            del doc._parsing
        except KeyError as v: pass
        except SAXParseException:
            print (u"====== SAX FAILED TO PARSE ==========\n", xmlpart) 
开发者ID:skylander86,项目名称:lambda-text-extractor,代码行数:50,代码来源:opendocument.py


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