| 1 | """Registration facilities for DOM. This module should not be used
|
|---|
| 2 | directly. Instead, the functions getDOMImplementation and
|
|---|
| 3 | registerDOMImplementation should be imported from xml.dom."""
|
|---|
| 4 |
|
|---|
| 5 | from xml.dom.minicompat import * # isinstance, StringTypes
|
|---|
| 6 |
|
|---|
| 7 | # This is a list of well-known implementations. Well-known names
|
|---|
| 8 | # should be published by posting to [email protected], and are
|
|---|
| 9 | # subsequently recorded in this file.
|
|---|
| 10 |
|
|---|
| 11 | well_known_implementations = {
|
|---|
| 12 | 'minidom':'xml.dom.minidom',
|
|---|
| 13 | '4DOM': 'xml.dom.DOMImplementation',
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | # DOM implementations not officially registered should register
|
|---|
| 17 | # themselves with their
|
|---|
| 18 |
|
|---|
| 19 | registered = {}
|
|---|
| 20 |
|
|---|
| 21 | def registerDOMImplementation(name, factory):
|
|---|
| 22 | """registerDOMImplementation(name, factory)
|
|---|
| 23 |
|
|---|
| 24 | Register the factory function with the name. The factory function
|
|---|
| 25 | should return an object which implements the DOMImplementation
|
|---|
| 26 | interface. The factory function can either return the same object,
|
|---|
| 27 | or a new one (e.g. if that implementation supports some
|
|---|
| 28 | customization)."""
|
|---|
| 29 |
|
|---|
| 30 | registered[name] = factory
|
|---|
| 31 |
|
|---|
| 32 | def _good_enough(dom, features):
|
|---|
| 33 | "_good_enough(dom, features) -> Return 1 if the dom offers the features"
|
|---|
| 34 | for f,v in features:
|
|---|
| 35 | if not dom.hasFeature(f,v):
|
|---|
| 36 | return 0
|
|---|
| 37 | return 1
|
|---|
| 38 |
|
|---|
| 39 | def getDOMImplementation(name = None, features = ()):
|
|---|
| 40 | """getDOMImplementation(name = None, features = ()) -> DOM implementation.
|
|---|
| 41 |
|
|---|
| 42 | Return a suitable DOM implementation. The name is either
|
|---|
| 43 | well-known, the module name of a DOM implementation, or None. If
|
|---|
| 44 | it is not None, imports the corresponding module and returns
|
|---|
| 45 | DOMImplementation object if the import succeeds.
|
|---|
| 46 |
|
|---|
| 47 | If name is not given, consider the available implementations to
|
|---|
|
|---|