classification
Title: plistlib - str converted to bool
Type: Stage:
Components: Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: VertigoRay
Priority: normal Keywords:

Created on 2013-09-04 21:51 by VertigoRay, last changed 2013-09-04 22:00 by VertigoRay. This issue is now closed.

Messages (2)
msg196959 - (view) Author: Ray (VertigoRay) Date: 2013-09-04 21:51
A plist with:
<key>My key</key>
<string>False</string>

will parse to a dict as:
{'My key': False}

Expected:
{'My key': 'False'}

If bool(False) is needed, the plist should say:
<key>My key</key>
<false/>
msg196963 - (view) Author: Ray (VertigoRay) Date: 2013-09-04 22:00
Disregard, I think.  I'm not sure why, but my current app seems to be doing the converting.

>>> import plistlib
>>> pl = {'My key': 'False'}
>>> plist = plistlib.writePlistToString(pl)
>>> plist
'<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n\t<key>My key</key>\n\t<string>False</string>\n</dict>\n</plist>\n'
>>> plistlib.readPlistFromString(plist)
{'My key': 'False'}
>>> pl = {'My key': False}
>>> plist = plistlib.writePlistToString(pl)
>>> plist
'<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n\t<key>My key</key>\n\t<false/>\n</dict>\n</plist>\n'
>>> plistlib.readPlistFromString(plist)
{'My key': False}
History
Date User Action Args
2013-09-04 22:00:57VertigoRaysetstatus: open -> closed
resolution: not a bug
messages: + msg196963
2013-09-04 21:51:08VertigoRaycreate