Exemplo n.º 1
0
 def parse(self, source):
     "Parse an XML document from a URL or an InputSource."
     self._source = saxutils.prepare_input_source(source)
     try:
         self._parser.parse(source)
     except SAXException, e:
         raise _exceptions.SAXException("", e)
Exemplo n.º 2
0
    def parse(self, source):
        source = prepare_input_source(source)

        self.prepareParser(source)
        file = source.getByteStream()
        buffer = file.read(self._bufsize)
        while buffer != "":
            self.feed(buffer)
            buffer = file.read(self._bufsize)
        self.close()
Exemplo n.º 3
0
    def parse(self, source):
        source = prepare_input_source(source)

        self.prepareParser(source)
        file = source.getByteStream()
        buffer = file.read(self._bufsize)
        while buffer != "":
            self.feed(buffer)
            buffer = file.read(self._bufsize)
        self.close()
Exemplo n.º 4
0
 def fromStream(self, stream, ownerDoc=None):
     self.handler.initState(ownerDoc=ownerDoc)
     #self.parser.parseFile(stream)
     s = saxutils.prepare_input_source(stream)
     self.parser.parse(s)
     rt = self.handler.getRootNode()
     #if hasattr(self.parser.parser,'deref'):
     #    self.parser.parser.deref()
     #self.parser.parser = None
     #self.parser = None
     #self.handler = None
     return rt
Exemplo n.º 5
0
 def fromStream(self, stream, ownerDoc=None):
     self.handler.initState(ownerDoc=ownerDoc)
     #self.parser.parseFile(stream)
     s = saxutils.prepare_input_source(stream)
     self.parser.parse(s)
     rt = self.handler.getRootNode()
     #if hasattr(self.parser.parser,'deref'):
     #    self.parser.parser.deref()
     #self.parser.parser = None
     #self.parser = None
     #self.handler = None
     return rt
Exemplo n.º 6
0
    def parse(self, source):
        "Parse an XML document from a URL or an InputSource."
        source = saxutils.prepare_input_source(source)

        self._source = source
        self.reset()
        self._cont_handler.setDocumentLocator(ExpatLocator(self))
        try:
            xmlreader.IncrementalParser.parse(self, source)
        finally:
            # Drop reference to Expat parser, but read potential
            # error state before that. Also, if close has completed,
            # we don't have a parser anymore, anyway.
            if self._parser:
                self._ColumnNumber = self._parser.ErrorColumnNumber
                self._LineNumber = self._parser.ErrorLineNumber
                self._parser = None
Exemplo n.º 7
0
    def external_entity_ref(self, context, base, sysid, pubid):
        if not self._external_ges:
            return 1

        source = self._ent_handler.resolveEntity(pubid, sysid)
        source = saxutils.prepare_input_source(source,
                                               self._source.getSystemId() or
                                               "")

        self._entity_stack.append((self._parser, self._source))
        self._parser = self._parser.ExternalEntityParserCreate(context)
        self._source = source

        try:
            xmlreader.IncrementalParser.parse(self, source)
        except:
            return 0  # FIXME: save error info here?

        (self._parser, self._source) = self._entity_stack[-1]
        del self._entity_stack[-1]
        return 1