diff -r 52ab9e1ff46a Lib/imghdr.py --- a/Lib/imghdr.py Sun Feb 16 14:17:28 2014 -0500 +++ b/Lib/imghdr.py Sat Feb 22 11:19:20 2014 +0200 @@ -10,7 +10,7 @@ f = None try: if h is None: - if isinstance(file, str): + if isinstance(file, (str, bytes)): f = open(file, 'rb') h = f.read(32) else: diff -r 52ab9e1ff46a Lib/test/test_imghdr.py --- a/Lib/test/test_imghdr.py Sun Feb 16 14:17:28 2014 -0500 +++ b/Lib/test/test_imghdr.py Sat Feb 22 11:19:20 2014 +0200 @@ -72,8 +72,6 @@ imghdr.what(None) with self.assertRaises(TypeError): imghdr.what(self.testfile, 1) - with self.assertRaises(AttributeError): - imghdr.what(os.fsencode(self.testfile)) with open(self.testfile, 'rb') as f: with self.assertRaises(AttributeError): imghdr.what(f.fileno()) @@ -127,5 +125,11 @@ with self.assertRaises(OSError) as cm: imghdr.what(stream) + def test_bytes_file(self): + for filename, expected in TEST_FILES: + filename = findfile(filename, subdir="imghdrdata") + self.assertEqual(imghdr.what(os.fsencode(filename)), + expected) + if __name__ == '__main__': unittest.main()