Permalink
Browse files

- pass through non-NS aware attribute names as is; a ":" should just …

…go to

ValueError
- use boolean test for attributes dict
  • Loading branch information...
1 parent 3222e75 commit b844f9e507c6155b1b2e7e95ed659d5e4c44fae8 @zzzeek zzzeek committed Mar 30, 2013
Showing with 6 additions and 20 deletions.
  1. +2 −7 src/lxml/sax.py
  2. +4 −13 src/lxml/tests/test_sax.py
View
9 src/lxml/sax.py
@@ -26,11 +26,6 @@ def _getNsTag(tag):
else:
return (None, tag)
-def _getAttrNSTag(attr_key):
- if ":" in attr_key:
- return tuple(attr_key.split(":", 1))
- else:
- return (None, attr_key)
class ElementTreeContentHandler(ContentHandler):
"""Build an lxml ElementTree from SAX events.
@@ -133,9 +128,9 @@ def endElementNS(self, ns_name, qname):
raise SaxError("Unexpected element closed: " + el_tag)
def startElement(self, name, attributes=None):
- if attributes is not None:
+ if attributes:
attributes = dict(
- [(_getAttrNSTag(k), v) for k, v in attributes.items()]
+ [((None, k), v) for k, v in attributes.items()]
)
self.startElementNS((None, name), name, attributes)
View
17 src/lxml/tests/test_sax.py
@@ -236,19 +236,10 @@ def test_etree_sax_ns_attributes(self):
handler = sax.ElementTreeContentHandler()
handler.startDocument()
- handler.startElement('a', {"blaA:attr_a1": "a1"})
- handler.startElement('b', {"blaA:attr_b1": "b1"})
- handler.endElement('b')
- handler.endElement('a')
-
- handler.endDocument()
-
- new_tree = handler.etree
- root = new_tree.getroot()
- self.assertEqual('a', root.tag)
- self.assertEqual('b', root[0].tag)
- self.assertEqual('a1', root.attrib["{blaA}attr_a1"])
- self.assertEqual('b1', root[0].attrib["{blaA}attr_b1"])
+ self.assertRaises(ValueError,
+ handler.startElement,
+ 'a', {"blaA:attr_a1": "a1"}
+ )
def test_etree_sax_error(self):
handler = sax.ElementTreeContentHandler()

0 comments on commit b844f9e

Please sign in to comment.