summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2003-01-26 09:04:35 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2003-01-26 09:04:35 (GMT)
commitf8de21c51bed1823a1a906562705ce84d9c4603d (patch)
treed6db4ebbc5ed1129c382f03bb6dc738b4b273014
parent041411a1c70e0e01fb32864359990d4fd3a20f97 (diff)
downloadcpython-f8de21c51bed1823a1a906562705ce84d9c4603d.zip
cpython-f8de21c51bed1823a1a906562705ce84d9c4603d.tar.gz
cpython-f8de21c51bed1823a1a906562705ce84d9c4603d.tar.bz2
Merge with PyXML 1.3:
Add support for the DOM Level 3 (draft) DOMImplementationSource interface to the xml.dom and xml.dom.minidom modules. Note API issue: the draft spec says to return null when there is no suitable implementation, while the Python getDOMImplementation() function raises ImportError (minor).
-rw-r--r--Lib/xml/dom/domreg.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/xml/dom/domreg.py b/Lib/xml/dom/domreg.py
index 14b87d6..0e6e615 100644
--- a/Lib/xml/dom/domreg.py
+++ b/Lib/xml/dom/domreg.py
@@ -2,6 +2,8 @@
directly. Instead, the functions getDOMImplementation and
registerDOMImplementation should be imported from xml.dom."""
+from xml.dom.minicompat import * # isinstance, StringTypes
+
# This is a list of well-known implementations. Well-known names
# should be published by posting to xml-sig@python.org, and are
# subsequently recorded in this file.
@@ -60,6 +62,8 @@ def getDOMImplementation(name = None, features = ()):
# User did not specify a name, try implementations in arbitrary
# order, returning the one that has the required features
+ if isinstance(features, StringTypes):
+ features = _parse_feature_string(features)
for creator in registered.values():
dom = creator()
if _good_enough(dom, features):
@@ -74,3 +78,22 @@ def getDOMImplementation(name = None, features = ()):
return dom
raise ImportError,"no suitable DOM implementation found"
+
+def _parse_feature_string(s):
+ features = []
+ parts = s.split()
+ i = 0
+ length = len(parts)
+ while i < length:
+ feature = parts[i]
+ if feature[0] in "0123456789":
+ raise ValueError, "bad feature name: " + `feature`
+ i = i + 1
+ version = None
+ if i < length:
+ v = parts[i]
+ if v[0] in "0123456789":
+ i = i + 1
+ version = v
+ features.append((feature, version))
+ return tuple(features)