Encapsulate an XML parse error or warning. This exception will include information for locating the error in the original XML document. Note that although the application will receive a SAXParseException as the argument to the handlers in the ErrorHandler interface, the application
| 40 | # ===== SAXPARSEEXCEPTION ===== |
| 41 | |
| 42 | class SAXParseException(SAXException): |
| 43 | """Encapsulate an XML parse error or warning. |
| 44 | |
| 45 | This exception will include information for locating the error in |
| 46 | the original XML document. Note that although the application will |
| 47 | receive a SAXParseException as the argument to the handlers in the |
| 48 | ErrorHandler interface, the application is not actually required |
| 49 | to raise the exception; instead, it can simply read the |
| 50 | information in it and take a different action. |
| 51 | |
| 52 | Since this exception is a subclass of SAXException, it inherits |
| 53 | the ability to wrap another exception.""" |
| 54 | |
| 55 | def __init__(self, msg, exception, locator): |
| 56 | "Creates the exception. The exception parameter is allowed to be None." |
| 57 | SAXException.__init__(self, msg, exception) |
| 58 | self._locator = locator |
| 59 | |
| 60 | # We need to cache this stuff at construction time. |
| 61 | # If this exception is raised, the objects through which we must |
| 62 | # traverse to get this information may be deleted by the time |
| 63 | # it gets caught. |
| 64 | self._systemId = self._locator.getSystemId() |
| 65 | self._colnum = self._locator.getColumnNumber() |
| 66 | self._linenum = self._locator.getLineNumber() |
| 67 | |
| 68 | def getColumnNumber(self): |
| 69 | """The column number of the end of the text where the exception |
| 70 | occurred.""" |
| 71 | return self._colnum |
| 72 | |
| 73 | def getLineNumber(self): |
| 74 | "The line number of the end of the text where the exception occurred." |
| 75 | return self._linenum |
| 76 | |
| 77 | def getPublicId(self): |
| 78 | "Get the public identifier of the entity where the exception occurred." |
| 79 | return self._locator.getPublicId() |
| 80 | |
| 81 | def getSystemId(self): |
| 82 | "Get the system identifier of the entity where the exception occurred." |
| 83 | return self._systemId |
| 84 | |
| 85 | def __str__(self): |
| 86 | "Create a string representation of the exception." |
| 87 | sysid = self.getSystemId() |
| 88 | if sysid is None: |
| 89 | sysid = "<unknown>" |
| 90 | linenum = self.getLineNumber() |
| 91 | if linenum is None: |
| 92 | linenum = "?" |
| 93 | colnum = self.getColumnNumber() |
| 94 | if colnum is None: |
| 95 | colnum = "?" |
| 96 | return "%s:%s:%s: %s" % (sysid, linenum, colnum, self._msg) |
| 97 | |
| 98 | |
| 99 | # ===== SAXNOTRECOGNIZEDEXCEPTION ===== |
no outgoing calls
searching dependent graphs…