Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8de21c

Browse files
committed
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).
1 parent 041411a commit f8de21c

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lib/xml/dom/domreg.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
directly. Instead, the functions getDOMImplementation and
33
registerDOMImplementation should be imported from xml.dom."""
44

5+
from xml.dom.minicompat import * # isinstance, StringTypes
6+
57
# This is a list of well-known implementations. Well-known names
68
# should be published by posting to [email protected], and are
79
# subsequently recorded in this file.
@@ -60,6 +62,8 @@ def getDOMImplementation(name = None, features = ()):
6062

6163
# User did not specify a name, try implementations in arbitrary
6264
# order, returning the one that has the required features
65+
if isinstance(features, StringTypes):
66+
features = _parse_feature_string(features)
6367
for creator in registered.values():
6468
dom = creator()
6569
if _good_enough(dom, features):
@@ -74,3 +78,22 @@ def getDOMImplementation(name = None, features = ()):
7478
return dom
7579

7680
raise ImportError,"no suitable DOM implementation found"
81+
82+
def _parse_feature_string(s):
83+
features = []
84+
parts = s.split()
85+
i = 0
86+
length = len(parts)
87+
while i < length:
88+
feature = parts[i]
89+
if feature[0] in "0123456789":
90+
raise ValueError, "bad feature name: " + `feature`
91+
i = i + 1
92+
version = None
93+
if i < length:
94+
v = parts[i]
95+
if v[0] in "0123456789":
96+
i = i + 1
97+
version = v
98+
features.append((feature, version))
99+
return tuple(features)

0 commit comments

Comments
 (0)