Skip to content

Commit

Permalink
Merge pull request #18 from miguelsousa/true-integer
Browse files Browse the repository at this point in the history
Write plist floats as integers if they can be converted
  • Loading branch information
typesupply committed Dec 10, 2015
2 parents f87d5ea + d19be63 commit b492423
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions normalization/ufonormalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2467,9 +2467,14 @@ def propertyListObject(self, data):
>>> writer.getText() == u'<dict>\\n\\t<key>a</key>\\n\\t<string>b</string>\\n</dict>'
True
>>> writer = XMLWriter(declaration=None)
>>> writer.propertyListObject({"a" : 20.2})
>>> writer.getText() == u'<dict>\\n\\t<key>a</key>\\n\\t<real>20.2</real>\\n</dict>'
True
>>> writer = XMLWriter(declaration=None)
>>> writer.propertyListObject({"a" : 20.0})
>>> writer.getText() == u'<dict>\\n\\t<key>a</key>\\n\\t<real>20</real>\\n</dict>'
>>> writer.getText() == u'<dict>\\n\\t<key>a</key>\\n\\t<integer>20</integer>\\n</dict>'
True
>>> writer = XMLWriter(declaration=None)
Expand Down Expand Up @@ -2533,28 +2538,28 @@ def propertyListObject(self, data):
>>> writer.getText() == u'<real>-1.1</real>'
True
Integer
-------
>>> writer = XMLWriter(declaration=None)
>>> writer.propertyListObject(1.0)
>>> writer.getText() == u'<real>1</real>'
>>> writer.getText() == u'<integer>1</integer>'
True
>>> writer = XMLWriter(declaration=None)
>>> writer.propertyListObject(-1.0)
>>> writer.getText() == u'<real>-1</real>'
>>> writer.getText() == u'<integer>-1</integer>'
True
>>> writer = XMLWriter(declaration=None)
>>> writer.propertyListObject(0.0)
>>> writer.getText() == u'<real>0</real>'
>>> writer.getText() == u'<integer>0</integer>'
True
>>> writer = XMLWriter(declaration=None)
>>> writer.propertyListObject(-0.0)
>>> writer.getText() == u'<real>0</real>'
>>> writer.getText() == u'<integer>0</integer>'
True
Integer
-------
>>> writer = XMLWriter(declaration=None)
>>> writer.propertyListObject(1)
>>> writer.getText() == u'<integer>1</integer>'
Expand Down Expand Up @@ -2635,7 +2640,12 @@ def propertyListObject(self, data):
elif isinstance(data, (int, long)):
self._plistInt(data)
elif isinstance(data, float):
self._plistFloat(data)
dataStr = xmlConvertFloat(data)
try:
data = int(dataStr)
self._plistInt(data)
except ValueError:
self._plistFloat(data)
elif isinstance(data, plistlib.Data):
self._plistData(data)
elif isinstance(data, datetime.datetime):
Expand Down

0 comments on commit b492423

Please sign in to comment.