0001 """Different kinds of SAX Exceptions""" 0002 import sys 0003 if sys.platform[:4] == "java": 0004 from java.lang import Exception 0005 del sys 0006 0007 # ===== SAXEXCEPTION ===== 0008 0009 class SAXException(Exception): 0010 """Encapsulate an XML error or warning. This class can contain 0011 basic error or warning information from either the XML parser or 0012 the application: you can subclass it to provide additional 0013 functionality, or to add localization. Note that although you will 0014 receive a SAXException as the argument to the handlers in the 0015 ErrorHandler interface, you are not actually required to throw 0016 the exception; instead, you can simply read the information in 0017 it.""" 0018 0019 def __init__(self, msg, exception=None): 0020 """Creates an exception. The message is required, but the exception 0021 is optional.""" 0022 self._msg = msg 0023 self._exception = exception 0024 Exception.__init__(self, msg) 0025 0026 def getMessage(self): 0027 "Return a message for this exception." 0028 return self._msg 0029 0030 def getException(self): 0031 "Return the embedded exception, or None if there was none." 0032 return self._exception 0033 0034 def __str__(self): 0035 "Create a string representation of the exception." 0036 return self._msg 0037 0038 def __getitem__(self, ix): 0039 """Avoids weird error messages if someone does exception[ix] by 0040 mistake, since Exception has __getitem__ defined.""" 0041 raise AttributeError("__getitem__") 0042 0043 0044 # ===== SAXPARSEEXCEPTION ===== 0045 0046 class SAXParseException(SAXException): 0047 """Encapsulate an XML parse error or warning. 0048 0049 This exception will include information for locating the error in 0050 the original XML document. Note that although the application will 0051 receive a SAXParseException as the argument to the handlers in the 0052 ErrorHandler interface, the application is not actually required 0053 to throw the exception; instead, it can simply read the 0054 information in it and take a different action. 0055 0056 Since this exception is a subclass of SAXException, it inherits 0057 the ability to wrap another exception.""" 0058 0059 def __init__(self, msg, exception, locator): 0060 "Creates the exception. The exception parameter is allowed to be None." 0061 SAXException.__init__(self, msg, exception) 0062 self._locator = locator 0063 0064 # We need to cache this stuff at construction time. 0065 # If this exception is thrown, the objects through which we must 0066 # traverse to get this information may be deleted by the time 0067 # it gets caught. 0068 self._systemId = self._locator.getSystemId() 0069 self._colnum = self._locator.getColumnNumber() 0070 self._linenum = self._locator.getLineNumber() 0071 0072 def getColumnNumber(self): 0073 """The column number of the end of the text where the exception 0074 occurred.""" 0075 return self._colnum 0076 0077 def getLineNumber(self): 0078 "The line number of the end of the text where the exception occurred." 0079 return self._linenum 0080 0081 def getPublicId(self): 0082 "Get the public identifier of the entity where the exception occurred." 0083 return self._locator.getPublicId() 0084 0085 def getSystemId(self): 0086 "Get the system identifier of the entity where the exception occurred." 0087 return self._systemId 0088 0089 def __str__(self): 0090 "Create a string representation of the exception." 0091 sysid = self.getSystemId() 0092 if sysid is None: 0093 sysid = "<unknown>" 0094 linenum = self.getLineNumber() 0095 if linenum is None: 0096 linenum = "?" 0097 colnum = self.getColumnNumber() 0098 if colnum is None: 0099 colnum = "?" 0100 return "%s:%s:%s: %s" % (sysid, linenum, colnum, self._msg) 0101 0102 0103 # ===== SAXNOTRECOGNIZEDEXCEPTION ===== 0104 0105 class SAXNotRecognizedException(SAXException): 0106 """Exception class for an unrecognized identifier. 0107 0108 An XMLReader will raise this exception when it is confronted with an 0109 unrecognized feature or property. SAX applications and extensions may 0110 use this class for similar purposes.""" 0111 0112 0113 # ===== SAXNOTSUPPORTEDEXCEPTION ===== 0114 0115 class SAXNotSupportedException(SAXException): 0116 """Exception class for an unsupported operation. 0117 0118 An XMLReader will raise this exception when a service it cannot 0119 perform is requested (specifically setting a state or value). SAX 0120 applications and extensions may use this class for similar 0121 purposes.""" 0122 0123 # ===== SAXNOTSUPPORTEDEXCEPTION ===== 0124 0125 class SAXReaderNotAvailable(SAXNotSupportedException): 0126 """Exception class for a missing driver. 0127 0128 An XMLReader module (driver) should raise this exception when it 0129 is first imported, e.g. when a support module cannot be imported. 0130 It also may be raised during parsing, e.g. if executing an external 0131 program is not permitted.""" 0132
Generated by PyXR 0.9.4