1 """Different kinds of SAX Exceptions"""
3 if sys
.platform
[:4] == "java":
4 from java
.lang
import Exception
7 # ===== SAXEXCEPTION =====
9 class SAXException(Exception):
10 """Encapsulate an XML error or warning. This class can contain
11 basic error or warning information from either the XML parser or
12 the application: you can subclass it to provide additional
13 functionality, or to add localization. Note that although you will
14 receive a SAXException as the argument to the handlers in the
15 ErrorHandler interface, you are not actually required to throw
16 the exception; instead, you can simply read the information in
19 def __init__(self
, msg
, exception
=None):
20 """Creates an exception. The message is required, but the exception
23 self
._exception
= exception
24 Exception.__init
__(self
, msg
)
27 "Return a message for this exception."
30 def getException(self
):
31 "Return the embedded exception, or None if there was none."
32 return self
._exception
35 "Create a string representation of the exception."
38 def __getitem__(self
, ix
):
39 """Avoids weird error messages if someone does exception[ix] by
40 mistake, since Exception has __getitem__ defined."""
41 raise AttributeError("__getitem__")
44 # ===== SAXPARSEEXCEPTION =====
46 class SAXParseException(SAXException
):
47 """Encapsulate an XML parse error or warning.
49 This exception will include information for locating the error in
50 the original XML document. Note that although the application will
51 receive a SAXParseException as the argument to the handlers in the
52 ErrorHandler interface, the application is not actually required
53 to throw the exception; instead, it can simply read the
54 information in it and take a different action.
56 Since this exception is a subclass of SAXException, it inherits
57 the ability to wrap another exception."""
59 def __init__(self
, msg
, exception
, locator
):
60 "Creates the exception. The exception parameter is allowed to be None."
61 SAXException
.__init
__(self
, msg
, exception
)
62 self
._locator
= locator
64 # We need to cache this stuff at construction time.
65 # If this exception is thrown, the objects through which we must
66 # traverse to get this information may be deleted by the time
68 self
._systemId
= self
._locator
.getSystemId()
69 self
._colnum
= self
._locator
.getColumnNumber()
70 self
._linenum
= self
._locator
.getLineNumber()
72 def getColumnNumber(self
):
73 """The column number of the end of the text where the exception
77 def getLineNumber(self
):
78 "The line number of the end of the text where the exception occurred."
81 def getPublicId(self
):
82 "Get the public identifier of the entity where the exception occurred."
83 return self
._locator
.getPublicId()
85 def getSystemId(self
):
86 "Get the system identifier of the entity where the exception occurred."
90 "Create a string representation of the exception."
91 sysid
= self
.getSystemId()
94 linenum
= self
.getLineNumber()
97 colnum
= self
.getColumnNumber()
100 return "%s:%s:%s: %s" % (sysid
, linenum
, colnum
, self
._msg
)
103 # ===== SAXNOTRECOGNIZEDEXCEPTION =====
105 class SAXNotRecognizedException(SAXException
):
106 """Exception class for an unrecognized identifier.
108 An XMLReader will raise this exception when it is confronted with an
109 unrecognized feature or property. SAX applications and extensions may
110 use this class for similar purposes."""
113 # ===== SAXNOTSUPPORTEDEXCEPTION =====
115 class SAXNotSupportedException(SAXException
):
116 """Exception class for an unsupported operation.
118 An XMLReader will raise this exception when a service it cannot
119 perform is requested (specifically setting a state or value). SAX
120 applications and extensions may use this class for similar
123 # ===== SAXNOTSUPPORTEDEXCEPTION =====
125 class SAXReaderNotAvailable(SAXNotSupportedException
):
126 """Exception class for a missing driver.
128 An XMLReader module (driver) should raise this exception when it
129 is first imported, e.g. when a support module cannot be imported.
130 It also may be raised during parsing, e.g. if executing an external
131 program is not permitted."""