classification
Title: plistlib output self-sorted dictionary
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: halfjuice, hynek, mher.movsisyan, ned.deily, ronaldoussoren
Priority: normal Keywords:

Created on 2013-06-08 03:52 by halfjuice, last changed 2014-07-23 16:07 by serhiy.storchaka. This issue is now closed.

Messages (5)
msg190792 - (view) Author: halfjuice (halfjuice) Date: 2013-06-08 03:52
Even with OrderedDict, the plistlib will still output the dict in its own order. Search for sorted(d.items()) in plistlib.py and you will know why. It is certainly warm-hearted to sort this before putting it into plist file but I think sometimes we just want a customized order.
msg190815 - (view) Author: Mher Movsisyan (mher.movsisyan) Date: 2013-06-08 18:28
I think this is not a bug. plistlib api accepts dict (not OrderedDict) and sorted output is a valid output. plistlib sorts dictionaries to be consistent with Apple's tools.

property list format [1] uses CFDictionary [2] with CFString keys. CFDictionary is unordered and the plist example in the format [1] is unordered too. But plutil [3] command sorts dictionaries. It is easy to observe by self-converting plist files with "plutil -convert xml1 test.plist" command.

1. https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man5/plist.5.html 

2. http://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFDictionaryRef/Reference/reference.html

3. https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/plutil.1.html
msg190845 - (view) Author: halfjuice (halfjuice) Date: 2013-06-09 06:03
Thanks for giving out docs and start a detail discussion on this Mher!

Sorry I'm not familiar with Apple plist tool (I'm using cocos2d-x on win32 for the moment...) Are you saying that plutil is used everytime we output a valid plist?

Another thing is whether the example in [1] is valid or not? If it is, I think we should provide unordered functionality.

The OrderedDict is subclass of dict and thus is acceptable as plistlib input. Actually when I remove the line for sort, the plist output as expected (with not order).
msg190888 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-06-10 06:22
I'm reworking the patch in #14455 and one of the things I intend to do is to add a keyword argument that controls whether or not the keys in dictionaries will be sorted by plistlib.
msg190942 - (view) Author: halfjuice (halfjuice) Date: 2013-06-11 02:41
Awesome. Thanks Ronald!
History
Date User Action Args
2014-07-23 16:07:37serhiy.storchakasetstatus: open -> closed
resolution: out of date
stage: resolved
2013-06-11 02:41:16halfjuicesetmessages: + msg190942
2013-06-10 06:22:33ronaldoussorensetmessages: + msg190888
2013-06-09 06:03:13halfjuicesetmessages: + msg190845
2013-06-08 19:01:13serhiy.storchakasetnosy: + ronaldoussoren, ned.deily, hynek
2013-06-08 18:28:28mher.movsisyansetnosy: + mher.movsisyan
messages: + msg190815
2013-06-08 03:52:16halfjuicecreate