]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.10/Lib/xml/sax/_exceptions.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / Lib / xml / sax / _exceptions.py
CommitLineData
3257aa99
DM
1"""Different kinds of SAX Exceptions"""\r
2import sys\r
3if sys.platform[:4] == "java":\r
4 from java.lang import Exception\r
5del sys\r
6\r
7# ===== SAXEXCEPTION =====\r
8\r
9class SAXException(Exception):\r
10 """Encapsulate an XML error or warning. This class can contain\r
11 basic error or warning information from either the XML parser or\r
12 the application: you can subclass it to provide additional\r
13 functionality, or to add localization. Note that although you will\r
14 receive a SAXException as the argument to the handlers in the\r
15 ErrorHandler interface, you are not actually required to raise\r
16 the exception; instead, you can simply read the information in\r
17 it."""\r
18\r
19 def __init__(self, msg, exception=None):\r
20 """Creates an exception. The message is required, but the exception\r
21 is optional."""\r
22 self._msg = msg\r
23 self._exception = exception\r
24 Exception.__init__(self, msg)\r
25\r
26 def getMessage(self):\r
27 "Return a message for this exception."\r
28 return self._msg\r
29\r
30 def getException(self):\r
31 "Return the embedded exception, or None if there was none."\r
32 return self._exception\r
33\r
34 def __str__(self):\r
35 "Create a string representation of the exception."\r
36 return self._msg\r
37\r
38 def __getitem__(self, ix):\r
39 """Avoids weird error messages if someone does exception[ix] by\r
40 mistake, since Exception has __getitem__ defined."""\r
41 raise AttributeError("__getitem__")\r
42\r
43\r
44# ===== SAXPARSEEXCEPTION =====\r
45\r
46class SAXParseException(SAXException):\r
47 """Encapsulate an XML parse error or warning.\r
48\r
49 This exception will include information for locating the error in\r
50 the original XML document. Note that although the application will\r
51 receive a SAXParseException as the argument to the handlers in the\r
52 ErrorHandler interface, the application is not actually required\r
53 to raise the exception; instead, it can simply read the\r
54 information in it and take a different action.\r
55\r
56 Since this exception is a subclass of SAXException, it inherits\r
57 the ability to wrap another exception."""\r
58\r
59 def __init__(self, msg, exception, locator):\r
60 "Creates the exception. The exception parameter is allowed to be None."\r
61 SAXException.__init__(self, msg, exception)\r
62 self._locator = locator\r
63\r
64 # We need to cache this stuff at construction time.\r
65 # If this exception is raised, the objects through which we must\r
66 # traverse to get this information may be deleted by the time\r
67 # it gets caught.\r
68 self._systemId = self._locator.getSystemId()\r
69 self._colnum = self._locator.getColumnNumber()\r
70 self._linenum = self._locator.getLineNumber()\r
71\r
72 def getColumnNumber(self):\r
73 """The column number of the end of the text where the exception\r
74 occurred."""\r
75 return self._colnum\r
76\r
77 def getLineNumber(self):\r
78 "The line number of the end of the text where the exception occurred."\r
79 return self._linenum\r
80\r
81 def getPublicId(self):\r
82 "Get the public identifier of the entity where the exception occurred."\r
83 return self._locator.getPublicId()\r
84\r
85 def getSystemId(self):\r
86 "Get the system identifier of the entity where the exception occurred."\r
87 return self._systemId\r
88\r
89 def __str__(self):\r
90 "Create a string representation of the exception."\r
91 sysid = self.getSystemId()\r
92 if sysid is None:\r
93 sysid = "<unknown>"\r
94 linenum = self.getLineNumber()\r
95 if linenum is None:\r
96 linenum = "?"\r
97 colnum = self.getColumnNumber()\r
98 if colnum is None:\r
99 colnum = "?"\r
100 return "%s:%s:%s: %s" % (sysid, linenum, colnum, self._msg)\r
101\r
102\r
103# ===== SAXNOTRECOGNIZEDEXCEPTION =====\r
104\r
105class SAXNotRecognizedException(SAXException):\r
106 """Exception class for an unrecognized identifier.\r
107\r
108 An XMLReader will raise this exception when it is confronted with an\r
109 unrecognized feature or property. SAX applications and extensions may\r
110 use this class for similar purposes."""\r
111\r
112\r
113# ===== SAXNOTSUPPORTEDEXCEPTION =====\r
114\r
115class SAXNotSupportedException(SAXException):\r
116 """Exception class for an unsupported operation.\r
117\r
118 An XMLReader will raise this exception when a service it cannot\r
119 perform is requested (specifically setting a state or value). SAX\r
120 applications and extensions may use this class for similar\r
121 purposes."""\r
122\r
123# ===== SAXNOTSUPPORTEDEXCEPTION =====\r
124\r
125class SAXReaderNotAvailable(SAXNotSupportedException):\r
126 """Exception class for a missing driver.\r
127\r
128 An XMLReader module (driver) should raise this exception when it\r
129 is first imported, e.g. when a support module cannot be imported.\r
130 It also may be raised during parsing, e.g. if executing an external\r
131 program is not permitted."""\r