Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Side by Side Diff: Lib/imghdr.py

Issue 28228: imghdr does not support pathlib
Patch Set: Created 3 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/test_imghdr.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Recognize image file formats based on their first few bytes.""" 1 """Recognize image file formats based on their first few bytes."""
2
3 from os import PathLike
2 4
3 __all__ = ["what"] 5 __all__ = ["what"]
4 6
5 #-------------------------# 7 #-------------------------#
6 # Recognize image headers # 8 # Recognize image headers #
7 #-------------------------# 9 #-------------------------#
8 10
9 def what(file, h=None): 11 def what(file, h=None):
10 f = None 12 f = None
11 try: 13 try:
12 if h is None: 14 if h is None:
13 if isinstance(file, str): 15 if isinstance(file, (str, PathLike)):
14 f = open(file, 'rb') 16 f = open(file, 'rb')
15 h = f.read(32) 17 h = f.read(32)
16 else: 18 else:
17 location = file.tell() 19 location = file.tell()
18 h = file.read(32) 20 h = file.read(32)
19 file.seek(location) 21 file.seek(location)
20 for tf in tests: 22 for tf in tests:
21 res = tf(h, f) 23 res = tf(h, f)
22 if res: 24 if res:
23 return res 25 return res
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 else: 159 else:
158 print(filename + ':', end=' ') 160 print(filename + ':', end=' ')
159 sys.stdout.flush() 161 sys.stdout.flush()
160 try: 162 try:
161 print(what(filename)) 163 print(what(filename))
162 except OSError: 164 except OSError:
163 print('*** not found ***') 165 print('*** not found ***')
164 166
165 if __name__ == '__main__': 167 if __name__ == '__main__':
166 test() 168 test()
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_imghdr.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+