[Python-checkins] python/dist/src/Lib/xml/dom domreg.py,1.1,1.2

loewis@users.sourceforge.net loewis@users.sourceforge.net
Sun, 26 Jan 2003 01:04:38 -0800


Update of /cvsroot/python/python/dist/src/Lib/xml/dom
In directory sc8-pr-cvs1:/tmp/cvs-serv19715

Modified Files:
	domreg.py 
Log Message:
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).


Index: domreg.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/dom/domreg.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** domreg.py	22 Feb 2001 14:04:09 -0000	1.1
--- domreg.py	26 Jan 2003 09:04:35 -0000	1.2
***************
*** 3,6 ****
--- 3,8 ----
  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
***************
*** 61,64 ****
--- 63,68 ----
      # 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()
***************
*** 75,76 ****
--- 79,99 ----
  
      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)