Skip to content
This repository was archived by the owner on Jan 28, 2019. It is now read-only.
This repository was archived by the owner on Jan 28, 2019. It is now read-only.

plistlib should handle python2 ascii bytes as strings, not data #162

@anthrotype

Description

@anthrotype

the new ufoLib.plistlib always treats bytes as <data> and unicode as <string> (like in python 3).

However this creates problems when running under python2, where it's common to use the native str type (== bytes) to encode ASCII textual data

See adobe-type-tools/afdko#486 (comment)

We can't optimistically assume that all clients of ufoLib will be well-behaved and only pass unicode values whenever they intend to write textual data under python 2. Even the ufoLib's own validators simply check that the incoming values are instances of basestring (e.g. see fontinfo validators), which on python 2 of course includes both bytes and unicode types.

I think the best solution is to add support for the use_builtin_types option in plistlib.load/dump functions. When set to True, we get the current behavior. When set to False we get the legacy, deprecated behavior: ie. plistlib.Data (a thin wrapper around a bytes object) gets seralised to <data> elements, whereas basestring is written as <string> elements.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions