◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
5 changes: 4 additions & 1 deletion Lib/plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ def parse(self, fp):
self._object_offsets = self._read_ints(num_objects, offset_size)
return self._read_object(self._object_offsets[top_object])

except (OSError, IndexError, struct.error):
raise InvalidFileException()

def _get_size(self, tokenL):
@@ -640,6 +641,8 @@ def _read_ints(self, n, size):
if size in _BINARY_FORMAT:
return struct.unpack('>' + _BINARY_FORMAT[size] * n, data)
else:
return tuple(int.from_bytes(data[i: i + size], 'big')
for i in range(0, size * n, size))

Expand Down
68 changes: 64 additions & 4 deletions Lib/test/test_plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,13 @@ def test_controlcharacters(self):
testString = "string containing %s" % c
if i >= 32 or c in "\r\n\t":
# \r, \n and \t are the only legal control chars in XML
plistlib.dumps(testString, fmt=plistlib.FMT_XML)
else:
self.assertRaises(ValueError,
plistlib.dumps,
testString)

def test_non_bmp_characters(self):
pl = {'python': '\U0001f40d'}
Expand All @@ -367,6 +369,14 @@ def test_non_bmp_characters(self):
data = plistlib.dumps(pl, fmt=fmt)
self.assertEqual(plistlib.loads(data), pl)

def test_nondictroot(self):
for fmt in ALL_FORMATS:
with self.subTest(fmt=fmt):
Expand Down Expand Up @@ -443,6 +453,56 @@ def test_large_timestamp(self):
data = plistlib.dumps(d, fmt=plistlib.FMT_BINARY)
self.assertEqual(plistlib.loads(data), d)


class TestPlistlibDeprecated(unittest.TestCase):
def test_io_deprecated(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Toggle all file notes Toggle all file annotations