Hi,
I have a small utility that auto-generates documentation for the commands in a tmbundle by extracting key-combo and documentation comments from the command files, see: https://github.com/persquare/CalvinScript.tmbundle/blob/master/Support/lib/h...
It works mostly well, but trying to parse a command file that contains a command mapped to the escape key using plistlib/biplist fails with an exception:
InvalidPlistException: ExpatError('not well-formed (invalid token): line 18, column 9',)
The (python) code to trigger is simple enough, plistlib or biplist doesn't matter:
try: import biplist as plistlib except: import plistlib
for file in os.listdir(path_to_cmd_dir_in_tmbundle): path = unicode(os.path.join(cmd_dir, file), 'utf-8') pl = plistlib.readPlist(path)
Any clues how to handle this?
/Per
On 29 Sep 2016, at 12:11, Per Persson wrote:
It works mostly well, but trying to parse a command file that contains a command mapped to the escape key using plistlib/biplist fails with an exception: […] Any clues how to handle this?
The issue is that XML does not allow ASCII control characters (and python checks this). XML 1.1 should allow them when entity-encoded, but both python 2.7.12 and 3.5.2 still throw an exception (for ``) in my test.
The biplist is using plistlib for XML property lists, so it may actually work for binary property lists.
So when encountering this exception, you could try convert the property list to its binary form (using `plutil`) and see if that works.
You could also look into using PyObjC and import `NSDictionary`, this should definitely read the file without problems.