[Python-checkins] CVS: python/dist/src/Lib/xml/sax __init__.py,1.12,1.13 _exceptions.py,1.4,1.5 expatreader.py,1.13,1.14

Martin v. Löwis python-dev@python.org
Fri, 6 Oct 2000 10:41:55 -0700


Update of /cvsroot/python/python/dist/src/Lib/xml/sax
In directory slayer.i.sourceforge.net:/tmp/cvs-serv4893/xml/sax

Modified Files:
	__init__.py _exceptions.py expatreader.py 
Log Message:
Add SAXReaderNotAvailable, and use it to distinguish between an
ImportError, and a missing driver.


Index: __init__.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/sax/__init__.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** __init__.py	2000/09/24 21:31:06	1.12
--- __init__.py	2000/10/06 17:41:51	1.13
***************
*** 23,27 ****
  from handler import ContentHandler, ErrorHandler
  from _exceptions import SAXException, SAXNotRecognizedException, \
!                         SAXParseException, SAXNotSupportedException
  
  
--- 23,28 ----
  from handler import ContentHandler, ErrorHandler
  from _exceptions import SAXException, SAXNotRecognizedException, \
!                         SAXParseException, SAXNotSupportedException, \
!                         SAXReaderNotAvailable
  
  
***************
*** 75,81 ****
              return _create_parser(parser_name)
          except ImportError,e:
              pass
  
!     raise SAXException("No parsers found", None)  
      
  # --- Internal utility methods used by make_parser
--- 76,90 ----
              return _create_parser(parser_name)
          except ImportError,e:
+             import sys
+             if sys.modules.has_key(parser_name):
+                 # The parser module was found, but importing it
+                 # failed unexpectedly, pass this exception through
+                 raise
+         except SAXReaderNotAvailable:
+             # The parser module detected that it won't work properly,
+             # so try the next one
              pass
  
!     raise SAXReaderNotAvailable("No parsers found", None)  
      
  # --- Internal utility methods used by make_parser

Index: _exceptions.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/sax/_exceptions.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** _exceptions.py	2000/09/21 16:32:28	1.4
--- _exceptions.py	2000/10/06 17:41:52	1.5
***************
*** 105,106 ****
--- 105,116 ----
      applications and extensions may use this class for similar
      purposes."""
+ 
+ # ===== SAXNOTSUPPORTEDEXCEPTION =====
+ 
+ class SAXReaderNotAvailable(SAXNotSupportedException):
+     """Exception class for a missing driver.
+ 
+     An XMLReader module (driver) should raise this exception when it
+     is first imported, e.g. when a support module cannot be imported.
+     It also may be raised during parsing, e.g. if executing an external
+     program is not permitted."""

Index: expatreader.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/sax/expatreader.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** expatreader.py	2000/09/29 19:00:40	1.13
--- expatreader.py	2000/10/06 17:41:52	1.14
***************
*** 7,11 ****
  
  from xml.sax._exceptions import *
! from xml.parsers import expat
  from xml.sax import xmlreader, saxutils, handler
  
--- 7,14 ----
  
  from xml.sax._exceptions import *
! try:
!     from xml.parsers import expat
! except ImportError:
!     raise SAXReaderNotAvailable("expat not supported",None) 
  from xml.sax import xmlreader, saxutils, handler