Skip to content

Commit

Permalink
Issue python#21888: plistlib's load() and loads() now work if the fmt…
Browse files Browse the repository at this point in the history
… parameter is

specified.
  • Loading branch information
serhiy-storchaka committed Jul 23, 2014
1 parent 64a1207 commit 8966759
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 3 additions & 5 deletions Lib/plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,18 +984,16 @@ def load(fp, *, fmt=None, use_builtin_types=True, dict_type=dict):
fp.seek(0)
for info in _FORMATS.values():
if info['detect'](header):
p = info['parser'](
use_builtin_types=use_builtin_types,
dict_type=dict_type,
)
P = info['parser']
break

else:
raise InvalidFileException()

else:
p = _FORMATS[fmt]['parser'](use_builtin_types=use_builtin_types)
P = _FORMATS[fmt]['parser']

p = P(use_builtin_types=use_builtin_types, dict_type=dict_type)
return p.parse(fp)


Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ def test_appleformattingfromliteral(self):
for fmt in ALL_FORMATS:
with self.subTest(fmt=fmt):
pl = self._create(fmt=fmt)
pl2 = plistlib.loads(TESTDATA[fmt], fmt=fmt)
self.assertEqual(dict(pl), dict(pl2),
"generated data was not identical to Apple's output")
pl2 = plistlib.loads(TESTDATA[fmt])
self.assertEqual(dict(pl), dict(pl2),
"generated data was not identical to Apple's output")
Expand All @@ -217,6 +220,8 @@ def test_bytesio(self):
b = BytesIO()
pl = self._create(fmt=fmt)
plistlib.dump(pl, b, fmt=fmt)
pl2 = plistlib.load(BytesIO(b.getvalue()), fmt=fmt)
self.assertEqual(dict(pl), dict(pl2))
pl2 = plistlib.load(BytesIO(b.getvalue()))
self.assertEqual(dict(pl), dict(pl2))

Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Core and Builtins
Library
-------

- Issue #21888: plistlib's load() and loads() now work if the fmt parameter is
specified.

- Issue #21044: tarfile.open() now handles fileobj with an integer 'name'
attribute. Based on patch by Antoine Pietri.

Expand Down

0 comments on commit 8966759

Please sign in to comment.