Fixed bug when setting empty value to optional non-string parameters
authorLaurent Bessard
Fri, 05 Apr 2013 00:08:02 +0200
changeset 1017 2925d6e49893
parent 1016 3d79c31e4697
child 1018 6b7ba640f49e
Fixed bug when setting empty value to optional non-string parameters
xmlclass/xmlclass.py
--- a/xmlclass/xmlclass.py	Fri Apr 05 00:06:28 2013 +0200
+++ b/xmlclass/xmlclass.py	Fri Apr 05 00:08:02 2013 +0200
@@ -1669,6 +1669,8 @@
                     raise ValueError("Wrong path!")
                 if attributes[parts[0]]["attr_type"]["basename"] == "boolean":
                     setattr(self, parts[0], value)
+                elif attributes[parts[0]]["use"] == "optional" and value == "":
+                    setattr(self, parts[0], None)
                 else:
                     setattr(self, parts[0], attributes[parts[0]]["attr_type"]["extract"](value, False))
             elif elements.has_key(parts[0]):
@@ -1677,6 +1679,8 @@
                         raise ValueError("Wrong path!")
                     if elements[parts[0]]["elmt_type"]["basename"] == "boolean":
                         setattr(self, parts[0], value)
+                    elif attributes[parts[0]]["minOccurs"] == 0 and value == "":
+                        setattr(self, parts[0], None)
                     else:
                         setattr(self, parts[0], elements[parts[0]]["elmt_type"]["extract"](value, False))
                 else: