Mercurial > cpython-lru_cache-weakref
annotate Lib/imghdr.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | ead358ce4d8a |
| children |
| rev | line source |
|---|---|
|
11706
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
1 """Recognize image file formats based on their first few bytes.""" |
| 876 | 2 |
|
16198
32755b456369
a few more modules get __all__
Skip Montanaro <skip@pobox.com>
parents:
15868
diff
changeset
|
3 __all__ = ["what"] |
| 876 | 4 |
| 5 #-------------------------# | |
|
6450
77a22d49dd85
Allow open file as parameter (must be seekable) (Jack)
Guido van Rossum <guido@python.org>
parents:
5304
diff
changeset
|
6 # Recognize image headers # |
| 876 | 7 #-------------------------# |
| 8 | |
|
6450
77a22d49dd85
Allow open file as parameter (must be seekable) (Jack)
Guido van Rossum <guido@python.org>
parents:
5304
diff
changeset
|
9 def what(file, h=None): |
|
11706
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
10 if h is None: |
| 48055 | 11 if isinstance(file, basestring): |
|
11706
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
12 f = open(file, 'rb') |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
13 h = f.read(32) |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
14 else: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
15 location = file.tell() |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
16 h = file.read(32) |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
17 file.seek(location) |
|
15868
3060cbfa01be
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11706
diff
changeset
|
18 f = None |
|
11706
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
19 else: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
20 f = None |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
21 try: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
22 for tf in tests: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
23 res = tf(h, f) |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
24 if res: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
25 return res |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
26 finally: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
27 if f: f.close() |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
28 return None |
| 876 | 29 |
| 30 | |
| 31 #---------------------------------# | |
| 32 # Subroutines per image file type # | |
| 33 #---------------------------------# | |
| 34 | |
| 35 tests = [] | |
| 36 | |
|
48246
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
37 def test_jpeg(h, f): |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
38 """JPEG data in JFIF format""" |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
39 if h[6:10] == 'JFIF': |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
40 return 'jpeg' |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
41 |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
42 tests.append(test_jpeg) |
| 876 | 43 |
|
48246
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
44 def test_exif(h, f): |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
45 """JPEG data in Exif format""" |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
46 if h[6:10] == 'Exif': |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
47 return 'jpeg' |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
48 |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
49 tests.append(test_exif) |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
50 |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
51 def test_png(h, f): |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
52 if h[:8] == "\211PNG\r\n\032\n": |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
53 return 'png' |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
54 |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
55 tests.append(test_png) |
| 876 | 56 |
| 57 def test_gif(h, f): | |
|
11706
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
58 """GIF ('87 and '89 variants)""" |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
59 if h[:6] in ('GIF87a', 'GIF89a'): |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
60 return 'gif' |
| 876 | 61 |
| 62 tests.append(test_gif) | |
| 63 | |
|
48246
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
64 def test_tiff(h, f): |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
65 """TIFF (can be in Motorola or Intel byte order)""" |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
66 if h[:2] in ('MM', 'II'): |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
67 return 'tiff' |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
68 |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
69 tests.append(test_tiff) |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
70 |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
71 def test_rgb(h, f): |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
72 """SGI image library""" |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
73 if h[:2] == '\001\332': |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
74 return 'rgb' |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
75 |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
76 tests.append(test_rgb) |
|
ead358ce4d8a
#3424 rearrange the order of tests in imghdr to place more common types first
Benjamin Peterson <benjamin@python.org>
parents:
48055
diff
changeset
|
77 |
|
1078
245003c006a6
Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents:
880
diff
changeset
|
78 def test_pbm(h, f): |
|
11706
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
79 """PBM (portable bitmap)""" |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
80 if len(h) >= 3 and \ |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
81 h[0] == 'P' and h[1] in '14' and h[2] in ' \t\n\r': |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
82 return 'pbm' |
|
1078
245003c006a6
Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents:
880
diff
changeset
|
83 |
|
245003c006a6
Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents:
880
diff
changeset
|
84 tests.append(test_pbm) |
|
245003c006a6
Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents:
880
diff
changeset
|
85 |
|
245003c006a6
Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents:
880
diff
changeset
|
86 def test_pgm(h, f): |
|
11706
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
87 """PGM (portable graymap)""" |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
88 if len(h) >= 3 and \ |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
89 h[0] == 'P' and h[1] in '25' and h[2] in ' \t\n\r': |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
90 return 'pgm' |
|
1078
245003c006a6
Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents:
880
diff
changeset
|
91 |
|
245003c006a6
Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents:
880
diff
changeset
|
92 tests.append(test_pgm) |
| 876 | 93 |
|
1078
245003c006a6
Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents:
880
diff
changeset
|
94 def test_ppm(h, f): |
|
11706
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
95 """PPM (portable pixmap)""" |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
96 if len(h) >= 3 and \ |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
97 h[0] == 'P' and h[1] in '36' and h[2] in ' \t\n\r': |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
98 return 'ppm' |
|
1078
245003c006a6
Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents:
880
diff
changeset
|
99 |
|
245003c006a6
Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents:
880
diff
changeset
|
100 tests.append(test_ppm) |
| 876 | 101 |
| 102 def test_rast(h, f): | |
|
11706
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
103 """Sun raster file""" |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
104 if h[:4] == '\x59\xA6\x6A\x95': |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
105 return 'rast' |
| 876 | 106 |
| 107 tests.append(test_rast) | |
| 108 | |
|
880
36b934326fed
Fix pnm test for short files and add X bitmap as recognized type
Guido van Rossum <guido@python.org>
parents:
876
diff
changeset
|
109 def test_xbm(h, f): |
|
11706
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
110 """X bitmap (X10 or X11)""" |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
111 s = '#define ' |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
112 if h[:len(s)] == s: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
113 return 'xbm' |
|
880
36b934326fed
Fix pnm test for short files and add X bitmap as recognized type
Guido van Rossum <guido@python.org>
parents:
876
diff
changeset
|
114 |
|
36b934326fed
Fix pnm test for short files and add X bitmap as recognized type
Guido van Rossum <guido@python.org>
parents:
876
diff
changeset
|
115 tests.append(test_xbm) |
|
36b934326fed
Fix pnm test for short files and add X bitmap as recognized type
Guido van Rossum <guido@python.org>
parents:
876
diff
changeset
|
116 |
|
5304
4459172f40bb
(Jack:) Recognize PNG files.
Guido van Rossum <guido@python.org>
parents:
4108
diff
changeset
|
117 def test_bmp(h, f): |
|
11706
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
118 if h[:2] == 'BM': |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
119 return 'bmp' |
|
15868
3060cbfa01be
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11706
diff
changeset
|
120 |
|
5304
4459172f40bb
(Jack:) Recognize PNG files.
Guido van Rossum <guido@python.org>
parents:
4108
diff
changeset
|
121 tests.append(test_bmp) |
|
4459172f40bb
(Jack:) Recognize PNG files.
Guido van Rossum <guido@python.org>
parents:
4108
diff
changeset
|
122 |
| 876 | 123 #--------------------# |
| 124 # Small test program # | |
| 125 #--------------------# | |
| 126 | |
| 127 def test(): | |
|
11706
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
128 import sys |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
129 recursive = 0 |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
130 if sys.argv[1:] and sys.argv[1] == '-r': |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
131 del sys.argv[1:2] |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
132 recursive = 1 |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
133 try: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
134 if sys.argv[1:]: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
135 testall(sys.argv[1:], recursive, 1) |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
136 else: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
137 testall(['.'], recursive, 1) |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
138 except KeyboardInterrupt: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
139 sys.stderr.write('\n[Interrupted]\n') |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
140 sys.exit(1) |
| 876 | 141 |
| 142 def testall(list, recursive, toplevel): | |
|
11706
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
143 import sys |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
144 import os |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
145 for filename in list: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
146 if os.path.isdir(filename): |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
147 print filename + '/:', |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
148 if recursive or toplevel: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
149 print 'recursing down:' |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
150 import glob |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
151 names = glob.glob(os.path.join(filename, '*')) |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
152 testall(names, recursive, 0) |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
153 else: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
154 print '*** directory (use -r) ***' |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
155 else: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
156 print filename + ':', |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
157 sys.stdout.flush() |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
158 try: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
159 print what(filename) |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
160 except IOError: |
|
b6f52c1ef6da
More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents:
6450
diff
changeset
|
161 print '*** not found ***' |
