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
(name=None, features=())
| 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 |
| 48 | find one with the required feature set. If no implementation can |
| 49 | be found, raise an ImportError. The features list must be a sequence |
| 50 | of (feature, version) pairs which are passed to hasFeature.""" |
| 51 | |
| 52 | import os |
| 53 | creator = None |
| 54 | mod = well_known_implementations.get(name) |
| 55 | if mod: |
| 56 | mod = __import__(mod, {}, {}, ['getDOMImplementation']) |
| 57 | return mod.getDOMImplementation() |
| 58 | elif name: |
| 59 | return registered[name]() |
| 60 | elif not sys.flags.ignore_environment and "PYTHON_DOM" in os.environ: |
| 61 | return getDOMImplementation(name = os.environ["PYTHON_DOM"]) |
| 62 | |
| 63 | # User did not specify a name, try implementations in arbitrary |
| 64 | # order, returning the one that has the required features |
| 65 | if isinstance(features, str): |
| 66 | features = _parse_feature_string(features) |
| 67 | for creator in registered.values(): |
| 68 | dom = creator() |
| 69 | if _good_enough(dom, features): |
| 70 | return dom |
| 71 | |
| 72 | for creator in well_known_implementations.keys(): |
| 73 | try: |
| 74 | dom = getDOMImplementation(name = creator) |
| 75 | except Exception: # typically ImportError, or AttributeError |
| 76 | continue |
| 77 | if _good_enough(dom, features): |
| 78 | return dom |
| 79 | |
| 80 | raise ImportError("no suitable DOM implementation found") |
| 81 | |
| 82 | def _parse_feature_string(s): |
| 83 | features = [] |
searching dependent graphs…