repair non-namespace-aware attribute mis-interpretation in ElementTreeContentHandler #107

Merged
merged 2 commits into from Mar 31, 2013

Conversation

Projects
None yet
2 participants
@zzzeek
Contributor

zzzeek commented Mar 30, 2013

this pull request allows the usage of non-NS aware SAX parsers to work properly with ElementTreeContentHandler, regarding attributes. This refers to https://bugs.launchpad.net/lxml/+bug/1136509.

Summary test:

document = """<?xml version="1.0" encoding="utf-8"?>
<SomeDocument>
    <Data FooBar="123">
    </Data>
</SomeDocument>
"""

from lxml import sax
from xml.sax import parse
from StringIO import StringIO

parse(StringIO(document), sax.ElementTreeContentHandler())

Above, the non-namespace aware parser generated by xml.sax.parse() calls the startElement() method, which ElementTreeContentHandler refers to startElementNS(). The attribute "FooBar" however must be expanded to the form (None, "FooBar"): "123" in order to be interpreted correctly by startElementNS().

zzzeek added some commits Mar 29, 2013

- repair issue in sax.ElementTreeContentHandler
whereby attributes passed to startElement() would be mis-interpreted
as containing a namespace attribute, leading to a TypeError,
as well as where attributes with namespaces wouldn't be split
up correctly when passed to startElement().
- pass through non-NS aware attribute names as is; a ":" should just …
…go to

ValueError
- use boolean test for attributes dict
@scoder

This comment has been minimized.

Show comment
Hide comment
@scoder

scoder Mar 31, 2013

Member

Thanks!

Member

scoder commented Mar 31, 2013

Thanks!

scoder added a commit that referenced this pull request Mar 31, 2013

Merge pull request #107 from zzzeek/master
repair non-namespace-aware attribute mis-interpretation in ElementTreeContentHandler

@scoder scoder merged commit 103cd6c into lxml:master Mar 31, 2013

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment