~pythonregexp2.7/python/issue2636-11

« back to all changes in this revision

Viewing changes to Lib/imghdr.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-21 13:47:31 UTC
  • mfrom: (39021.1.404 Regexp-2.7)
  • mto: This revision was merged to the branch mainline in revision 39030.
  • Revision ID: darklord@timehorse.com-20080921134731-rudomuzeh1b2tz1y
Merged in changes from the latest python source snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
def what(file, h=None):
10
10
    if h is None:
11
 
        if type(file) == type(''):
 
11
        if isinstance(file, basestring):
12
12
            f = open(file, 'rb')
13
13
            h = f.read(32)
14
14
        else:
34
34
 
35
35
tests = []
36
36
 
 
37
def test_jpeg(h, f):
 
38
    """JPEG data in JFIF format"""
 
39
    if h[6:10] == 'JFIF':
 
40
        return 'jpeg'
 
41
 
 
42
tests.append(test_jpeg)
 
43
 
 
44
def test_exif(h, f):
 
45
    """JPEG data in Exif format"""
 
46
    if h[6:10] == 'Exif':
 
47
        return 'jpeg'
 
48
 
 
49
tests.append(test_exif)
 
50
 
 
51
def test_png(h, f):
 
52
    if h[:8] == "\211PNG\r\n\032\n":
 
53
        return 'png'
 
54
 
 
55
tests.append(test_png)
 
56
 
 
57
def test_gif(h, f):
 
58
    """GIF ('87 and '89 variants)"""
 
59
    if h[:6] in ('GIF87a', 'GIF89a'):
 
60
        return 'gif'
 
61
 
 
62
tests.append(test_gif)
 
63
 
 
64
def test_tiff(h, f):
 
65
    """TIFF (can be in Motorola or Intel byte order)"""
 
66
    if h[:2] in ('MM', 'II'):
 
67
        return 'tiff'
 
68
 
 
69
tests.append(test_tiff)
 
70
 
37
71
def test_rgb(h, f):
38
72
    """SGI image library"""
39
73
    if h[:2] == '\001\332':
41
75
 
42
76
tests.append(test_rgb)
43
77
 
44
 
def test_gif(h, f):
45
 
    """GIF ('87 and '89 variants)"""
46
 
    if h[:6] in ('GIF87a', 'GIF89a'):
47
 
        return 'gif'
48
 
 
49
 
tests.append(test_gif)
50
 
 
51
78
def test_pbm(h, f):
52
79
    """PBM (portable bitmap)"""
53
80
    if len(h) >= 3 and \
72
99
 
73
100
tests.append(test_ppm)
74
101
 
75
 
def test_tiff(h, f):
76
 
    """TIFF (can be in Motorola or Intel byte order)"""
77
 
    if h[:2] in ('MM', 'II'):
78
 
        return 'tiff'
79
 
 
80
 
tests.append(test_tiff)
81
 
 
82
102
def test_rast(h, f):
83
103
    """Sun raster file"""
84
104
    if h[:4] == '\x59\xA6\x6A\x95':
94
114
 
95
115
tests.append(test_xbm)
96
116
 
97
 
def test_jpeg(h, f):
98
 
    """JPEG data in JFIF format"""
99
 
    if h[6:10] == 'JFIF':
100
 
        return 'jpeg'
101
 
 
102
 
tests.append(test_jpeg)
103
 
 
104
 
def test_exif(h, f):
105
 
    """JPEG data in Exif format"""
106
 
    if h[6:10] == 'Exif':
107
 
        return 'jpeg'
108
 
 
109
 
tests.append(test_exif)
110
 
 
111
117
def test_bmp(h, f):
112
118
    if h[:2] == 'BM':
113
119
        return 'bmp'
114
120
 
115
121
tests.append(test_bmp)
116
122
 
117
 
def test_png(h, f):
118
 
    if h[:8] == "\211PNG\r\n\032\n":
119
 
        return 'png'
120
 
 
121
 
tests.append(test_png)
122
 
 
123
123
#--------------------#
124
124
# Small test program #
125
125
#--------------------#