quandyfactory / dicttoxml

Simple library to convert a Python dictionary or other native data type into a valid XML string.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Boolean turns into number

badsequel opened this issue · comments

Hi,

Ref this:

Python -> XML
integer int
long long
float float
Decimal number
string str
unicode str
datetime str
None null
boolean bool
list list
set list
tuple list
dict dict

This code produces the below xml. the element has a type attribute set to "number". Should be bool, if I am reading the above correctly and haven't missed something obvious.

from dicttoxml import dicttoxml

aBool = bool(1) 
aString = str("Bob")
anInt = int(10)

data = [
   { "person": {
   "name" : aString,"age":anInt, "kid": aBool}
   }
   ]

xml = dicttoxml(data,attr_type = True, root=False) 
xml_string = xml.decode('utf-8')

print(xml_string)
<item type="dict">
    <person type="dict">
        <kid type="number">True</kid>
        <name type="str">Bob</name>
        <age type="int">10</age>
    </person>
</item>

Thanks for catching this. It turns out that the test isinstance(True, numbers.Number) returns True. I modified the get_xml_type() function to test for boolean values before testing for numbers and the issue is fixed in version 1.6.5.

Note that I'm currently getting an Upload failed (500): Internal Server Error when I try to upload the newest version of dicttoxml to pypi, so for now you'll have to get the code from github.

So I incremented the version to 1.6.6, reinstalled it and re-uploaded it to pypi, and now it works. Not sure what the issue was with 1.6.5, but the newest version is now available both here on github and via pypi.

Fix confirmed. Thanx.