+++ /dev/null
-"""Different kinds of SAX Exceptions"""\r
-import sys\r
-if sys.platform[:4] == "java":\r
- from java.lang import Exception\r
-del sys\r
-\r
-# ===== SAXEXCEPTION =====\r
-\r
-class SAXException(Exception):\r
- """Encapsulate an XML error or warning. This class can contain\r
- basic error or warning information from either the XML parser or\r
- the application: you can subclass it to provide additional\r
- functionality, or to add localization. Note that although you will\r
- receive a SAXException as the argument to the handlers in the\r
- ErrorHandler interface, you are not actually required to throw\r
- the exception; instead, you can simply read the information in\r
- it."""\r
-\r
- def __init__(self, msg, exception=None):\r
- """Creates an exception. The message is required, but the exception\r
- is optional."""\r
- self._msg = msg\r
- self._exception = exception\r
- Exception.__init__(self, msg)\r
-\r
- def getMessage(self):\r
- "Return a message for this exception."\r
- return self._msg\r
-\r
- def getException(self):\r
- "Return the embedded exception, or None if there was none."\r
- return self._exception\r
-\r
- def __str__(self):\r
- "Create a string representation of the exception."\r
- return self._msg\r
-\r
- def __getitem__(self, ix):\r
- """Avoids weird error messages if someone does exception[ix] by\r
- mistake, since Exception has __getitem__ defined."""\r
- raise AttributeError("__getitem__")\r
-\r
-\r
-# ===== SAXPARSEEXCEPTION =====\r
-\r
-class SAXParseException(SAXException):\r
- """Encapsulate an XML parse error or warning.\r
-\r
- This exception will include information for locating the error in\r
- the original XML document. Note that although the application will\r
- receive a SAXParseException as the argument to the handlers in the\r
- ErrorHandler interface, the application is not actually required\r
- to throw the exception; instead, it can simply read the\r
- information in it and take a different action.\r
-\r
- Since this exception is a subclass of SAXException, it inherits\r
- the ability to wrap another exception."""\r
-\r
- def __init__(self, msg, exception, locator):\r
- "Creates the exception. The exception parameter is allowed to be None."\r
- SAXException.__init__(self, msg, exception)\r
- self._locator = locator\r
-\r
- # We need to cache this stuff at construction time.\r
- # If this exception is thrown, the objects through which we must\r
- # traverse to get this information may be deleted by the time\r
- # it gets caught.\r
- self._systemId = self._locator.getSystemId()\r
- self._colnum = self._locator.getColumnNumber()\r
- self._linenum = self._locator.getLineNumber()\r
-\r
- def getColumnNumber(self):\r
- """The column number of the end of the text where the exception\r
- occurred."""\r
- return self._colnum\r
-\r
- def getLineNumber(self):\r
- "The line number of the end of the text where the exception occurred."\r
- return self._linenum\r
-\r
- def getPublicId(self):\r
- "Get the public identifier of the entity where the exception occurred."\r
- return self._locator.getPublicId()\r
-\r
- def getSystemId(self):\r
- "Get the system identifier of the entity where the exception occurred."\r
- return self._systemId\r
-\r
- def __str__(self):\r
- "Create a string representation of the exception."\r
- sysid = self.getSystemId()\r
- if sysid is None:\r
- sysid = "<unknown>"\r
- linenum = self.getLineNumber()\r
- if linenum is None:\r
- linenum = "?"\r
- colnum = self.getColumnNumber()\r
- if colnum is None:\r
- colnum = "?"\r
- return "%s:%s:%s: %s" % (sysid, linenum, colnum, self._msg)\r
-\r
-\r
-# ===== SAXNOTRECOGNIZEDEXCEPTION =====\r
-\r
-class SAXNotRecognizedException(SAXException):\r
- """Exception class for an unrecognized identifier.\r
-\r
- An XMLReader will raise this exception when it is confronted with an\r
- unrecognized feature or property. SAX applications and extensions may\r
- use this class for similar purposes."""\r
-\r
-\r
-# ===== SAXNOTSUPPORTEDEXCEPTION =====\r
-\r
-class SAXNotSupportedException(SAXException):\r
- """Exception class for an unsupported operation.\r
-\r
- An XMLReader will raise this exception when a service it cannot\r
- perform is requested (specifically setting a state or value). SAX\r
- applications and extensions may use this class for similar\r
- purposes."""\r
-\r
-# ===== SAXNOTSUPPORTEDEXCEPTION =====\r
-\r
-class SAXReaderNotAvailable(SAXNotSupportedException):\r
- """Exception class for a missing driver.\r
-\r
- An XMLReader module (driver) should raise this exception when it\r
- is first imported, e.g. when a support module cannot be imported.\r
- It also may be raised during parsing, e.g. if executing an external\r
- program is not permitted."""\r