[Python-checkins] CVS: python/dist/src/Lib/xml/sax expatreader.py,1.14,1.15
Martin v. Löwis
python-dev@python.org
Fri, 6 Oct 2000 14:09:02 -0700
Update of /cvsroot/python/python/dist/src/Lib/xml/sax
In directory slayer.i.sourceforge.net:/tmp/cvs-serv2763
Modified Files:
expatreader.py
Log Message:
Move translation from expat.error to SAXParseException into feed, so that
callers of feed will get a SAXException.
In close, feed the last chunk first before calling endDocument, so that
the parser may report errors before the end of the document. Don't do
anything in a nested parser.
Don't call endDocument in parse; that will be called in close.
Use self._source for finding the SystemID; XML_GetBase will be cleared in
case of an error.
Index: expatreader.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/sax/expatreader.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** expatreader.py 2000/10/06 17:41:52 1.14
--- expatreader.py 2000/10/06 21:08:59 1.15
***************
*** 40,50 ****
self.reset()
self._cont_handler.setDocumentLocator(self)
! try:
! xmlreader.IncrementalParser.parse(self, source)
! except expat.error:
! error_code = self._parser.ErrorCode
! raise SAXParseException(expat.ErrorString(error_code), None, self)
!
! self._cont_handler.endDocument()
def prepareParser(self, source):
--- 40,44 ----
self.reset()
self._cont_handler.setDocumentLocator(self)
! xmlreader.IncrementalParser.parse(self, source)
def prepareParser(self, source):
***************
*** 74,78 ****
# IncrementalParser methods
! def feed(self, data):
if not self._parsing:
self._parsing = 1
--- 68,72 ----
# IncrementalParser methods
! def feed(self, data, isFinal = 0):
if not self._parsing:
self._parsing = 1
***************
*** 80,92 ****
self._cont_handler.startDocument()
! if not self._parser.Parse(data, 0):
! msg = pyexpat.ErrorString(self._parser.ErrorCode)
! raise SAXParseException(msg, None, self)
def close(self):
! if self._parsing:
! self._cont_handler.endDocument()
! self._parsing = 0
! self._parser.Parse("", 1)
def reset(self):
--- 74,94 ----
self._cont_handler.startDocument()
! try:
! # The isFinal parameter is internal to the expat reader.
! # If it is set to true, expat will check validity of the entire
! # document. When feeding chunks, they are not normally final -
! # except when invoked from close.
! self._parser.Parse(data, isFinal)
! except expat.error:
! error_code = self._parser.ErrorCode
! raise SAXParseException(expat.ErrorString(error_code), None, self)
def close(self):
! if self._entity_stack:
! # If we are completing an external entity, do nothing here
! return
! self.feed("", isFinal = 1)
! self._cont_handler.endDocument()
! self._parsing = 0
def reset(self):
***************
*** 129,133 ****
def getSystemId(self):
! return self._parser.GetBase()
# event handlers
--- 131,135 ----
def getSystemId(self):
! return self._source.getSystemId()
# event handlers
***************
*** 195,199 ****
try:
xmlreader.IncrementalParser.parse(self, source)
! self.close()
except:
return 0 # FIXME: save error info here?
--- 197,201 ----
try:
xmlreader.IncrementalParser.parse(self, source)
! self._parser.Parse("",1)
except:
return 0 # FIXME: save error info here?