]> granicus.if.org Git - python/commitdiff
Issue #21888: plistlib's load() and loads() now work if the fmt parameter is
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 23 Jul 2014 15:49:31 +0000 (18:49 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 23 Jul 2014 15:49:31 +0000 (18:49 +0300)
specified.

Lib/plistlib.py
Lib/test/test_plistlib.py
Misc/NEWS

index 8c148a84363958b38f12378ea6f7dc98cd86f3fa..b9946fd313af0d67fddb74c1d0022f803f518ad6 100644 (file)
@@ -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)
 
 
index dc2fdf696d7e9d0015b753f47caf84ecf64357f1..fef9f3997237e1b5dd9275cefe028e9da7452161 100644 (file)
@@ -207,6 +207,9 @@ class TestPlistlib(unittest.TestCase):
         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")
@@ -217,6 +220,8 @@ class TestPlistlib(unittest.TestCase):
                 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))
 
index 2845d9f05dafbf86c9cd99a7acfbaabbae84a9d3..2dc905dcbe4cceec8112fffdaeb54556e5084d81 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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.