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

Commit

Permalink
plistlib: restore old readPlist/writePlist etc., with deprecation war…
Browse files Browse the repository at this point in the history
…ning
  • Loading branch information
anthrotype committed Jul 12, 2018
1 parent c6bc1cd commit d664f31
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Lib/ufoLib/plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
unicode,
basestring,
tounicode,
tobytes,
SimpleNamespace,
range,
)
Expand Down Expand Up @@ -388,3 +389,44 @@ def dumps(value, sort_keys=True, skipkeys=False, pretty_print=True):
pretty_print=pretty_print,
)
return fp.getvalue()


# The following functions were part of the old py2-like ufoLib.plistlib API.
# They are kept only for backward compatiblity.
from .utils import deprecated


@deprecated("Use 'load' instead")
def readPlist(path_or_file):
did_open = False
if isinstance(path_or_file, basestring):
path_or_file = open(path_or_file, "rb")
did_open = True
try:
return load(path_or_file)
finally:
if did_open:
path_or_file.close()


@deprecated("Use 'dump' instead")
def writePlist(value, path_or_file):
did_open = False
if isinstance(path_or_file, basestring):
path_or_file = open(path_or_file, "wb")
did_open = True
try:
dump(value, path_or_file)
finally:
if did_open:
path_or_file.close()


@deprecated("Use 'loads' instead")
def readPlistFromString(data):
return loads(tobytes(data, encoding="utf-8"))


@deprecated("Use 'dumps' instead")
def writePlistToString(value):
return dumps(value)

0 comments on commit d664f31

Please sign in to comment.