__init__.py 3.9 KB

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