Back to index

python3.2  3.2.2
Functions | Variables
xml.dom.domreg Namespace Reference

Functions

def registerDOMImplementation
def _good_enough
def getDOMImplementation
def _parse_feature_string

Variables

dictionary well_known_implementations
dictionary registered = {}

Detailed Description

Registration facilities for DOM. This module should not be used
directly. Instead, the functions getDOMImplementation and
registerDOMImplementation should be imported from xml.dom.

Function Documentation

def xml.dom.domreg._good_enough (   dom,
  features 
) [private]

Definition at line 32 of file domreg.py.

00032 
00033 def _good_enough(dom, features):
00034     "_good_enough(dom, features) -> Return 1 if the dom offers the features"
00035     for f,v in features:
00036         if not dom.hasFeature(f,v):
00037             return 0
00038     return 1

Here is the caller graph for this function:

def xml.dom.domreg._parse_feature_string (   s) [private]

Definition at line 82 of file domreg.py.

00082 
00083 def _parse_feature_string(s):
00084     features = []
00085     parts = s.split()
00086     i = 0
00087     length = len(parts)
00088     while i < length:
00089         feature = parts[i]
00090         if feature[0] in "0123456789":
00091             raise ValueError("bad feature name: %r" % (feature,))
00092         i = i + 1
00093         version = None
00094         if i < length:
00095             v = parts[i]
00096             if v[0] in "0123456789":
00097                 i = i + 1
00098                 version = v
00099         features.append((feature, version))
00100     return tuple(features)

Here is the caller graph for this function:

def xml.dom.domreg.getDOMImplementation (   name = None,
  features = () 
)
getDOMImplementation(name = None, features = ()) -> DOM implementation.

Return a suitable DOM implementation. The name is either
well-known, the module name of a DOM implementation, or None. If
it is not None, imports the corresponding module and returns
DOMImplementation object if the import succeeds.

If name is not given, consider the available implementations to
find one with the required feature set. If no implementation can
be found, raise an ImportError. The features list must be a sequence
of (feature, version) pairs which are passed to hasFeature.

Definition at line 39 of file domreg.py.

00039 
00040 def getDOMImplementation(name=None, features=()):
00041     """getDOMImplementation(name = None, features = ()) -> DOM implementation.
00042 
00043     Return a suitable DOM implementation. The name is either
00044     well-known, the module name of a DOM implementation, or None. If
00045     it is not None, imports the corresponding module and returns
00046     DOMImplementation object if the import succeeds.
00047 
00048     If name is not given, consider the available implementations to
00049     find one with the required feature set. If no implementation can
00050     be found, raise an ImportError. The features list must be a sequence
00051     of (feature, version) pairs which are passed to hasFeature."""
00052 
00053     import os
00054     creator = None
00055     mod = well_known_implementations.get(name)
00056     if mod:
00057         mod = __import__(mod, {}, {}, ['getDOMImplementation'])
00058         return mod.getDOMImplementation()
00059     elif name:
00060         return registered[name]()
00061     elif "PYTHON_DOM" in os.environ:
00062         return getDOMImplementation(name = os.environ["PYTHON_DOM"])
00063 
00064     # User did not specify a name, try implementations in arbitrary
00065     # order, returning the one that has the required features
00066     if isinstance(features, str):
00067         features = _parse_feature_string(features)
00068     for creator in registered.values():
00069         dom = creator()
00070         if _good_enough(dom, features):
00071             return dom
00072 
00073     for creator in well_known_implementations.keys():
00074         try:
00075             dom = getDOMImplementation(name = creator)
00076         except Exception: # typically ImportError, or AttributeError
00077             continue
00078         if _good_enough(dom, features):
00079             return dom
00080 
00081     raise ImportError("no suitable DOM implementation found")

Here is the call graph for this function:

Here is the caller graph for this function:

def xml.dom.domreg.registerDOMImplementation (   name,
  factory 
)
registerDOMImplementation(name, factory)

Register the factory function with the name. The factory function
should return an object which implements the DOMImplementation
interface. The factory function can either return the same object,
or a new one (e.g. if that implementation supports some
customization).

Definition at line 21 of file domreg.py.

00021 
00022 def registerDOMImplementation(name, factory):
00023     """registerDOMImplementation(name, factory)
00024 
00025     Register the factory function with the name. The factory function
00026     should return an object which implements the DOMImplementation
00027     interface. The factory function can either return the same object,
00028     or a new one (e.g. if that implementation supports some
00029     customization)."""
00030 
00031     registered[name] = factory


Variable Documentation

Definition at line 19 of file domreg.py.

Initial value:
00001 {
00002     'minidom':'xml.dom.minidom',
00003     '4DOM': 'xml.dom.DOMImplementation',
00004     }

Definition at line 11 of file domreg.py.