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

Delta Between Two Patch Sets: Lib/imghdr.py

Issue 28228: imghdr does not support pathlib
Left Patch Set: Created 3 years, 4 months ago
Right Patch Set: Created 3 years, 4 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | Lib/test/test_imghdr.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """Recognize image file formats based on their first few bytes.""" 1 """Recognize image file formats based on their first few bytes."""
2 2
3 from os import PathLike
4
3 __all__ = ["what"] 5 __all__ = ["what"]
4
5 from os import PathLike
6 6
7 #-------------------------# 7 #-------------------------#
8 # Recognize image headers # 8 # Recognize image headers #
9 #-------------------------# 9 #-------------------------#
10 10
11 def what(file, h=None): 11 def what(file, h=None):
12 f = None 12 f = None
13 try: 13 try:
14 if h is None: 14 if h is None:
15 if isinstance(file, (str, PathLike)): 15 if isinstance(file, (str, PathLike)):
storchaka 2016/09/21 10:43:04 Or maybe use the test "not hasattr(file, 'read')".
16 f = open(file, 'rb') 16 f = open(file, 'rb')
17 h = f.read(32) 17 h = f.read(32)
18 else: 18 else:
19 location = file.tell() 19 location = file.tell()
20 h = file.read(32) 20 h = file.read(32)
21 file.seek(location) 21 file.seek(location)
22 for tf in tests: 22 for tf in tests:
23 res = tf(h, f) 23 res = tf(h, f)
24 if res: 24 if res:
25 return res 25 return res
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 else: 159 else:
160 print(filename + ':', end=' ') 160 print(filename + ':', end=' ')
161 sys.stdout.flush() 161 sys.stdout.flush()
162 try: 162 try:
163 print(what(filename)) 163 print(what(filename))
164 except OSError: 164 except OSError:
165 print('*** not found ***') 165 print('*** not found ***')
166 166
167 if __name__ == '__main__': 167 if __name__ == '__main__':
168 test() 168 test()
LEFTRIGHT

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