1"""W3C Document Object Model implementation for Python.
2
3The Python mapping of the Document Object Model is documented in the
4Python Library Reference in the section on the xml.dom package.
5
6This package contains the following modules:
7
8minidom -- 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.
11
12pulldom -- DOM builder supporting on-demand tree-building for selected
13           subtrees of the document.
14
15"""
16
17
18class Node:
19    """Class giving the NodeType constants."""
20    __slots__ = ()
21
22    # DOM implementations may use this as a base class for their own
23    # Node implementations.  If they don't, the constants defined here
24    # should still be used as the canonical definitions as they match
25    # the values given in the W3C recommendation.  Client code can
26    # safely refer to these values in all tests of Node.nodeType
27    # values.
28
29    ELEMENT_NODE                = 1
30    ATTRIBUTE_NODE              = 2
31    TEXT_NODE                   = 3
32    CDATA_SECTION_NODE          = 4
33    ENTITY_REFERENCE_NODE       = 5
34    ENTITY_NODE                 = 6
35    PROCESSING_INSTRUCTION_NODE = 7
36    COMMENT_NODE                = 8
37    DOCUMENT_NODE               = 9
38    DOCUMENT_TYPE_NODE          = 10
39    DOCUMENT_FRAGMENT_NODE      = 11
40    NOTATION_NODE               = 12
41
42
43#ExceptionCode
44INDEX_SIZE_ERR                 = 1
45DOMSTRING_SIZE_ERR             = 2
46HIERARCHY_REQUEST_ERR          = 3
47WRONG_DOCUMENT_ERR             = 4
48INVALID_CHARACTER_ERR          = 5
49NO_DATA_ALLOWED_ERR            = 6
50NO_MODIFICATION_ALLOWED_ERR    = 7
51NOT_FOUND_ERR                  = 8
52NOT_SUPPORTED_ERR              = 9
53INUSE_ATTRIBUTE_ERR            = 10
54INVALID_STATE_ERR              = 11
55SYNTAX_ERR                     = 12
56INVALID_MODIFICATION_ERR       = 13
57NAMESPACE_ERR                  = 14
58INVALID_ACCESS_ERR             = 15
59VALIDATION_ERR                 = 16
60
61
62class DOMException(Exception):
63    """Abstract base class for DOM exceptions.
64    Exceptions with specific codes are specializations of this class."""
65
66    def __init__(self, *args, **kw):
67        if self.__class__ is DOMException:
68            raise RuntimeError(
69                "DOMException should not be instantiated directly")
70        Exception.__init__(self, *args, **kw)
71
72    def _get_code(self):
73        return self.code
74
75
76class IndexSizeErr(DOMException):
77    code = INDEX_SIZE_ERR
78
79class DomstringSizeErr(DOMException):
80    code = DOMSTRING_SIZE_ERR
81
82class HierarchyRequestErr(DOMException):
83    code = HIERARCHY_REQUEST_ERR
84
85class WrongDocumentErr(DOMException):
86    code = WRONG_DOCUMENT_ERR
87
88class InvalidCharacterErr(DOMException):
89    code = INVALID_CHARACTER_ERR
90
91class NoDataAllowedErr(DOMException):
92    code = NO_DATA_ALLOWED_ERR
93
94class NoModificationAllowedErr(DOMException):
95    code = NO_MODIFICATION_ALLOWED_ERR
96
97class NotFoundErr(DOMException):
98    code = NOT_FOUND_ERR
99
100class NotSupportedErr(DOMException):
101    code = NOT_SUPPORTED_ERR
102
103class InuseAttributeErr(DOMException):
104    code = INUSE_ATTRIBUTE_ERR
105
106class InvalidStateErr(DOMException):
107    code = INVALID_STATE_ERR
108
109class SyntaxErr(DOMException):
110    code = SYNTAX_ERR
111
112class InvalidModificationErr(DOMException):
113    code = INVALID_MODIFICATION_ERR
114
115class NamespaceErr(DOMException):
116    code = NAMESPACE_ERR
117
118class InvalidAccessErr(DOMException):
119    code = INVALID_ACCESS_ERR
120
121class ValidationErr(DOMException):
122    code = VALIDATION_ERR
123
124class UserDataHandler:
125    """Class giving the operation constants for UserDataHandler.handle()."""
126
127    # Based on DOM Level 3 (WD 9 April 2002)
128
129    NODE_CLONED   = 1
130    NODE_IMPORTED = 2
131    NODE_DELETED  = 3
132    NODE_RENAMED  = 4
133
134XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace"
135XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/"
136XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml"
137EMPTY_NAMESPACE = None
138EMPTY_PREFIX = None
139
140from .domreg import getDOMImplementation, registerDOMImplementation
141