Message6644

Author samuel337
Recipients pekka.klarck, samuel337
Date 2011-09-11.05:58:12
SpamBayes Score 8.493206e-15
Marked as misclassified No
Message-id <1315720693.01.0.993493108776.issue1768@psf.upfronthosting.co.za>
In-reply-to
Content
I just encountered this bug as well. It actually affects all attribute names that are exactly 2 characters long. 

The dirty workaround is to use - 

    attrs._attrs.getValue('id')

instead to get values, and remember that that will throw a KeyError exception if it does not exist.

The bug is rather simple - in Lib/xml/sax/drivers2/drv_javasax.py, in the function _fixTuple, on line 241, it checks the length of the first argument, nsTuple, and if it is a length of 2, assumes it is a tuple of (namespace, localName) and proceeds to unpack it. 

Unfortunately it doesn't check the type, and other methods (specifically _makeJavaNsTuple and _makePythonNsTuple) pass in a string instead, therefore a string of length 2 is assumed to be a (namespace, localName) tuple as a string is a sequence type as well.

The solution is to enact a type check that specifically excludes strings, e.g.

def _fixTuple(nsTuple, frm, to):
    # NOTE the isinstance check that excludes strings
    if not isinstance(nsTuple, str) and len(nsTuple) == 2:
        nsUri, localName = nsTuple
        if nsUri == frm:
            nsUri = to
        return (nsUri, localName)
    return nsTuple

The alternative is to check for a tuple, but that then you would exclude other sequence and sequence-like types.

I hope this is enough information to perform the one-liner fix; I can provide a diff file if necessary.
History
Date User Action Args
2011-09-11 05:58:13samuel337setmessageid: <1315720693.01.0.993493108776.issue1768@psf.upfronthosting.co.za>
2011-09-11 05:58:13samuel337setrecipients: + samuel337, pekka.klarck
2011-09-11 05:58:12samuel337linkissue1768 messages
2011-09-11 05:58:12samuel337create