1 """W3C Document Object Model implementation for Python.
3 The Python mapping of the Document Object Model is documented in the
4 Python Library Reference in the section on the xml.dom package.
6 This package contains the following modules:
8 minidom -- A simple implementation of the Level 1 DOM with namespace
9 support added (based on the Level 2 specification) and other
10 minor Level 2 functionality.
12 pulldom -- DOM builder supporting on-demand tree-building for selected
13 subtrees of the document.
19 """Class giving the NodeType constants."""
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
31 CDATA_SECTION_NODE
= 4
32 ENTITY_REFERENCE_NODE
= 5
34 PROCESSING_INSTRUCTION_NODE
= 7
37 DOCUMENT_TYPE_NODE
= 10
38 DOCUMENT_FRAGMENT_NODE
= 11
44 DOMSTRING_SIZE_ERR
= 2
45 HIERARCHY_REQUEST_ERR
= 3
46 WRONG_DOCUMENT_ERR
= 4
47 INVALID_CHARACTER_ERR
= 5
48 NO_DATA_ALLOWED_ERR
= 6
49 NO_MODIFICATION_ALLOWED_ERR
= 7
52 INUSE_ATTRIBUTE_ERR
= 10
53 INVALID_STATE_ERR
= 11
55 INVALID_MODIFICATION_ERR
= 13
57 INVALID_ACCESS_ERR
= 15
61 class DOMException(Exception):
62 """Abstract base class for DOM exceptions.
63 Exceptions with specific codes are specializations of this class."""
65 def __init__(self
, *args
, **kw
):
66 if self
.__class
__ is DOMException
:
68 "DOMException should not be instantiated directly")
69 Exception.__init
__(self
, *args
, **kw
)
75 class IndexSizeErr(DOMException
):
78 class DomstringSizeErr(DOMException
):
79 code
= DOMSTRING_SIZE_ERR
81 class HierarchyRequestErr(DOMException
):
82 code
= HIERARCHY_REQUEST_ERR
84 class WrongDocumentErr(DOMException
):
85 code
= WRONG_DOCUMENT_ERR
87 class InvalidCharacterErr(DOMException
):
88 code
= INVALID_CHARACTER_ERR
90 class NoDataAllowedErr(DOMException
):
91 code
= NO_DATA_ALLOWED_ERR
93 class NoModificationAllowedErr(DOMException
):
94 code
= NO_MODIFICATION_ALLOWED_ERR
96 class NotFoundErr(DOMException
):
99 class NotSupportedErr(DOMException
):
100 code
= NOT_SUPPORTED_ERR
102 class InuseAttributeErr(DOMException
):
103 code
= INUSE_ATTRIBUTE_ERR
105 class InvalidStateErr(DOMException
):
106 code
= INVALID_STATE_ERR
108 class SyntaxErr(DOMException
):
111 class InvalidModificationErr(DOMException
):
112 code
= INVALID_MODIFICATION_ERR
114 class NamespaceErr(DOMException
):
117 class InvalidAccessErr(DOMException
):
118 code
= INVALID_ACCESS_ERR
120 class ValidationErr(DOMException
):
121 code
= VALIDATION_ERR
123 class UserDataHandler
:
124 """Class giving the operation constants for UserDataHandler.handle()."""
126 # Based on DOM Level 3 (WD 9 April 2002)
133 XML_NAMESPACE
= "http://www.w3.org/XML/1998/namespace"
134 XMLNS_NAMESPACE
= "http://www.w3.org/2000/xmlns/"
135 XHTML_NAMESPACE
= "http://www.w3.org/1999/xhtml"
136 EMPTY_NAMESPACE
= None
139 from domreg
import getDOMImplementation
,registerDOMImplementation