ntt / eveapi

Python library for accessing the EVE Online API
Other
148 stars 57 forks source link

Rowset column have a name, row - doesn't always have an attribute with this name #6

Closed ave- closed 12 years ago

ave- commented 12 years ago

While working with ContractItems API I've stumbled upon a bug - while columns attribute in rowset always contains name "rawQuantity", row doesn't. Example XML:

<eveapi version="2">
<currentTime>2012-02-22 18:05:44</currentTime>
<result>
<rowset name="itemList" key="recordID" columns="recordID,typeID,quantity,rawQuantity,singleton,included">
<row recordID="643979193" typeID="16064" quantity="1" singleton="0" included="1"/>
</rowset>
</result>
<cachedUntil>2022-02-19 04:25:56</cachedUntil>
</eveapi>

In current implementation, attributes taken from row are not parsed, it is assumed that columns count in rowset is equal to attributes count in row (or less, but a fix for that is already implemented). In this situation, columns in row are "shifted" and included column is not even created. Instead, rawQuality is filled with singleton value, and singleton is filled with included value.

I've created a quick hack to remedy this situation (and my Python skill is quite low, so it can be very inefficient), but just by pre-filling a list with zero integer values and then re-filling it by index of column name. I don't like this kind of solution and ask for a more proper variant instead (if any).

Quick (and dirty) fix below:

            # <hack>
            # - check for missing attributes while columns do exist!
            # very ugly hack and dunno what to do with zero values created
            # 
            if (len(attributes)/2 < len(self.container._cols)):
                hacklist=[0]*len(self.container._cols) #predef length!
                for i in xrange(0, len(attributes), 2):
                    hacklist[self.container._cols.index(attributes[i])]=_autocast(attributes[i], attributes[i+1])
                self.container.append(hacklist)
            else:
            # </hack>
                self.container.append([_autocast(attributes[i], attributes[i+1]) for i in xrange(0, len(attributes), 2)])

P.S. I'm not a native English speaker, so some wordings may be incorrect. Feel free to ask if something is not quite understandable.

ntt commented 12 years ago

Perfectly clear :) Just pushed a fix. Thanks!