blob: 11cd3da6589e28c97f2aad6491433853ab299766 [file] [log] [blame]
Fred Drakee85c3502000-06-29 19:28:01 +00001"""W3C Document Object Model implementation for Python.
2
Fred Drake6bcf4c22000-12-11 22:29:23 +00003The Python mapping of the Document Object Model is documented in the
4Python Library Reference in the section on the xml.dom package.
Fred Drakee85c3502000-06-29 19:28:01 +00005
6This package contains the following modules:
7
8minidom -- A simple implementation of the Level 1 DOM with namespace
Fred Drake6bcf4c22000-12-11 22:29:23 +00009 support added (based on the Level 2 specification) and other
10 minor Level 2 functionality.
11
12pulldom -- DOM builder supporting on-demand tree-building for selected
13 subtrees of the document.
Fred Drakee85c3502000-06-29 19:28:01 +000014
15"""
Fred Drake6bcf4c22000-12-11 22:29:23 +000016
17
18class Node:
19 """Class giving the NodeType constants."""
20
21 # DOM implementations may use this as a base class for their own
22 # Node implementations. If they don't, the constants defined here
23 # should still be used as the canonical definitions as they match
24 # the values given in the W3C recommendation. Client code can
25 # safely refer to these values in all tests of Node.nodeType
26 # values.
27
28 ELEMENT_NODE = 1
29 ATTRIBUTE_NODE = 2
30 TEXT_NODE = 3
31 CDATA_SECTION_NODE = 4
32 ENTITY_REFERENCE_NODE = 5
33 ENTITY_NODE = 6
34 PROCESSING_INSTRUCTION_NODE = 7
35 COMMENT_NODE = 8
36 DOCUMENT_NODE = 9
37 DOCUMENT_TYPE_NODE = 10
38 DOCUMENT_FRAGMENT_NODE = 11
39 NOTATION_NODE = 12
Martin v. Löwis64acf1d2000-12-13 14:21:07 +000040
Fred Drake5d1b5ea2000-12-13 16:35:53 +000041
Martin v. Löwis64acf1d2000-12-13 14:21:07 +000042#ExceptionCode
43INDEX_SIZE_ERR = 1
44DOMSTRING_SIZE_ERR = 2
45HIERARCHY_REQUEST_ERR = 3
46WRONG_DOCUMENT_ERR = 4
47INVALID_CHARACTER_ERR = 5
48NO_DATA_ALLOWED_ERR = 6
49NO_MODIFICATION_ALLOWED_ERR = 7
50NOT_FOUND_ERR = 8
51NOT_SUPPORTED_ERR = 9
52INUSE_ATTRIBUTE_ERR = 10
53INVALID_STATE_ERR = 11
54SYNTAX_ERR = 12
55INVALID_MODIFICATION_ERR = 13
56NAMESPACE_ERR = 14
57INVALID_ACCESS_ERR = 15
Fred Drakea3502702002-08-09 14:57:55 +000058VALIDATION_ERR = 16
Martin v. Löwis64acf1d2000-12-13 14:21:07 +000059
Fred Drake5d1b5ea2000-12-13 16:35:53 +000060
Martin v. Löwis64acf1d2000-12-13 14:21:07 +000061class DOMException(Exception):
62 """Abstract base class for DOM exceptions.
63 Exceptions with specific codes are specializations of this class."""
Martin v. Löwis52ce0d02001-01-27 08:47:37 +000064
Fred Drake5d1b5ea2000-12-13 16:35:53 +000065 def __init__(self, *args, **kw):
66 if self.__class__ is DOMException:
67 raise RuntimeError(
Fred Drakef16527c2000-12-15 23:56:43 +000068 "DOMException should not be instantiated directly")
Fred Drake279aa6c2000-12-15 21:07:59 +000069 apply(Exception.__init__, (self,) + args, kw)
Fred Drake5d1b5ea2000-12-13 16:35:53 +000070
Fred Drakeb6a44252001-02-19 14:57:02 +000071 def _get_code(self):
72 return self.code
73
Martin v. Löwis64acf1d2000-12-13 14:21:07 +000074
75class IndexSizeErr(DOMException):
76 code = INDEX_SIZE_ERR
77
78class DomstringSizeErr(DOMException):
79 code = DOMSTRING_SIZE_ERR
80
81class HierarchyRequestErr(DOMException):
82 code = HIERARCHY_REQUEST_ERR
83
84class WrongDocumentErr(DOMException):
85 code = WRONG_DOCUMENT_ERR
86
87class InvalidCharacterErr(DOMException):
88 code = INVALID_CHARACTER_ERR
89
90class NoDataAllowedErr(DOMException):
91 code = NO_DATA_ALLOWED_ERR
92
93class NoModificationAllowedErr(DOMException):
94 code = NO_MODIFICATION_ALLOWED_ERR
95
96class NotFoundErr(DOMException):
97 code = NOT_FOUND_ERR
98
99class NotSupportedErr(DOMException):
100 code = NOT_SUPPORTED_ERR
101
102class InuseAttributeErr(DOMException):
103 code = INUSE_ATTRIBUTE_ERR
104
105class InvalidStateErr(DOMException):
106 code = INVALID_STATE_ERR
107
108class SyntaxErr(DOMException):
109 code = SYNTAX_ERR
110
111class InvalidModificationErr(DOMException):
112 code = INVALID_MODIFICATION_ERR
113
114class NamespaceErr(DOMException):
115 code = NAMESPACE_ERR
116
117class InvalidAccessErr(DOMException):
118 code = INVALID_ACCESS_ERR
Martin v. Löwis7edbd4f2001-02-22 14:05:50 +0000119
Fred Drakea3502702002-08-09 14:57:55 +0000120class ValidationErr(DOMException):
121 code = VALIDATION_ERR
122
Fred Drakebd34b6b2001-11-30 15:37:33 +0000123
124XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace"
125XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/"
126XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml"
127EMPTY_NAMESPACE = None
Fred Drakea3502702002-08-09 14:57:55 +0000128EMPTY_PREFIX = None
Fred Drakebd34b6b2001-11-30 15:37:33 +0000129
Martin v. Löwis7edbd4f2001-02-22 14:05:50 +0000130from domreg import getDOMImplementation,registerDOMImplementation