當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。