ยปCore Development>Code coverage>Lib/xml/sax/_exceptions.py

Python code coverage for Lib/xml/sax/_exceptions.py

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