source: trunk/essentials/dev-lang/python/Lib/xml/dom/domreg.py@ 3951

Last change on this file since 3951 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 3.4 KB
Line 
1"""Registration facilities for DOM. This module should not be used
2directly. Instead, the functions getDOMImplementation and
3registerDOMImplementation should be imported from xml.dom."""
4
5from 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
11well_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
19registered = {}
20
21def 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
32def _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
39def 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