astropy/astropy — pull request #596 by mdboom (2013-01-02 18:47:40+00:00)
Title: VOTable INFO element content not getting loaded

When parsing a VOTable via astropy.io.vo.parse(), the text content for the INFO elements are apparently not getting loaded. This is important when the VOTable is the response from a standard VO DAL service (e.g. SIA) in which an INFO element's content provides an error message.

I looked into the code found that the INFO content gets consumed in astropy.io.vo.tree.info.parse() but is not stored. This method is actually inherited from astropy.io.vo.SimpleElement. I note that the parse methods for both the Resource and VOTableFile classes have code that suggest that they expect to see the closing INFO tag and pick up the INFO content then.

for start, tag, data, pos in iterator:
if start:
tag_mapping.get(tag, self._add_unknown_tag)(
iterator, tag, data, config, pos)
elif tag == 'DESCRIPTION':
...
elif tag == 'INFO':
self.infos[-1].content = data

This never happens since parse method invoked when the start tag is seen (_add_info()) consumes the closing tag.

It seems the proper place to fix this would be in astropy.io.vo.SimpleElementWithContent (which Info also inherits from); I get INFOs properly parsed if I add a parse() method:

def parse(self, iterator, config):
for start, tag, data, pos in iterator:
if start and tag != self._element_name:
self._add_unknown_tag(iterator, tag, data, config, pos)
elif tag == self._element_name:
# added this bit to fill INFO content
if data:
self.content = data
###
break

return self

When I next get a chance, I'll fork the respository, apply this fix, and request a merge, unless someone beats me to it.