[Jython-checkins] jython (merge 2.5 -> default): merge from 2.5: Fix for xml attribute namespace issue

alan.kennedy jython-checkins at python.org
Sun Oct 30 14:13:30 CET 2011


http://hg.python.org/jython/rev/179cb4437158
changeset:   6261:179cb4437158
parent:      6259:71b3f883f6c5
parent:      6260:936bd1b132eb
user:        Alan Kennedy <jython-dev at xhaus.com>
date:        Sun Oct 30 13:11:40 2011 +0000
summary:
  merge from 2.5: Fix for xml attribute namespace issue
http://bugs.jython.org/issue1768

files:
  Lib/test/test_sax.py                |  46 ++++++++--------
  Lib/xml/sax/drivers2/drv_javasax.py |   2 +-
  NEWS                                |   3 +
  3 files changed, 28 insertions(+), 23 deletions(-)


diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py
--- a/Lib/test/test_sax.py
+++ b/Lib/test/test_sax.py
@@ -390,22 +390,23 @@
     gather = AttrGatherer()
     parser.setContentHandler(gather)
 
-    parser.parse(StringIO("<doc xmlns:ns='%s' ns:attr='val'/>" % ns_uri))
+    a_name = "id" ; a_val = "val"
+    parser.parse(StringIO("<doc xmlns:ns='%s' ns:%s='%s'/>" % (ns_uri, a_name, a_val) ))
 
     attrs = gather._attrs
 
     return attrs.getLength() == 1 and \
-           attrs.getNames() == [(ns_uri, "attr")] and \
-           attrs.getQNames() == ["ns:attr"] and \
+           attrs.getNames() == [(ns_uri, a_name)] and \
+           attrs.getQNames() == ["ns:%s" % a_name] and \
            len(attrs) == 1 and \
-           attrs.has_key((ns_uri, "attr")) and \
-           attrs.keys() == [(ns_uri, "attr")] and \
-           attrs.get((ns_uri, "attr")) == "val" and \
-           attrs.get((ns_uri, "attr"), 25) == "val" and \
-           attrs.items() == [((ns_uri, "attr"), "val")] and \
-           attrs.values() == ["val"] and \
-           attrs.getValue((ns_uri, "attr")) == "val" and \
-           attrs[(ns_uri, "attr")] == "val"
+           attrs.has_key((ns_uri, a_name)) and \
+           attrs.keys() == [(ns_uri, a_name)] and \
+           attrs.get((ns_uri, a_name)) == a_val and \
+           attrs.get((ns_uri, a_name), 25) == a_val and \
+           attrs.items() == [((ns_uri, a_name), a_val)] and \
+           attrs.values() == [a_val] and \
+           attrs.getValue((ns_uri, a_name)) == a_val and \
+           attrs[(ns_uri, a_name)] == a_val
 
 def test_expat_nsattrs_no_namespace():
     parser = make_parser()
@@ -413,22 +414,23 @@
     gather = AttrGatherer()
     parser.setContentHandler(gather)
 
-    parser.parse(StringIO("<doc attr='val'/>"))
+    a_name = "id" ; a_val = "val"
+    parser.parse(StringIO("<doc %s='%s'/>" % (a_name, a_val) ))
 
     attrs = gather._attrs
 
     return attrs.getLength() == 1 and \
-           attrs.getNames() == [(None, "attr")] and \
-           attrs.getQNames() == ["attr"] and \
+           attrs.getNames() == [(None, a_name)] and \
+           attrs.getQNames() == [a_name] and \
            len(attrs) == 1 and \
-           attrs.has_key((None, "attr")) and \
-           attrs.keys() == [(None, "attr")] and \
-           attrs.get((None, "attr")) == "val" and \
-           attrs.get((None, "attr"), 25) == "val" and \
-           attrs.items() == [((None, "attr"), "val")] and \
-           attrs.values() == ["val"] and \
-           attrs.getValue((None, "attr")) == "val" and \
-           attrs[(None, "attr")] == "val"
+           attrs.has_key((None, a_name)) and \
+           attrs.keys() == [(None, a_name)] and \
+           attrs.get((None, a_name)) == a_val and \
+           attrs.get((None, a_name), 25) == a_val and \
+           attrs.items() == [((None, a_name), a_val)] and \
+           attrs.values() == [a_val] and \
+           attrs.getValue((None, a_name)) == a_val and \
+           attrs[(None, a_name)] == a_val
 
 # ===== InputSource support
 
diff --git a/Lib/xml/sax/drivers2/drv_javasax.py b/Lib/xml/sax/drivers2/drv_javasax.py
--- a/Lib/xml/sax/drivers2/drv_javasax.py
+++ b/Lib/xml/sax/drivers2/drv_javasax.py
@@ -238,7 +238,7 @@
         pass # TODO
 
 def _fixTuple(nsTuple, frm, to):
-    if len(nsTuple) == 2:
+    if isinstance(nsTuple, tuple) and len(nsTuple) == 2:
         nsUri, localName = nsTuple
         if nsUri == frm:
             nsUri = to
diff --git a/NEWS b/NEWS
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,9 @@
     - [ 1727 ] Error in Jython 2.5.2 with os.stat and varargs
     - [ 1735 ] return type of os.read is unicode, not str
     - [ 1755 ] os.utime('/tmp/nonexistent-file', None) fails to raise OSError
+    - [ 1768 ] sax.parse doesn't handle attributes with name 'id' correctly
+    - [ 1803 ] _tcpsocket doesn't have 'family' attribute
+    - [ 1804 ] _tcpsocket doesn't have 'type' and 'proto' attributes
     - [ 1811 ] Recursive import bug w/ SQLAlchemy 0.7.3
 
 Jython 2.5.2

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list