I've been pushing an instance of xml.sax.xmlreader.AttributesImpl onto
my Context. AttributesImpl tries to implement a dictionary-like
interface, including __getitem__, but not __contains__.
Somehow, no matter what the value of x is, what's passed to
xml.sax.xmlreader.AttributesImpl is int(0).
This was causing a KeyError in template attribute lookup.
This is clearly a bug in AttributesImple or the xml.sax package in
general, but I'm patching Django back to use .has_key to avoid the
problem.
N.B. Anyone using Ellington news will have this problem.
Cheers,
Jeremy
It looks a bit more subtle than that class being incomplete. The default
xml.sax.xmlreader.AttributesImpl class is fine. All the way back to
Python 2.3. However, if you have PyXML installed for all the extra
goodies that supplies, that is transparently into the xml.* namespace
(via _xmlplus) and, in that case, AttributesImpl is missing a feature.
So this will work for some people, but not others.
> Somehow, no matter what the value of x is, what's passed to
> xml.sax.xmlreader.AttributesImpl is int(0).
>
> This was causing a KeyError in template attribute lookup.
>
> This is clearly a bug in AttributesImple or the xml.sax package in
> general, but I'm patching Django back to use .has_key to avoid the
> problem.
>
> N.B. Anyone using Ellington news will have this problem.
I'll go through that diff and revert the places that are likely to
affect something like this.
Regards,
Malcolm
--
Experience is something you don't get until just after you need it.
http://www.pointy-stick.com/blog/
I know Malcolm's busy with QS refactor, but I wanted to note, I've
made this a ticket so it doesn't get lost:
http://code.djangoproject.com/ticket/5297
Yes, it looks as if PyXML's _xmlplus.sax.xmlreader.AttributesImpl is
missing __contains__:
$ diff -u /usr/lib/python2.4/xml/sax/xmlreader.py /usr/lib/python2.4/site-packages/_xmlplus/sax/xmlreader.py
--- /usr/lib/python2.4/xml/sax/xmlreader.py 2007-07-18 22:24:05.000000000 -0500
+++ /usr/lib/python2.4/site-packages/_xmlplus/sax/xmlreader.py 2007-08-29 22:39:02.000000000 -0500
@@ -321,9 +321,6 @@
def has_key(self, name):
return self._attrs.has_key(name)
- def __contains__(self, name):
- return self._attrs.has_key(name)
-
def get(self, name, alternative=None):
return self._attrs.get(name, alternative)
Gary