Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8966759

Browse files
Issue #21888: plistlib's load() and loads() now work if the fmt parameter is
specified.
1 parent 64a1207 commit 8966759

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

Lib/plistlib.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -984,18 +984,16 @@ def load(fp, *, fmt=None, use_builtin_types=True, dict_type=dict):
984984
fp.seek(0)
985985
for info in _FORMATS.values():
986986
if info['detect'](header):
987-
p = info['parser'](
988-
use_builtin_types=use_builtin_types,
989-
dict_type=dict_type,
990-
)
987+
P = info['parser']
991988
break
992989

993990
else:
994991
raise InvalidFileException()
995992

996993
else:
997-
p = _FORMATS[fmt]['parser'](use_builtin_types=use_builtin_types)
994+
P = _FORMATS[fmt]['parser']
998995

996+
p = P(use_builtin_types=use_builtin_types, dict_type=dict_type)
999997
return p.parse(fp)
1000998

1001999

Lib/test/test_plistlib.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ def test_appleformattingfromliteral(self):
207207
for fmt in ALL_FORMATS:
208208
with self.subTest(fmt=fmt):
209209
pl = self._create(fmt=fmt)
210+
pl2 = plistlib.loads(TESTDATA[fmt], fmt=fmt)
211+
self.assertEqual(dict(pl), dict(pl2),
212+
"generated data was not identical to Apple's output")
210213
pl2 = plistlib.loads(TESTDATA[fmt])
211214
self.assertEqual(dict(pl), dict(pl2),
212215
"generated data was not identical to Apple's output")
@@ -217,6 +220,8 @@ def test_bytesio(self):
217220
b = BytesIO()
218221
pl = self._create(fmt=fmt)
219222
plistlib.dump(pl, b, fmt=fmt)
223+
pl2 = plistlib.load(BytesIO(b.getvalue()), fmt=fmt)
224+
self.assertEqual(dict(pl), dict(pl2))
220225
pl2 = plistlib.load(BytesIO(b.getvalue()))
221226
self.assertEqual(dict(pl), dict(pl2))
222227

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Core and Builtins
2727
Library
2828
-------
2929

30+
- Issue #21888: plistlib's load() and loads() now work if the fmt parameter is
31+
specified.
32+
3033
- Issue #21044: tarfile.open() now handles fileobj with an integer 'name'
3134
attribute. Based on patch by Antoine Pietri.
3235

0 commit comments

Comments
 (0)