1 """W3C Document Object Model implementation for Python.
2 
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.
5 
6 This package contains the following modules:
7 
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.
11 
12 pulldom -- DOM builder supporting on-demand tree-building for selected
13            subtrees of the document.
14 
15 """
16 
17 
18 class 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
44 INDEX_SIZE_ERR                 = 1
45 DOMSTRING_SIZE_ERR             = 2
46 HIERARCHY_REQUEST_ERR          = 3
47 WRONG_DOCUMENT_ERR             = 4
48 INVALID_CHARACTER_ERR          = 5
49 NO_DATA_ALLOWED_ERR            = 6
50 NO_MODIFICATION_ALLOWED_ERR    = 7
51 NOT_FOUND_ERR                  = 8
52 NOT_SUPPORTED_ERR              = 9
53 INUSE_ATTRIBUTE_ERR            = 10
54 INVALID_STATE_ERR              = 11
55 SYNTAX_ERR                     = 12
56 INVALID_MODIFICATION_ERR       = 13
57 NAMESPACE_ERR                  = 14
58 INVALID_ACCESS_ERR             = 15
59 VALIDATION_ERR                 = 16
60 
61 
62 class 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 
76 class IndexSizeErr(DOMException):
77     code = INDEX_SIZE_ERR
78 
79 class DomstringSizeErr(DOMException):
80     code = DOMSTRING_SIZE_ERR
81 
82 class HierarchyRequestErr(DOMException):
83     code = HIERARCHY_REQUEST_ERR
84 
85 class WrongDocumentErr(DOMException):
86     code = WRONG_DOCUMENT_ERR
87 
88 class InvalidCharacterErr(DOMException):
89     code = INVALID_CHARACTER_ERR
90 
91 class NoDataAllowedErr(DOMException):
92     code = NO_DATA_ALLOWED_ERR
93 
94 class NoModificationAllowedErr(DOMException):
95     code = NO_MODIFICATION_ALLOWED_ERR
96 
97 class NotFoundErr(DOMException):
98     code = NOT_FOUND_ERR
99 
100 class NotSupportedErr(DOMException):
101     code = NOT_SUPPORTED_ERR
102 
103 class InuseAttributeErr(DOMException):
104     code = INUSE_ATTRIBUTE_ERR
105 
106 class InvalidStateErr(DOMException):
107     code = INVALID_STATE_ERR
108 
109 class SyntaxErr(DOMException):
110     code = SYNTAX_ERR
111 
112 class InvalidModificationErr(DOMException):
113     code = INVALID_MODIFICATION_ERR
114 
115 class NamespaceErr(DOMException):
116     code = NAMESPACE_ERR
117 
118 class InvalidAccessErr(DOMException):
119     code = INVALID_ACCESS_ERR
120 
121 class ValidationErr(DOMException):
122     code = VALIDATION_ERR
123 
124 class 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 
134 XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace"
135 XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/"
136 XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml"
137 EMPTY_NAMESPACE = None
138 EMPTY_PREFIX = None
139 
140 from .domreg import getDOMImplementation, registerDOMImplementation
141