summaryrefslogtreecommitdiffstats
path: root/Lib/xml
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2000-10-06 17:41:52 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2000-10-06 17:41:52 (GMT)
commit962c9e7f9188c75a3889fcc7fd29fb1626e278d0 (patch)
tree3656fb89cdb496f4015152b35951276f432df3c7 /Lib/xml
parent75698a4937130b0ca8019c553a4be7f02eb5ab0a (diff)
downloadcpython-962c9e7f9188c75a3889fcc7fd29fb1626e278d0.zip
cpython-962c9e7f9188c75a3889fcc7fd29fb1626e278d0.tar.gz
cpython-962c9e7f9188c75a3889fcc7fd29fb1626e278d0.tar.bz2
Add SAXReaderNotAvailable, and use it to distinguish between an
ImportError, and a missing driver.
Diffstat (limited to 'Lib/xml')
-rw-r--r--Lib/xml/sax/__init__.py13
-rw-r--r--Lib/xml/sax/_exceptions.py10
-rw-r--r--Lib/xml/sax/expatreader.py5
3 files changed, 25 insertions, 3 deletions
diff --git a/Lib/xml/sax/__init__.py b/Lib/xml/sax/__init__.py
index 1f1f58e..447420e 100644
--- a/Lib/xml/sax/__init__.py
+++ b/Lib/xml/sax/__init__.py
@@ -22,7 +22,8 @@ expatreader -- Driver that allows use of the Expat parser with SAX.
from xmlreader import InputSource
from handler import ContentHandler, ErrorHandler
from _exceptions import SAXException, SAXNotRecognizedException, \
- SAXParseException, SAXNotSupportedException
+ SAXParseException, SAXNotSupportedException, \
+ SAXReaderNotAvailable
def parse(source, handler, errorHandler=ErrorHandler()):
@@ -74,9 +75,17 @@ def make_parser(parser_list = []):
try:
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 SAXException("No parsers found", None)
+ raise SAXReaderNotAvailable("No parsers found", None)
# --- Internal utility methods used by make_parser
diff --git a/Lib/xml/sax/_exceptions.py b/Lib/xml/sax/_exceptions.py
index c02974f..1804f3f 100644
--- a/Lib/xml/sax/_exceptions.py
+++ b/Lib/xml/sax/_exceptions.py
@@ -104,3 +104,13 @@ class SAXNotSupportedException(SAXException):
perform is requested (specifically setting a state or value). SAX
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."""
diff --git a/Lib/xml/sax/expatreader.py b/Lib/xml/sax/expatreader.py
index 2fc2b7c..eb46bcd 100644
--- a/Lib/xml/sax/expatreader.py
+++ b/Lib/xml/sax/expatreader.py
@@ -6,7 +6,10 @@ pyexpat.__version__ == '2.22'.
version = "0.20"
from xml.sax._exceptions import *
-from xml.parsers import expat
+try:
+ from xml.parsers import expat
+except ImportError:
+ raise SAXReaderNotAvailable("expat not supported",None)
from xml.sax import xmlreader, saxutils, handler
AttributesImpl = xmlreader.AttributesImpl