mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-113537: support loads str in plistlib.loads (#113582)
Add support for loading XML plists from a string value instead of a only bytes value.
This commit is contained in:
parent
66f3964815
commit
bbf214df23
4 changed files with 24 additions and 3 deletions
|
|
@ -906,6 +906,11 @@ def loads(value, *, fmt=None, dict_type=dict, aware_datetime=False):
|
|||
"""Read a .plist file from a bytes object.
|
||||
Return the unpacked root object (which usually is a dictionary).
|
||||
"""
|
||||
if isinstance(value, str):
|
||||
if fmt == FMT_BINARY:
|
||||
raise TypeError("value must be bytes-like object when fmt is "
|
||||
"FMT_BINARY")
|
||||
value = value.encode()
|
||||
fp = BytesIO(value)
|
||||
return load(fp, fmt=fmt, dict_type=dict_type, aware_datetime=aware_datetime)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue