mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 21:50:54 +03:00
py3k: Update exception usage to modern syntax
This commit is contained in:
parent
37f22ebfcd
commit
78575798d7
|
@ -60,14 +60,14 @@ class ArgStream(ChunkStream):
|
||||||
|
|
||||||
# assertions
|
# assertions
|
||||||
if self.count != 0:
|
if self.count != 0:
|
||||||
raise SyntaxError, "misplaced AHDR chunk"
|
raise SyntaxError("misplaced AHDR chunk")
|
||||||
|
|
||||||
s = self.fp.read(bytes)
|
s = self.fp.read(bytes)
|
||||||
self.size = i32(s), i32(s[4:])
|
self.size = i32(s), i32(s[4:])
|
||||||
try:
|
try:
|
||||||
self.mode, self.rawmode = _MODES[(ord(s[8]), ord(s[9]))]
|
self.mode, self.rawmode = _MODES[(ord(s[8]), ord(s[9]))]
|
||||||
except:
|
except:
|
||||||
raise SyntaxError, "unknown ARG mode"
|
raise SyntaxError("unknown ARG mode")
|
||||||
|
|
||||||
if Image.DEBUG:
|
if Image.DEBUG:
|
||||||
print "AHDR size", self.size
|
print "AHDR size", self.size
|
||||||
|
@ -80,7 +80,7 @@ class ArgStream(ChunkStream):
|
||||||
|
|
||||||
# assertions
|
# assertions
|
||||||
if self.count != 0:
|
if self.count != 0:
|
||||||
raise SyntaxError, "misplaced AFRM chunk"
|
raise SyntaxError("misplaced AFRM chunk")
|
||||||
|
|
||||||
self.show = 1
|
self.show = 1
|
||||||
self.id = 0
|
self.id = 0
|
||||||
|
@ -107,7 +107,7 @@ class ArgStream(ChunkStream):
|
||||||
|
|
||||||
# assertions
|
# assertions
|
||||||
if self.count != 0:
|
if self.count != 0:
|
||||||
raise SyntaxError, "misplaced ADEF chunk"
|
raise SyntaxError("misplaced ADEF chunk")
|
||||||
|
|
||||||
self.show = 0
|
self.show = 0
|
||||||
self.id = 0
|
self.id = 0
|
||||||
|
@ -130,7 +130,7 @@ class ArgStream(ChunkStream):
|
||||||
|
|
||||||
# assertions
|
# assertions
|
||||||
if self.count == 0:
|
if self.count == 0:
|
||||||
raise SyntaxError, "misplaced NAME chunk"
|
raise SyntaxError("misplaced NAME chunk")
|
||||||
|
|
||||||
name = self.fp.read(bytes)
|
name = self.fp.read(bytes)
|
||||||
self.names[self.id] = name
|
self.names[self.id] = name
|
||||||
|
@ -145,7 +145,7 @@ class ArgStream(ChunkStream):
|
||||||
|
|
||||||
self.eof = 1
|
self.eof = 1
|
||||||
|
|
||||||
raise EOFError, "end of ARG file"
|
raise EOFError("end of ARG file")
|
||||||
|
|
||||||
def __getmodesize(self, s, full=1):
|
def __getmodesize(self, s, full=1):
|
||||||
|
|
||||||
|
@ -154,13 +154,13 @@ class ArgStream(ChunkStream):
|
||||||
try:
|
try:
|
||||||
mode, rawmode = _MODES[(ord(s[8]), ord(s[9]))]
|
mode, rawmode = _MODES[(ord(s[8]), ord(s[9]))]
|
||||||
except:
|
except:
|
||||||
raise SyntaxError, "unknown image mode"
|
raise SyntaxError("unknown image mode")
|
||||||
|
|
||||||
if full:
|
if full:
|
||||||
if ord(s[12]):
|
if ord(s[12]):
|
||||||
pass # interlace not yet supported
|
pass # interlace not yet supported
|
||||||
if ord(s[11]):
|
if ord(s[11]):
|
||||||
raise SyntaxError, "unknown filter category"
|
raise SyntaxError("unknown filter category")
|
||||||
|
|
||||||
return size, mode, rawmode
|
return size, mode, rawmode
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ class ArgStream(ChunkStream):
|
||||||
|
|
||||||
# assertions
|
# assertions
|
||||||
if self.count == 0:
|
if self.count == 0:
|
||||||
raise SyntaxError, "misplaced PAST chunk"
|
raise SyntaxError("misplaced PAST chunk")
|
||||||
|
|
||||||
if self.repair is not None:
|
if self.repair is not None:
|
||||||
# we must repair the target image before we
|
# we must repair the target image before we
|
||||||
|
@ -206,7 +206,7 @@ class ArgStream(ChunkStream):
|
||||||
|
|
||||||
# assertions
|
# assertions
|
||||||
if self.count == 0:
|
if self.count == 0:
|
||||||
raise SyntaxError, "misplaced BLNK chunk"
|
raise SyntaxError("misplaced BLNK chunk")
|
||||||
|
|
||||||
s = self.fp.read(bytes)
|
s = self.fp.read(bytes)
|
||||||
size, mode, rawmode = self.__getmodesize(s, 0)
|
size, mode, rawmode = self.__getmodesize(s, 0)
|
||||||
|
@ -223,7 +223,7 @@ class ArgStream(ChunkStream):
|
||||||
|
|
||||||
# assertions
|
# assertions
|
||||||
if self.count == 0:
|
if self.count == 0:
|
||||||
raise SyntaxError, "misplaced IHDR chunk"
|
raise SyntaxError("misplaced IHDR chunk")
|
||||||
|
|
||||||
# image header
|
# image header
|
||||||
s = self.fp.read(bytes)
|
s = self.fp.read(bytes)
|
||||||
|
@ -243,7 +243,7 @@ class ArgStream(ChunkStream):
|
||||||
|
|
||||||
# assertions
|
# assertions
|
||||||
if self.count == 0:
|
if self.count == 0:
|
||||||
raise SyntaxError, "misplaced DHDR chunk"
|
raise SyntaxError("misplaced DHDR chunk")
|
||||||
|
|
||||||
s = self.fp.read(bytes)
|
s = self.fp.read(bytes)
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ class ArgStream(ChunkStream):
|
||||||
|
|
||||||
# assertions
|
# assertions
|
||||||
if self.count == 0:
|
if self.count == 0:
|
||||||
raise SyntaxError, "misplaced JHDR chunk"
|
raise SyntaxError("misplaced JHDR chunk")
|
||||||
|
|
||||||
# image header
|
# image header
|
||||||
s = self.fp.read(bytes)
|
s = self.fp.read(bytes)
|
||||||
|
@ -296,7 +296,7 @@ class ArgStream(ChunkStream):
|
||||||
|
|
||||||
# assertions
|
# assertions
|
||||||
if self.count == 0:
|
if self.count == 0:
|
||||||
raise SyntaxError, "misplaced UHDR chunk"
|
raise SyntaxError("misplaced UHDR chunk")
|
||||||
|
|
||||||
# image header
|
# image header
|
||||||
s = self.fp.read(bytes)
|
s = self.fp.read(bytes)
|
||||||
|
@ -321,7 +321,7 @@ class ArgStream(ChunkStream):
|
||||||
if n < 0:
|
if n < 0:
|
||||||
# end of image
|
# end of image
|
||||||
if e < 0:
|
if e < 0:
|
||||||
raise IOError, "decoder error %d" % e
|
raise IOError("decoder error %d" % e)
|
||||||
else:
|
else:
|
||||||
self.data = self.data[n:]
|
self.data = self.data[n:]
|
||||||
|
|
||||||
|
@ -386,7 +386,7 @@ class ArgStream(ChunkStream):
|
||||||
"SYNC -- reset decoder"
|
"SYNC -- reset decoder"
|
||||||
|
|
||||||
if self.count != 0:
|
if self.count != 0:
|
||||||
raise SyntaxError, "misplaced sYNC chunk"
|
raise SyntaxError("misplaced sYNC chunk")
|
||||||
|
|
||||||
s = self.fp.read(bytes)
|
s = self.fp.read(bytes)
|
||||||
self.__reset()
|
self.__reset()
|
||||||
|
@ -418,7 +418,7 @@ class ArgImageFile(ImageFile.ImageFile):
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.fp.read(8) != MAGIC:
|
if self.fp.read(8) != MAGIC:
|
||||||
raise SyntaxError, "not an ARG file"
|
raise SyntaxError("not an ARG file")
|
||||||
|
|
||||||
self.arg = ArgStream(self.fp)
|
self.arg = ArgStream(self.fp)
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ class ArgImageFile(ImageFile.ImageFile):
|
||||||
cid, offset, bytes = self.arg.read()
|
cid, offset, bytes = self.arg.read()
|
||||||
|
|
||||||
if cid != "AHDR":
|
if cid != "AHDR":
|
||||||
raise SyntaxError, "expected an AHDR chunk"
|
raise SyntaxError("expected an AHDR chunk")
|
||||||
|
|
||||||
s = self.arg.call(cid, offset, bytes)
|
s = self.arg.call(cid, offset, bytes)
|
||||||
|
|
||||||
|
@ -452,7 +452,7 @@ class ArgImageFile(ImageFile.ImageFile):
|
||||||
def seek(self, frame):
|
def seek(self, frame):
|
||||||
|
|
||||||
if self.arg.eof:
|
if self.arg.eof:
|
||||||
raise EOFError, "end of animation"
|
raise EOFError("end of animation")
|
||||||
|
|
||||||
self.fp = self.arg.fp
|
self.fp = self.arg.fp
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ class ArgImageFile(ImageFile.ImageFile):
|
||||||
cid, offset, bytes = self.arg.read()
|
cid, offset, bytes = self.arg.read()
|
||||||
|
|
||||||
if self.arg.eof:
|
if self.arg.eof:
|
||||||
raise EOFError, "end of animation"
|
raise EOFError("end of animation")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
s = self.arg.call(cid, offset, bytes)
|
s = self.arg.call(cid, offset, bytes)
|
||||||
|
|
|
@ -93,7 +93,7 @@ class BdfFontFile(FontFile.FontFile):
|
||||||
|
|
||||||
s = fp.readline()
|
s = fp.readline()
|
||||||
if s[:13] != "STARTFONT 2.1":
|
if s[:13] != "STARTFONT 2.1":
|
||||||
raise SyntaxError, "not a valid BDF file"
|
raise SyntaxError("not a valid BDF file")
|
||||||
|
|
||||||
props = {}
|
props = {}
|
||||||
comments = []
|
comments = []
|
||||||
|
|
|
@ -50,7 +50,7 @@ class CurImageFile(BmpImagePlugin.BmpImageFile):
|
||||||
# check magic
|
# check magic
|
||||||
s = self.fp.read(6)
|
s = self.fp.read(6)
|
||||||
if not _accept(s):
|
if not _accept(s):
|
||||||
raise SyntaxError, "not an CUR file"
|
raise SyntaxError("not an CUR file")
|
||||||
|
|
||||||
# pick the largest cursor in the file
|
# pick the largest cursor in the file
|
||||||
m = ""
|
m = ""
|
||||||
|
|
|
@ -48,7 +48,7 @@ class DcxImageFile(PcxImageFile):
|
||||||
# Header
|
# Header
|
||||||
s = self.fp.read(4)
|
s = self.fp.read(4)
|
||||||
if i32(s) != MAGIC:
|
if i32(s) != MAGIC:
|
||||||
raise SyntaxError, "not a DCX file"
|
raise SyntaxError("not a DCX file")
|
||||||
|
|
||||||
# Component directory
|
# Component directory
|
||||||
self._offset = []
|
self._offset = []
|
||||||
|
|
|
@ -146,7 +146,7 @@ class EpsImageFile(ImageFile.ImageFile):
|
||||||
length = i32(s[8:])
|
length = i32(s[8:])
|
||||||
fp.seek(offset)
|
fp.seek(offset)
|
||||||
else:
|
else:
|
||||||
raise SyntaxError, "not an EPS file"
|
raise SyntaxError("not an EPS file")
|
||||||
|
|
||||||
fp.seek(offset)
|
fp.seek(offset)
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ class EpsImageFile(ImageFile.ImageFile):
|
||||||
while s:
|
while s:
|
||||||
|
|
||||||
if len(s) > 255:
|
if len(s) > 255:
|
||||||
raise SyntaxError, "not an EPS file"
|
raise SyntaxError("not an EPS file")
|
||||||
|
|
||||||
if s[-2:] == '\r\n':
|
if s[-2:] == '\r\n':
|
||||||
s = s[:-2]
|
s = s[:-2]
|
||||||
|
@ -172,8 +172,8 @@ class EpsImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
m = split.match(s)
|
m = split.match(s)
|
||||||
except re.error, v:
|
except re.error as v:
|
||||||
raise SyntaxError, "not an EPS file"
|
raise SyntaxError("not an EPS file")
|
||||||
|
|
||||||
if m:
|
if m:
|
||||||
k, v = m.group(1, 2)
|
k, v = m.group(1, 2)
|
||||||
|
@ -207,7 +207,7 @@ class EpsImageFile(ImageFile.ImageFile):
|
||||||
# tools mistakenly put in the Comments section
|
# tools mistakenly put in the Comments section
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise IOError, "bad EPS header"
|
raise IOError("bad EPS header")
|
||||||
|
|
||||||
s = fp.readline()
|
s = fp.readline()
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ class EpsImageFile(ImageFile.ImageFile):
|
||||||
while s[0] == "%":
|
while s[0] == "%":
|
||||||
|
|
||||||
if len(s) > 255:
|
if len(s) > 255:
|
||||||
raise SyntaxError, "not an EPS file"
|
raise SyntaxError("not an EPS file")
|
||||||
|
|
||||||
if s[-2:] == '\r\n':
|
if s[-2:] == '\r\n':
|
||||||
s = s[:-2]
|
s = s[:-2]
|
||||||
|
@ -278,7 +278,7 @@ class EpsImageFile(ImageFile.ImageFile):
|
||||||
break
|
break
|
||||||
|
|
||||||
if not box:
|
if not box:
|
||||||
raise IOError, "cannot determine EPS bounding box"
|
raise IOError("cannot determine EPS bounding box")
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
# Load EPS via Ghostscript
|
# Load EPS via Ghostscript
|
||||||
|
@ -308,7 +308,7 @@ def _save(im, fp, filename, eps=1):
|
||||||
elif im.mode == "CMYK":
|
elif im.mode == "CMYK":
|
||||||
operator = (8, 4, "false 4 colorimage")
|
operator = (8, 4, "false 4 colorimage")
|
||||||
else:
|
else:
|
||||||
raise ValueError, "image mode is not supported"
|
raise ValueError("image mode is not supported")
|
||||||
|
|
||||||
if eps:
|
if eps:
|
||||||
#
|
#
|
||||||
|
|
|
@ -50,7 +50,7 @@ class FliImageFile(ImageFile.ImageFile):
|
||||||
if not (magic in [0xAF11, 0xAF12] and
|
if not (magic in [0xAF11, 0xAF12] and
|
||||||
i16(s[14:16]) in [0, 3] and # flags
|
i16(s[14:16]) in [0, 3] and # flags
|
||||||
s[20:22] == '\x00\x00'): # reserved
|
s[20:22] == '\x00\x00'): # reserved
|
||||||
raise SyntaxError, "not an FLI/FLC file"
|
raise SyntaxError("not an FLI/FLC file")
|
||||||
|
|
||||||
# image characteristics
|
# image characteristics
|
||||||
self.mode = "P"
|
self.mode = "P"
|
||||||
|
@ -112,7 +112,7 @@ class FliImageFile(ImageFile.ImageFile):
|
||||||
def seek(self, frame):
|
def seek(self, frame):
|
||||||
|
|
||||||
if frame != self.frame + 1:
|
if frame != self.frame + 1:
|
||||||
raise ValueError, "cannot seek to frame %d" % frame
|
raise ValueError("cannot seek to frame %d" % frame)
|
||||||
self.frame = frame
|
self.frame = frame
|
||||||
|
|
||||||
# move to next frame
|
# move to next frame
|
||||||
|
|
|
@ -60,10 +60,10 @@ class FpxImageFile(ImageFile.ImageFile):
|
||||||
try:
|
try:
|
||||||
self.ole = OleFileIO(self.fp)
|
self.ole = OleFileIO(self.fp)
|
||||||
except IOError:
|
except IOError:
|
||||||
raise SyntaxError, "not an FPX file; invalid OLE file"
|
raise SyntaxError("not an FPX file; invalid OLE file")
|
||||||
|
|
||||||
if self.ole.root.clsid != "56616700-C154-11CE-8553-00AA00A1F95B":
|
if self.ole.root.clsid != "56616700-C154-11CE-8553-00AA00A1F95B":
|
||||||
raise SyntaxError, "not an FPX file; bad root CLSID"
|
raise SyntaxError("not an FPX file; bad root CLSID")
|
||||||
|
|
||||||
self._open_index(1)
|
self._open_index(1)
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ class FpxImageFile(ImageFile.ImageFile):
|
||||||
# print size, self.mode, self.rawmode
|
# print size, self.mode, self.rawmode
|
||||||
|
|
||||||
if size != self.size:
|
if size != self.size:
|
||||||
raise IOError, "subimage mismatch"
|
raise IOError("subimage mismatch")
|
||||||
|
|
||||||
# get tile descriptors
|
# get tile descriptors
|
||||||
fp.seek(28 + offset)
|
fp.seek(28 + offset)
|
||||||
|
@ -198,7 +198,7 @@ class FpxImageFile(ImageFile.ImageFile):
|
||||||
self.tile_prefix = self.jpeg[jpeg_tables]
|
self.tile_prefix = self.jpeg[jpeg_tables]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise IOError, "unknown/invalid compression"
|
raise IOError("unknown/invalid compression")
|
||||||
|
|
||||||
x = x + xtile
|
x = x + xtile
|
||||||
if x >= xsize:
|
if x >= xsize:
|
||||||
|
|
|
@ -34,13 +34,13 @@ class GbrImageFile(ImageFile.ImageFile):
|
||||||
header_size = i32(self.fp.read(4))
|
header_size = i32(self.fp.read(4))
|
||||||
version = i32(self.fp.read(4))
|
version = i32(self.fp.read(4))
|
||||||
if header_size < 20 or version != 1:
|
if header_size < 20 or version != 1:
|
||||||
raise SyntaxError, "not a GIMP brush"
|
raise SyntaxError("not a GIMP brush")
|
||||||
|
|
||||||
width = i32(self.fp.read(4))
|
width = i32(self.fp.read(4))
|
||||||
height = i32(self.fp.read(4))
|
height = i32(self.fp.read(4))
|
||||||
bytes = i32(self.fp.read(4))
|
bytes = i32(self.fp.read(4))
|
||||||
if width <= 0 or height <= 0 or bytes != 1:
|
if width <= 0 or height <= 0 or bytes != 1:
|
||||||
raise SyntaxError, "not a GIMP brush"
|
raise SyntaxError("not a GIMP brush")
|
||||||
|
|
||||||
comment = self.fp.read(header_size - 20)[:-1]
|
comment = self.fp.read(header_size - 20)[:-1]
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
# Screen
|
# Screen
|
||||||
s = self.fp.read(13)
|
s = self.fp.read(13)
|
||||||
if s[:6] not in ["GIF87a", "GIF89a"]:
|
if s[:6] not in ["GIF87a", "GIF89a"]:
|
||||||
raise SyntaxError, "not a GIF file"
|
raise SyntaxError("not a GIF file")
|
||||||
|
|
||||||
self.info["version"] = s[:6]
|
self.info["version"] = s[:6]
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
self.__fp.seek(self.__rewind)
|
self.__fp.seek(self.__rewind)
|
||||||
|
|
||||||
if frame != self.__frame + 1:
|
if frame != self.__frame + 1:
|
||||||
raise ValueError, "cannot seek to frame %d" % frame
|
raise ValueError("cannot seek to frame %d" % frame)
|
||||||
self.__frame = frame
|
self.__frame = frame
|
||||||
|
|
||||||
self.tile = []
|
self.tile = []
|
||||||
|
@ -201,7 +201,7 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
if not self.tile:
|
if not self.tile:
|
||||||
# self.__fp = None
|
# self.__fp = None
|
||||||
raise EOFError, "no more images in GIF file"
|
raise EOFError("no more images in GIF file")
|
||||||
|
|
||||||
self.mode = "L"
|
self.mode = "L"
|
||||||
if self.palette:
|
if self.palette:
|
||||||
|
|
|
@ -96,7 +96,7 @@ class GimpGradientFile(GradientFile):
|
||||||
def __init__(self, fp):
|
def __init__(self, fp):
|
||||||
|
|
||||||
if fp.readline()[:13] != "GIMP Gradient":
|
if fp.readline()[:13] != "GIMP Gradient":
|
||||||
raise SyntaxError, "not a GIMP gradient file"
|
raise SyntaxError("not a GIMP gradient file")
|
||||||
|
|
||||||
count = int(fp.readline())
|
count = int(fp.readline())
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ class GimpGradientFile(GradientFile):
|
||||||
cspace = int(s[12])
|
cspace = int(s[12])
|
||||||
|
|
||||||
if cspace != 0:
|
if cspace != 0:
|
||||||
raise IOError, "cannot handle HSV colour space"
|
raise IOError("cannot handle HSV colour space")
|
||||||
|
|
||||||
gradient.append((x0, x1, xm, rgb0, rgb1, segment))
|
gradient.append((x0, x1, xm, rgb0, rgb1, segment))
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class GimpPaletteFile:
|
||||||
self.palette = map(lambda i: chr(i)*3, range(256))
|
self.palette = map(lambda i: chr(i)*3, range(256))
|
||||||
|
|
||||||
if fp.readline()[:12] != "GIMP Palette":
|
if fp.readline()[:12] != "GIMP Palette":
|
||||||
raise SyntaxError, "not a GIMP palette file"
|
raise SyntaxError("not a GIMP palette file")
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
|
@ -42,11 +42,11 @@ class GimpPaletteFile:
|
||||||
if re.match("\w+:|#", s):
|
if re.match("\w+:|#", s):
|
||||||
continue
|
continue
|
||||||
if len(s) > 100:
|
if len(s) > 100:
|
||||||
raise SyntaxError, "bad palette file"
|
raise SyntaxError("bad palette file")
|
||||||
|
|
||||||
v = tuple(map(int, s.split()[:3]))
|
v = tuple(map(int, s.split()[:3]))
|
||||||
if len(v) != 3:
|
if len(v) != 3:
|
||||||
raise ValueError, "bad palette entry"
|
raise ValueError("bad palette entry")
|
||||||
|
|
||||||
if 0 <= i <= 255:
|
if 0 <= i <= 255:
|
||||||
self.palette[i] = chr(v[0]) + chr(v[1]) + chr(v[2])
|
self.palette[i] = chr(v[0]) + chr(v[1]) + chr(v[2])
|
||||||
|
|
|
@ -27,7 +27,7 @@ def read_32t(fobj, (start, length), (width, height)):
|
||||||
fobj.seek(start)
|
fobj.seek(start)
|
||||||
sig = fobj.read(4)
|
sig = fobj.read(4)
|
||||||
if sig != '\x00\x00\x00\x00':
|
if sig != '\x00\x00\x00\x00':
|
||||||
raise SyntaxError, 'Unknown signature, expecting 0x00000000'
|
raise SyntaxError('Unknown signature, expecting 0x00000000')
|
||||||
return read_32(fobj, (start + 4, length - 4), (width, height))
|
return read_32(fobj, (start + 4, length - 4), (width, height))
|
||||||
|
|
||||||
def read_32(fobj, (start, length), size):
|
def read_32(fobj, (start, length), size):
|
||||||
|
@ -111,7 +111,7 @@ class IcnsFile:
|
||||||
self.fobj = fobj
|
self.fobj = fobj
|
||||||
sig, filesize = nextheader(fobj)
|
sig, filesize = nextheader(fobj)
|
||||||
if sig != 'icns':
|
if sig != 'icns':
|
||||||
raise SyntaxError, 'not an icns file'
|
raise SyntaxError('not an icns file')
|
||||||
i = HEADERSIZE
|
i = HEADERSIZE
|
||||||
while i < filesize:
|
while i < filesize:
|
||||||
sig, blocksize = nextheader(fobj)
|
sig, blocksize = nextheader(fobj)
|
||||||
|
@ -133,7 +133,7 @@ class IcnsFile:
|
||||||
def bestsize(self):
|
def bestsize(self):
|
||||||
sizes = self.itersizes()
|
sizes = self.itersizes()
|
||||||
if not sizes:
|
if not sizes:
|
||||||
raise SyntaxError, "No 32bit icon resources found"
|
raise SyntaxError("No 32bit icon resources found")
|
||||||
return max(sizes)
|
return max(sizes)
|
||||||
|
|
||||||
def dataforsize(self, size):
|
def dataforsize(self, size):
|
||||||
|
|
|
@ -48,7 +48,7 @@ class IcoImageFile(BmpImagePlugin.BmpImageFile):
|
||||||
# check magic
|
# check magic
|
||||||
s = self.fp.read(6)
|
s = self.fp.read(6)
|
||||||
if not _accept(s):
|
if not _accept(s):
|
||||||
raise SyntaxError, "not an ICO file"
|
raise SyntaxError("not an ICO file")
|
||||||
|
|
||||||
# pick the largest icon in the file
|
# pick the largest icon in the file
|
||||||
m = ""
|
m = ""
|
||||||
|
|
|
@ -113,7 +113,7 @@ class ImImageFile(ImageFile.ImageFile):
|
||||||
# 100 bytes, this is (probably) not a text header.
|
# 100 bytes, this is (probably) not a text header.
|
||||||
|
|
||||||
if not "\n" in self.fp.read(100):
|
if not "\n" in self.fp.read(100):
|
||||||
raise SyntaxError, "not an IM file"
|
raise SyntaxError("not an IM file")
|
||||||
self.fp.seek(0)
|
self.fp.seek(0)
|
||||||
|
|
||||||
n = 0
|
n = 0
|
||||||
|
@ -140,7 +140,7 @@ class ImImageFile(ImageFile.ImageFile):
|
||||||
s = s + self.fp.readline()
|
s = s + self.fp.readline()
|
||||||
|
|
||||||
if len(s) > 100:
|
if len(s) > 100:
|
||||||
raise SyntaxError, "not an IM file"
|
raise SyntaxError("not an IM file")
|
||||||
|
|
||||||
if s[-2:] == '\r\n':
|
if s[-2:] == '\r\n':
|
||||||
s = s[:-2]
|
s = s[:-2]
|
||||||
|
@ -149,8 +149,8 @@ class ImImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
m = split.match(s)
|
m = split.match(s)
|
||||||
except re.error, v:
|
except re.error as v:
|
||||||
raise SyntaxError, "not an IM file"
|
raise SyntaxError("not an IM file")
|
||||||
|
|
||||||
if m:
|
if m:
|
||||||
|
|
||||||
|
@ -180,10 +180,10 @@ class ImImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
raise SyntaxError, "Syntax error in IM header: " + s
|
raise SyntaxError("Syntax error in IM header: " + s)
|
||||||
|
|
||||||
if not n:
|
if not n:
|
||||||
raise SyntaxError, "Not an IM file"
|
raise SyntaxError("Not an IM file")
|
||||||
|
|
||||||
# Basic attributes
|
# Basic attributes
|
||||||
self.size = self.info[SIZE]
|
self.size = self.info[SIZE]
|
||||||
|
@ -193,7 +193,7 @@ class ImImageFile(ImageFile.ImageFile):
|
||||||
while s and s[0] != chr(26):
|
while s and s[0] != chr(26):
|
||||||
s = self.fp.read(1)
|
s = self.fp.read(1)
|
||||||
if not s:
|
if not s:
|
||||||
raise SyntaxError, "File truncated"
|
raise SyntaxError("File truncated")
|
||||||
|
|
||||||
if self.info.has_key(LUT):
|
if self.info.has_key(LUT):
|
||||||
# convert lookup table to palette or lut attribute
|
# convert lookup table to palette or lut attribute
|
||||||
|
@ -253,7 +253,7 @@ class ImImageFile(ImageFile.ImageFile):
|
||||||
def seek(self, frame):
|
def seek(self, frame):
|
||||||
|
|
||||||
if frame < 0 or frame >= self.info[FRAMES]:
|
if frame < 0 or frame >= self.info[FRAMES]:
|
||||||
raise EOFError, "seek outside sequence"
|
raise EOFError("seek outside sequence")
|
||||||
|
|
||||||
if self.frame == frame:
|
if self.frame == frame:
|
||||||
return
|
return
|
||||||
|
@ -304,7 +304,7 @@ def _save(im, fp, filename, check=0):
|
||||||
try:
|
try:
|
||||||
type, rawmode = SAVE[im.mode]
|
type, rawmode = SAVE[im.mode]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ValueError, "Cannot save %s images as IM" % im.mode
|
raise ValueError("Cannot save %s images as IM" % im.mode)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
frames = im.encoderinfo["frames"]
|
frames = im.encoderinfo["frames"]
|
||||||
|
|
|
@ -52,7 +52,7 @@ try:
|
||||||
# them. Note that other modules should not refer to _imaging
|
# them. Note that other modules should not refer to _imaging
|
||||||
# directly; import Image and use the Image.core variable instead.
|
# directly; import Image and use the Image.core variable instead.
|
||||||
import _imaging as core
|
import _imaging as core
|
||||||
except ImportError, v:
|
except ImportError as v:
|
||||||
core = _imaging_not_installed()
|
core = _imaging_not_installed()
|
||||||
if str(v)[:20] == "Module use of python" and warnings:
|
if str(v)[:20] == "Module use of python" and warnings:
|
||||||
# The _imaging C module is present, but not compiled for
|
# The _imaging C module is present, but not compiled for
|
||||||
|
@ -356,7 +356,7 @@ def init():
|
||||||
except ImportError:
|
except ImportError:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print "Image: failed to import",
|
print "Image: failed to import",
|
||||||
print f, ":", sys.exc_value
|
print f, ":", sys.exc_info()[1]
|
||||||
visited[fullpath] = None
|
visited[fullpath] = None
|
||||||
|
|
||||||
if OPEN or SAVE:
|
if OPEN or SAVE:
|
||||||
|
|
|
@ -307,7 +307,7 @@ def profileToProfile(im, inputProfile, outputProfile, renderingIntent=INTENT_PER
|
||||||
imOut = None
|
imOut = None
|
||||||
else:
|
else:
|
||||||
imOut = transform.apply(im)
|
imOut = transform.apply(im)
|
||||||
except (IOError, TypeError, ValueError), v:
|
except (IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
return imOut
|
return imOut
|
||||||
|
@ -334,7 +334,7 @@ def getOpenProfile(profileFilename):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return ImageCmsProfile(profileFilename)
|
return ImageCmsProfile(profileFilename)
|
||||||
except (IOError, TypeError, ValueError), v:
|
except (IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -408,7 +408,7 @@ def buildTransform(inputProfile, outputProfile, inMode, outMode, renderingIntent
|
||||||
if not isinstance(outputProfile, ImageCmsProfile):
|
if not isinstance(outputProfile, ImageCmsProfile):
|
||||||
outputProfile = ImageCmsProfile(outputProfile)
|
outputProfile = ImageCmsProfile(outputProfile)
|
||||||
return ImageCmsTransform(inputProfile, outputProfile, inMode, outMode, renderingIntent, flags=flags)
|
return ImageCmsTransform(inputProfile, outputProfile, inMode, outMode, renderingIntent, flags=flags)
|
||||||
except (IOError, TypeError, ValueError), v:
|
except (IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -501,7 +501,7 @@ def buildProofTransform(inputProfile, outputProfile, proofProfile, inMode, outMo
|
||||||
if not isinstance(proofProfile, ImageCmsProfile):
|
if not isinstance(proofProfile, ImageCmsProfile):
|
||||||
proofProfile = ImageCmsProfile(proofProfile)
|
proofProfile = ImageCmsProfile(proofProfile)
|
||||||
return ImageCmsTransform(inputProfile, outputProfile, inMode, outMode, renderingIntent, proofProfile, proofRenderingIntent, flags)
|
return ImageCmsTransform(inputProfile, outputProfile, inMode, outMode, renderingIntent, proofProfile, proofRenderingIntent, flags)
|
||||||
except (IOError, TypeError, ValueError), v:
|
except (IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
buildTransformFromOpenProfiles = buildTransform
|
buildTransformFromOpenProfiles = buildTransform
|
||||||
|
@ -557,7 +557,7 @@ def applyTransform(im, transform, inPlace=0):
|
||||||
imOut = None
|
imOut = None
|
||||||
else:
|
else:
|
||||||
imOut = transform.apply(im)
|
imOut = transform.apply(im)
|
||||||
except (TypeError, ValueError), v:
|
except (TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
return imOut
|
return imOut
|
||||||
|
@ -602,7 +602,7 @@ def createProfile(colorSpace, colorTemp=-1):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return core.createProfile(colorSpace, colorTemp)
|
return core.createProfile(colorSpace, colorTemp)
|
||||||
except (TypeError, ValueError), v:
|
except (TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -633,7 +633,7 @@ def getProfileName(profile):
|
||||||
if not isinstance(profile, ImageCmsProfile):
|
if not isinstance(profile, ImageCmsProfile):
|
||||||
profile = ImageCmsProfile(profile)
|
profile = ImageCmsProfile(profile)
|
||||||
return profile.profile.product_name + "\n"
|
return profile.profile.product_name + "\n"
|
||||||
except (AttributeError, IOError, TypeError, ValueError), v:
|
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -665,7 +665,7 @@ def getProfileInfo(profile):
|
||||||
profile = ImageCmsProfile(profile)
|
profile = ImageCmsProfile(profile)
|
||||||
# add an extra newline to preserve pyCMS compatibility
|
# add an extra newline to preserve pyCMS compatibility
|
||||||
return profile.product_info + "\n"
|
return profile.product_info + "\n"
|
||||||
except (AttributeError, IOError, TypeError, ValueError), v:
|
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -703,7 +703,7 @@ def getDefaultIntent(profile):
|
||||||
if not isinstance(profile, ImageCmsProfile):
|
if not isinstance(profile, ImageCmsProfile):
|
||||||
profile = ImageCmsProfile(profile)
|
profile = ImageCmsProfile(profile)
|
||||||
return profile.profile.rendering_intent
|
return profile.profile.rendering_intent
|
||||||
except (AttributeError, IOError, TypeError, ValueError), v:
|
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -752,7 +752,7 @@ def isIntentSupported(profile, intent, direction):
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
except (AttributeError, IOError, TypeError, ValueError), v:
|
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||||
raise PyCMSError(v)
|
raise PyCMSError(v)
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
@ -89,25 +89,25 @@ class ImageFile(Image.Image):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._open()
|
self._open()
|
||||||
except IndexError, v: # end of data
|
except IndexError as v: # end of data
|
||||||
if Image.DEBUG > 1:
|
if Image.DEBUG > 1:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise SyntaxError, v
|
raise SyntaxError(v)
|
||||||
except TypeError, v: # end of data (ord)
|
except TypeError as v: # end of data (ord)
|
||||||
if Image.DEBUG > 1:
|
if Image.DEBUG > 1:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise SyntaxError, v
|
raise SyntaxError(v)
|
||||||
except KeyError, v: # unsupported mode
|
except KeyError as v: # unsupported mode
|
||||||
if Image.DEBUG > 1:
|
if Image.DEBUG > 1:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise SyntaxError, v
|
raise SyntaxError(v)
|
||||||
except EOFError, v: # got header but not the first frame
|
except EOFError as v: # got header but not the first frame
|
||||||
if Image.DEBUG > 1:
|
if Image.DEBUG > 1:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise SyntaxError, v
|
raise SyntaxError(v)
|
||||||
|
|
||||||
if not self.mode or self.size[0] <= 0:
|
if not self.mode or self.size[0] <= 0:
|
||||||
raise SyntaxError, "not identified by this driver"
|
raise SyntaxError("not identified by this driver")
|
||||||
|
|
||||||
def draft(self, mode, size):
|
def draft(self, mode, size):
|
||||||
"Set draft mode"
|
"Set draft mode"
|
||||||
|
|
|
@ -38,7 +38,7 @@ class _Operand:
|
||||||
elif im1.im.mode in ("I", "F"):
|
elif im1.im.mode in ("I", "F"):
|
||||||
return im1.im
|
return im1.im
|
||||||
else:
|
else:
|
||||||
raise ValueError, "unsupported mode: %s" % im1.im.mode
|
raise ValueError("unsupported mode: %s" % im1.im.mode)
|
||||||
else:
|
else:
|
||||||
# argument was a constant
|
# argument was a constant
|
||||||
if _isconstant(im1) and self.im.mode in ("1", "L", "I"):
|
if _isconstant(im1) and self.im.mode in ("1", "L", "I"):
|
||||||
|
@ -55,7 +55,7 @@ class _Operand:
|
||||||
try:
|
try:
|
||||||
op = getattr(_imagingmath, op+"_"+im1.mode)
|
op = getattr(_imagingmath, op+"_"+im1.mode)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise TypeError, "bad operand type for '%s'" % op
|
raise TypeError("bad operand type for '%s'" % op)
|
||||||
_imagingmath.unop(op, out.im.id, im1.im.id)
|
_imagingmath.unop(op, out.im.id, im1.im.id)
|
||||||
else:
|
else:
|
||||||
# binary operation
|
# binary operation
|
||||||
|
@ -65,7 +65,7 @@ class _Operand:
|
||||||
if im1.mode != "F": im1 = im1.convert("F")
|
if im1.mode != "F": im1 = im1.convert("F")
|
||||||
if im2.mode != "F": im2 = im2.convert("F")
|
if im2.mode != "F": im2 = im2.convert("F")
|
||||||
if im1.mode != im2.mode:
|
if im1.mode != im2.mode:
|
||||||
raise ValueError, "mode mismatch"
|
raise ValueError("mode mismatch")
|
||||||
if im1.size != im2.size:
|
if im1.size != im2.size:
|
||||||
# crop both arguments to a common size
|
# crop both arguments to a common size
|
||||||
size = (min(im1.size[0], im2.size[0]),
|
size = (min(im1.size[0], im2.size[0]),
|
||||||
|
@ -79,7 +79,7 @@ class _Operand:
|
||||||
try:
|
try:
|
||||||
op = getattr(_imagingmath, op+"_"+im1.mode)
|
op = getattr(_imagingmath, op+"_"+im1.mode)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise TypeError, "bad operand type for '%s'" % op
|
raise TypeError("bad operand type for '%s'" % op)
|
||||||
_imagingmath.binop(op, out.im.id, im1.im.id, im2.im.id)
|
_imagingmath.binop(op, out.im.id, im1.im.id, im2.im.id)
|
||||||
return _Operand(out)
|
return _Operand(out)
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ def _lut(image, lut):
|
||||||
lut = lut + lut + lut
|
lut = lut + lut + lut
|
||||||
return image.point(lut)
|
return image.point(lut)
|
||||||
else:
|
else:
|
||||||
raise IOError, "not supported for this image mode"
|
raise IOError("not supported for this image mode")
|
||||||
|
|
||||||
#
|
#
|
||||||
# actions
|
# actions
|
||||||
|
|
|
@ -32,7 +32,7 @@ class ImagePalette:
|
||||||
self.colors = {}
|
self.colors = {}
|
||||||
self.dirty = None
|
self.dirty = None
|
||||||
if len(self.mode)*256 != len(self.palette):
|
if len(self.mode)*256 != len(self.palette):
|
||||||
raise ValueError, "wrong palette size"
|
raise ValueError("wrong palette size")
|
||||||
|
|
||||||
def getdata(self):
|
def getdata(self):
|
||||||
# experimental: get palette contents in format suitable
|
# experimental: get palette contents in format suitable
|
||||||
|
@ -176,7 +176,7 @@ def load(filename):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not lut:
|
if not lut:
|
||||||
raise IOError, "cannot load palette"
|
raise IOError("cannot load palette")
|
||||||
|
|
||||||
return lut # data, rawmode
|
return lut # data, rawmode
|
||||||
|
|
||||||
|
|
|
@ -53,13 +53,13 @@ class Stat:
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
self.h = image_or_list # assume it to be a histogram list
|
self.h = image_or_list # assume it to be a histogram list
|
||||||
if type(self.h) != type([]):
|
if type(self.h) != type([]):
|
||||||
raise TypeError, "first argument must be image or list"
|
raise TypeError("first argument must be image or list")
|
||||||
self.bands = range(len(self.h) / 256)
|
self.bands = range(len(self.h) / 256)
|
||||||
|
|
||||||
def __getattr__(self, id):
|
def __getattr__(self, id):
|
||||||
"Calculate missing attribute"
|
"Calculate missing attribute"
|
||||||
if id[:4] == "_get":
|
if id[:4] == "_get":
|
||||||
raise AttributeError, id
|
raise AttributeError(id)
|
||||||
# calculate missing attribute
|
# calculate missing attribute
|
||||||
v = getattr(self, "_get" + id)()
|
v = getattr(self, "_get" + id)()
|
||||||
setattr(self, id, v)
|
setattr(self, id, v)
|
||||||
|
|
|
@ -175,7 +175,7 @@ class PhotoImage:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tk.call("PyImagingPhoto", self.__photo, block.id)
|
tk.call("PyImagingPhoto", self.__photo, block.id)
|
||||||
except Tkinter.TclError, v:
|
except Tkinter.TclError as v:
|
||||||
# activate Tkinter hook
|
# activate Tkinter hook
|
||||||
try:
|
try:
|
||||||
import _imagingtk
|
import _imagingtk
|
||||||
|
@ -289,7 +289,7 @@ def _show(image, title):
|
||||||
bg="black", bd=0)
|
bg="black", bd=0)
|
||||||
|
|
||||||
if not Tkinter._default_root:
|
if not Tkinter._default_root:
|
||||||
raise IOError, "tkinter not initialized"
|
raise IOError("tkinter not initialized")
|
||||||
top = Tkinter.Toplevel()
|
top = Tkinter.Toplevel()
|
||||||
if title:
|
if title:
|
||||||
top.title(title)
|
top.title(title)
|
||||||
|
|
|
@ -40,7 +40,7 @@ class ImtImageFile(ImageFile.ImageFile):
|
||||||
# 100 bytes, this is (probably) not a text header.
|
# 100 bytes, this is (probably) not a text header.
|
||||||
|
|
||||||
if not "\n" in self.fp.read(100):
|
if not "\n" in self.fp.read(100):
|
||||||
raise SyntaxError, "not an IM file"
|
raise SyntaxError("not an IM file")
|
||||||
self.fp.seek(0)
|
self.fp.seek(0)
|
||||||
|
|
||||||
xsize = ysize = 0
|
xsize = ysize = 0
|
||||||
|
|
|
@ -70,12 +70,12 @@ class IptcImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
# syntax
|
# syntax
|
||||||
if ord(s[0]) != 0x1C or tag[0] < 1 or tag[0] > 9:
|
if ord(s[0]) != 0x1C or tag[0] < 1 or tag[0] > 9:
|
||||||
raise SyntaxError, "invalid IPTC/NAA file"
|
raise SyntaxError("invalid IPTC/NAA file")
|
||||||
|
|
||||||
# field size
|
# field size
|
||||||
size = ord(s[3])
|
size = ord(s[3])
|
||||||
if size > 132:
|
if size > 132:
|
||||||
raise IOError, "illegal field length in IPTC/NAA file"
|
raise IOError("illegal field length in IPTC/NAA file")
|
||||||
elif size == 128:
|
elif size == 128:
|
||||||
size = 0
|
size = 0
|
||||||
elif size > 128:
|
elif size > 128:
|
||||||
|
@ -150,7 +150,7 @@ class IptcImageFile(ImageFile.ImageFile):
|
||||||
try:
|
try:
|
||||||
compression = COMPRESSION[self.getint((3,120))]
|
compression = COMPRESSION[self.getint((3,120))]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise IOError, "Unknown IPTC image compression"
|
raise IOError("Unknown IPTC image compression")
|
||||||
|
|
||||||
# tile
|
# tile
|
||||||
if tag == (8,10):
|
if tag == (8,10):
|
||||||
|
|
|
@ -47,7 +47,7 @@ class MicImageFile(TiffImagePlugin.TiffImageFile):
|
||||||
try:
|
try:
|
||||||
self.ole = OleFileIO(self.fp)
|
self.ole = OleFileIO(self.fp)
|
||||||
except IOError:
|
except IOError:
|
||||||
raise SyntaxError, "not an MIC file; invalid OLE file"
|
raise SyntaxError("not an MIC file; invalid OLE file")
|
||||||
|
|
||||||
# find ACI subfiles with Image members (maybe not the
|
# find ACI subfiles with Image members (maybe not the
|
||||||
# best way to identify MIC files, but what the... ;-)
|
# best way to identify MIC files, but what the... ;-)
|
||||||
|
@ -60,7 +60,7 @@ class MicImageFile(TiffImagePlugin.TiffImageFile):
|
||||||
# if we didn't find any images, this is probably not
|
# if we didn't find any images, this is probably not
|
||||||
# an MIC file.
|
# an MIC file.
|
||||||
if not self.images:
|
if not self.images:
|
||||||
raise SyntaxError, "not an MIC file; no image entries"
|
raise SyntaxError("not an MIC file; no image entries")
|
||||||
|
|
||||||
self.__fp = self.fp
|
self.__fp = self.fp
|
||||||
self.frame = 0
|
self.frame = 0
|
||||||
|
@ -75,7 +75,7 @@ class MicImageFile(TiffImagePlugin.TiffImageFile):
|
||||||
try:
|
try:
|
||||||
filename = self.images[frame]
|
filename = self.images[frame]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise EOFError, "no such frame"
|
raise EOFError("no such frame")
|
||||||
|
|
||||||
self.fp = self.ole.openstream(filename)
|
self.fp = self.ole.openstream(filename)
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ class MpegImageFile(ImageFile.ImageFile):
|
||||||
s = BitStream(self.fp)
|
s = BitStream(self.fp)
|
||||||
|
|
||||||
if s.read(32) != 0x1B3:
|
if s.read(32) != 0x1B3:
|
||||||
raise SyntaxError, "not an MPEG file"
|
raise SyntaxError("not an MPEG file")
|
||||||
|
|
||||||
self.mode = "RGB"
|
self.mode = "RGB"
|
||||||
self.size = s.read(12), s.read(12)
|
self.size = s.read(12), s.read(12)
|
||||||
|
|
|
@ -45,14 +45,14 @@ class MspImageFile(ImageFile.ImageFile):
|
||||||
# Header
|
# Header
|
||||||
s = self.fp.read(32)
|
s = self.fp.read(32)
|
||||||
if s[:4] not in ["DanM", "LinS"]:
|
if s[:4] not in ["DanM", "LinS"]:
|
||||||
raise SyntaxError, "not an MSP file"
|
raise SyntaxError("not an MSP file")
|
||||||
|
|
||||||
# Header checksum
|
# Header checksum
|
||||||
sum = 0
|
sum = 0
|
||||||
for i in range(0, 32, 2):
|
for i in range(0, 32, 2):
|
||||||
sum = sum ^ i16(s[i:i+2])
|
sum = sum ^ i16(s[i:i+2])
|
||||||
if sum != 0:
|
if sum != 0:
|
||||||
raise SyntaxError, "bad MSP checksum"
|
raise SyntaxError("bad MSP checksum")
|
||||||
|
|
||||||
self.mode = "1"
|
self.mode = "1"
|
||||||
self.size = i16(s[4:]), i16(s[6:])
|
self.size = i16(s[4:]), i16(s[6:])
|
||||||
|
@ -71,7 +71,7 @@ def o16(i):
|
||||||
def _save(im, fp, filename):
|
def _save(im, fp, filename):
|
||||||
|
|
||||||
if im.mode != "1":
|
if im.mode != "1":
|
||||||
raise IOError, "cannot write mode %s as MSP" % im.mode
|
raise IOError("cannot write mode %s as MSP" % im.mode)
|
||||||
|
|
||||||
# create MSP header
|
# create MSP header
|
||||||
header = [0] * 16
|
header = [0] * 16
|
||||||
|
|
|
@ -273,7 +273,7 @@ class OleFileIO:
|
||||||
header = self.fp.read(512)
|
header = self.fp.read(512)
|
||||||
|
|
||||||
if len(header) != 512 or header[:8] != MAGIC:
|
if len(header) != 512 or header[:8] != MAGIC:
|
||||||
raise IOError, "not an OLE2 structured storage file"
|
raise IOError("not an OLE2 structured storage file")
|
||||||
|
|
||||||
# file clsid (probably never used, so we don't store it)
|
# file clsid (probably never used, so we don't store it)
|
||||||
clsid = self._clsid(header[8:24])
|
clsid = self._clsid(header[8:24])
|
||||||
|
@ -385,7 +385,7 @@ class OleFileIO:
|
||||||
if kid.name == name:
|
if kid.name == name:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise IOError, "file not found"
|
raise IOError("file not found")
|
||||||
node = kid
|
node = kid
|
||||||
return node.sid
|
return node.sid
|
||||||
|
|
||||||
|
@ -423,7 +423,7 @@ class OleFileIO:
|
||||||
slot = self._find(filename)
|
slot = self._find(filename)
|
||||||
name, type, sect, size, sids, clsid = self.sidlist[slot]
|
name, type, sect, size, sids, clsid = self.sidlist[slot]
|
||||||
if type != 2:
|
if type != 2:
|
||||||
raise IOError, "this file is not a stream"
|
raise IOError("this file is not a stream")
|
||||||
return self._open(sect, size)
|
return self._open(sect, size)
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -524,5 +524,5 @@ if __name__ == "__main__":
|
||||||
props.sort()
|
props.sort()
|
||||||
for k, v in props:
|
for k, v in props:
|
||||||
print " ", k, v
|
print " ", k, v
|
||||||
except IOError, v:
|
except IOError as v:
|
||||||
print "***", "cannot read", file, "-", v
|
print "***", "cannot read", file, "-", v
|
||||||
|
|
|
@ -33,7 +33,7 @@ class PaletteFile:
|
||||||
if s[0] == "#":
|
if s[0] == "#":
|
||||||
continue
|
continue
|
||||||
if len(s) > 100:
|
if len(s) > 100:
|
||||||
raise SyntaxError, "bad palette file"
|
raise SyntaxError("bad palette file")
|
||||||
|
|
||||||
v = map(int, s.split())
|
v = map(int, s.split())
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -158,7 +158,7 @@ def _save(im, fp, filename, check=0):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
raise IOError, "cannot write mode %s as Palm" % im.mode
|
raise IOError("cannot write mode %s as Palm" % im.mode)
|
||||||
|
|
||||||
if check:
|
if check:
|
||||||
return check
|
return check
|
||||||
|
|
|
@ -37,7 +37,7 @@ class PcdImageFile(ImageFile.ImageFile):
|
||||||
s = self.fp.read(2048)
|
s = self.fp.read(2048)
|
||||||
|
|
||||||
if s[:4] != "PCD_":
|
if s[:4] != "PCD_":
|
||||||
raise SyntaxError, "not a PCD file"
|
raise SyntaxError("not a PCD file")
|
||||||
|
|
||||||
orientation = ord(s[1538]) & 3
|
orientation = ord(s[1538]) & 3
|
||||||
if orientation == 1:
|
if orientation == 1:
|
||||||
|
|
|
@ -66,7 +66,7 @@ class PcfFontFile(FontFile.FontFile):
|
||||||
|
|
||||||
magic = l32(fp.read(4))
|
magic = l32(fp.read(4))
|
||||||
if magic != PCF_MAGIC:
|
if magic != PCF_MAGIC:
|
||||||
raise SyntaxError, "not a PCF file"
|
raise SyntaxError("not a PCF file")
|
||||||
|
|
||||||
FontFile.FontFile.__init__(self)
|
FontFile.FontFile.__init__(self)
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ class PcfFontFile(FontFile.FontFile):
|
||||||
nbitmaps = i32(fp.read(4))
|
nbitmaps = i32(fp.read(4))
|
||||||
|
|
||||||
if nbitmaps != len(metrics):
|
if nbitmaps != len(metrics):
|
||||||
raise IOError, "Wrong number of bitmaps"
|
raise IOError("Wrong number of bitmaps")
|
||||||
|
|
||||||
offsets = []
|
offsets = []
|
||||||
for i in range(nbitmaps):
|
for i in range(nbitmaps):
|
||||||
|
|
|
@ -48,12 +48,12 @@ class PcxImageFile(ImageFile.ImageFile):
|
||||||
# header
|
# header
|
||||||
s = self.fp.read(128)
|
s = self.fp.read(128)
|
||||||
if not _accept(s):
|
if not _accept(s):
|
||||||
raise SyntaxError, "not a PCX file"
|
raise SyntaxError("not a PCX file")
|
||||||
|
|
||||||
# image
|
# image
|
||||||
bbox = i16(s,4), i16(s,6), i16(s,8)+1, i16(s,10)+1
|
bbox = i16(s,4), i16(s,6), i16(s,8)+1, i16(s,10)+1
|
||||||
if bbox[2] <= bbox[0] or bbox[3] <= bbox[1]:
|
if bbox[2] <= bbox[0] or bbox[3] <= bbox[1]:
|
||||||
raise SyntaxError, "bad PCX image size"
|
raise SyntaxError("bad PCX image size")
|
||||||
|
|
||||||
# format
|
# format
|
||||||
version = ord(s[1])
|
version = ord(s[1])
|
||||||
|
@ -91,7 +91,7 @@ class PcxImageFile(ImageFile.ImageFile):
|
||||||
rawmode = "RGB;L"
|
rawmode = "RGB;L"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise IOError, "unknown PCX mode"
|
raise IOError("unknown PCX mode")
|
||||||
|
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.size = bbox[2]-bbox[0], bbox[3]-bbox[1]
|
self.size = bbox[2]-bbox[0], bbox[3]-bbox[1]
|
||||||
|
@ -119,7 +119,7 @@ def _save(im, fp, filename, check=0):
|
||||||
try:
|
try:
|
||||||
version, bits, planes, rawmode = SAVE[im.mode]
|
version, bits, planes, rawmode = SAVE[im.mode]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ValueError, "Cannot save %s images as PCX" % im.mode
|
raise ValueError("Cannot save %s images as PCX" % im.mode)
|
||||||
|
|
||||||
if check:
|
if check:
|
||||||
return check
|
return check
|
||||||
|
|
|
@ -45,7 +45,7 @@ class PixarImageFile(ImageFile.ImageFile):
|
||||||
# assuming a 4-byte magic label (FIXME: add "_accept" hook)
|
# assuming a 4-byte magic label (FIXME: add "_accept" hook)
|
||||||
s = self.fp.read(4)
|
s = self.fp.read(4)
|
||||||
if s != "\200\350\000\000":
|
if s != "\200\350\000\000":
|
||||||
raise SyntaxError, "not a PIXAR file"
|
raise SyntaxError("not a PIXAR file")
|
||||||
|
|
||||||
# read rest of header
|
# read rest of header
|
||||||
s = s + self.fp.read(508)
|
s = s + self.fp.read(508)
|
||||||
|
|
|
@ -96,7 +96,7 @@ class ChunkStream:
|
||||||
len = i32(s)
|
len = i32(s)
|
||||||
|
|
||||||
if not is_cid(cid):
|
if not is_cid(cid):
|
||||||
raise SyntaxError, "broken PNG file (chunk %s)" % repr(cid)
|
raise SyntaxError("broken PNG file (chunk %s)" % repr(cid))
|
||||||
|
|
||||||
return cid, pos, len
|
return cid, pos, len
|
||||||
|
|
||||||
|
@ -120,8 +120,8 @@ class ChunkStream:
|
||||||
crc1 = Image.core.crc32(data, Image.core.crc32(cid))
|
crc1 = Image.core.crc32(data, Image.core.crc32(cid))
|
||||||
crc2 = i16(self.fp.read(2)), i16(self.fp.read(2))
|
crc2 = i16(self.fp.read(2)), i16(self.fp.read(2))
|
||||||
if crc1 != crc2:
|
if crc1 != crc2:
|
||||||
raise SyntaxError, "broken PNG file"\
|
raise SyntaxError("broken PNG file"\
|
||||||
"(bad header checksum in %s)" % cid
|
"(bad header checksum in %s)" % cid)
|
||||||
|
|
||||||
def crc_skip(self, cid, data):
|
def crc_skip(self, cid, data):
|
||||||
"Read checksum. Used if the C module is not present"
|
"Read checksum. Used if the C module is not present"
|
||||||
|
@ -215,7 +215,7 @@ class PngStream(ChunkStream):
|
||||||
if ord(s[12]):
|
if ord(s[12]):
|
||||||
self.im_info["interlace"] = 1
|
self.im_info["interlace"] = 1
|
||||||
if ord(s[11]):
|
if ord(s[11]):
|
||||||
raise SyntaxError, "unknown filter category"
|
raise SyntaxError("unknown filter category")
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def chunk_IDAT(self, pos, len):
|
def chunk_IDAT(self, pos, len):
|
||||||
|
@ -313,7 +313,7 @@ class PngImageFile(ImageFile.ImageFile):
|
||||||
def _open(self):
|
def _open(self):
|
||||||
|
|
||||||
if self.fp.read(8) != _MAGIC:
|
if self.fp.read(8) != _MAGIC:
|
||||||
raise SyntaxError, "not a PNG file"
|
raise SyntaxError("not a PNG file")
|
||||||
|
|
||||||
#
|
#
|
||||||
# Parse headers up to the first IDAT chunk
|
# Parse headers up to the first IDAT chunk
|
||||||
|
@ -503,7 +503,7 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
|
||||||
try:
|
try:
|
||||||
rawmode, mode = _OUTMODES[mode]
|
rawmode, mode = _OUTMODES[mode]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise IOError, "cannot write mode %s as PNG" % mode
|
raise IOError("cannot write mode %s as PNG" % mode)
|
||||||
|
|
||||||
if check:
|
if check:
|
||||||
return check
|
return check
|
||||||
|
|
|
@ -61,7 +61,7 @@ class PpmImageFile(ImageFile.ImageFile):
|
||||||
# check magic
|
# check magic
|
||||||
s = self.fp.read(1)
|
s = self.fp.read(1)
|
||||||
if s != "P":
|
if s != "P":
|
||||||
raise SyntaxError, "not a PPM file"
|
raise SyntaxError("not a PPM file")
|
||||||
mode = MODES[self._token(s)]
|
mode = MODES[self._token(s)]
|
||||||
|
|
||||||
if mode == "1":
|
if mode == "1":
|
||||||
|
@ -111,7 +111,7 @@ def _save(im, fp, filename):
|
||||||
elif im.mode == "RGBA":
|
elif im.mode == "RGBA":
|
||||||
rawmode, head = "RGB", "P6"
|
rawmode, head = "RGB", "P6"
|
||||||
else:
|
else:
|
||||||
raise IOError, "cannot write mode %s as PPM" % im.mode
|
raise IOError("cannot write mode %s as PPM" % im.mode)
|
||||||
fp.write(head + "\n%d %d\n" % im.size)
|
fp.write(head + "\n%d %d\n" % im.size)
|
||||||
if head != "P4":
|
if head != "P4":
|
||||||
fp.write("255\n")
|
fp.write("255\n")
|
||||||
|
|
|
@ -65,7 +65,7 @@ class PsdImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
s = read(26)
|
s = read(26)
|
||||||
if s[:4] != "8BPS" or i16(s[4:]) != 1:
|
if s[:4] != "8BPS" or i16(s[4:]) != 1:
|
||||||
raise SyntaxError, "not a PSD file"
|
raise SyntaxError("not a PSD file")
|
||||||
|
|
||||||
psd_bits = i16(s[22:])
|
psd_bits = i16(s[22:])
|
||||||
psd_channels = i16(s[12:])
|
psd_channels = i16(s[12:])
|
||||||
|
@ -74,7 +74,7 @@ class PsdImageFile(ImageFile.ImageFile):
|
||||||
mode, channels = MODES[(psd_mode, psd_bits)]
|
mode, channels = MODES[(psd_mode, psd_bits)]
|
||||||
|
|
||||||
if channels > psd_channels:
|
if channels > psd_channels:
|
||||||
raise IOError, "not enough channels"
|
raise IOError("not enough channels")
|
||||||
|
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.size = i32(s[18:]), i32(s[14:])
|
self.size = i32(s[18:]), i32(s[14:])
|
||||||
|
@ -146,7 +146,7 @@ class PsdImageFile(ImageFile.ImageFile):
|
||||||
self.fp = self._fp
|
self.fp = self._fp
|
||||||
return name, bbox
|
return name, bbox
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise EOFError, "no such layer"
|
raise EOFError("no such layer")
|
||||||
|
|
||||||
def tell(self):
|
def tell(self):
|
||||||
# return layer number (0=image, 1..max=layers)
|
# return layer number (0=image, 1..max=layers)
|
||||||
|
|
|
@ -101,14 +101,14 @@ class SpiderImageFile(ImageFile.ImageFile):
|
||||||
t = struct.unpack('<27f',f) # little-endian
|
t = struct.unpack('<27f',f) # little-endian
|
||||||
hdrlen = isSpiderHeader(t)
|
hdrlen = isSpiderHeader(t)
|
||||||
if hdrlen == 0:
|
if hdrlen == 0:
|
||||||
raise SyntaxError, "not a valid Spider file"
|
raise SyntaxError("not a valid Spider file")
|
||||||
except struct.error:
|
except struct.error:
|
||||||
raise SyntaxError, "not a valid Spider file"
|
raise SyntaxError("not a valid Spider file")
|
||||||
|
|
||||||
h = (99,) + t # add 1 value : spider header index starts at 1
|
h = (99,) + t # add 1 value : spider header index starts at 1
|
||||||
iform = int(h[5])
|
iform = int(h[5])
|
||||||
if iform != 1:
|
if iform != 1:
|
||||||
raise SyntaxError, "not a Spider 2D image"
|
raise SyntaxError("not a Spider 2D image")
|
||||||
|
|
||||||
self.size = int(h[12]), int(h[2]) # size in pixels (width, height)
|
self.size = int(h[12]), int(h[2]) # size in pixels (width, height)
|
||||||
self.istack = int(h[24])
|
self.istack = int(h[24])
|
||||||
|
@ -131,7 +131,7 @@ class SpiderImageFile(ImageFile.ImageFile):
|
||||||
offset = hdrlen + self.stkoffset
|
offset = hdrlen + self.stkoffset
|
||||||
self.istack = 2 # So Image knows it's still a stack
|
self.istack = 2 # So Image knows it's still a stack
|
||||||
else:
|
else:
|
||||||
raise SyntaxError, "inconsistent stack header values"
|
raise SyntaxError("inconsistent stack header values")
|
||||||
|
|
||||||
if self.bigendian:
|
if self.bigendian:
|
||||||
self.rawmode = "F;32BF"
|
self.rawmode = "F;32BF"
|
||||||
|
@ -154,7 +154,7 @@ class SpiderImageFile(ImageFile.ImageFile):
|
||||||
if self.istack == 0:
|
if self.istack == 0:
|
||||||
return
|
return
|
||||||
if frame >= self.nimages:
|
if frame >= self.nimages:
|
||||||
raise EOFError, "attempt to seek past end of file"
|
raise EOFError("attempt to seek past end of file")
|
||||||
self.stkoffset = self.hdrlen + frame * (self.hdrlen + self.imgbytes)
|
self.stkoffset = self.hdrlen + frame * (self.hdrlen + self.imgbytes)
|
||||||
self.fp = self.__fp
|
self.fp = self.__fp
|
||||||
self.fp.seek(self.stkoffset)
|
self.fp.seek(self.stkoffset)
|
||||||
|
@ -239,13 +239,13 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
hdr = makeSpiderHeader(im)
|
hdr = makeSpiderHeader(im)
|
||||||
if len(hdr) < 256:
|
if len(hdr) < 256:
|
||||||
raise IOError, "Error creating Spider header"
|
raise IOError("Error creating Spider header")
|
||||||
|
|
||||||
# write the SPIDER header
|
# write the SPIDER header
|
||||||
try:
|
try:
|
||||||
fp = open(filename, 'wb')
|
fp = open(filename, 'wb')
|
||||||
except:
|
except:
|
||||||
raise IOError, "Unable to open %s for writing" % filename
|
raise IOError("Unable to open %s for writing" % filename)
|
||||||
fp.writelines(hdr)
|
fp.writelines(hdr)
|
||||||
|
|
||||||
rawmode = "F;32NF" #32-bit native floating point
|
rawmode = "F;32NF" #32-bit native floating point
|
||||||
|
|
|
@ -46,7 +46,7 @@ class SunImageFile(ImageFile.ImageFile):
|
||||||
# HEAD
|
# HEAD
|
||||||
s = self.fp.read(32)
|
s = self.fp.read(32)
|
||||||
if i32(s) != 0x59a66a95:
|
if i32(s) != 0x59a66a95:
|
||||||
raise SyntaxError, "not an SUN raster file"
|
raise SyntaxError("not an SUN raster file")
|
||||||
|
|
||||||
offset = 32
|
offset = 32
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class SunImageFile(ImageFile.ImageFile):
|
||||||
elif depth == 24:
|
elif depth == 24:
|
||||||
self.mode, rawmode = "RGB", "BGR"
|
self.mode, rawmode = "RGB", "BGR"
|
||||||
else:
|
else:
|
||||||
raise SyntaxError, "unsupported mode"
|
raise SyntaxError("unsupported mode")
|
||||||
|
|
||||||
compression = i32(s[20:24])
|
compression = i32(s[20:24])
|
||||||
|
|
||||||
|
|
|
@ -36,12 +36,12 @@ class TarIO(ContainerIO.ContainerIO):
|
||||||
|
|
||||||
s = fh.read(512)
|
s = fh.read(512)
|
||||||
if len(s) != 512:
|
if len(s) != 512:
|
||||||
raise IOError, "unexpected end of tar file"
|
raise IOError("unexpected end of tar file")
|
||||||
|
|
||||||
name = s[:100]
|
name = s[:100]
|
||||||
i = name.find(chr(0))
|
i = name.find(chr(0))
|
||||||
if i == 0:
|
if i == 0:
|
||||||
raise IOError, "cannot find subfile"
|
raise IOError("cannot find subfile")
|
||||||
if i > 0:
|
if i > 0:
|
||||||
name = name[:i]
|
name = name[:i]
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ class TgaImageFile(ImageFile.ImageFile):
|
||||||
if id != 0 or colormaptype not in (0, 1) or\
|
if id != 0 or colormaptype not in (0, 1) or\
|
||||||
self.size[0] <= 0 or self.size[1] <= 0 or\
|
self.size[0] <= 0 or self.size[1] <= 0 or\
|
||||||
depth not in (1, 8, 16, 24, 32):
|
depth not in (1, 8, 16, 24, 32):
|
||||||
raise SyntaxError, "not a TGA file"
|
raise SyntaxError("not a TGA file")
|
||||||
|
|
||||||
# image mode
|
# image mode
|
||||||
if imagetype in (3, 11):
|
if imagetype in (3, 11):
|
||||||
|
@ -89,7 +89,7 @@ class TgaImageFile(ImageFile.ImageFile):
|
||||||
if depth == 32:
|
if depth == 32:
|
||||||
self.mode = "RGBA"
|
self.mode = "RGBA"
|
||||||
else:
|
else:
|
||||||
raise SyntaxError, "unknown TGA mode"
|
raise SyntaxError("unknown TGA mode")
|
||||||
|
|
||||||
# orientation
|
# orientation
|
||||||
orientation = flags & 0x30
|
orientation = flags & 0x30
|
||||||
|
@ -98,7 +98,7 @@ class TgaImageFile(ImageFile.ImageFile):
|
||||||
elif not orientation:
|
elif not orientation:
|
||||||
orientation = -1
|
orientation = -1
|
||||||
else:
|
else:
|
||||||
raise SyntaxError, "unknown TGA orientation"
|
raise SyntaxError("unknown TGA orientation")
|
||||||
|
|
||||||
self.info["orientation"] = orientation
|
self.info["orientation"] = orientation
|
||||||
|
|
||||||
|
|
|
@ -265,7 +265,7 @@ class ImageFileDirectory:
|
||||||
# work around broken (?) matrox library
|
# work around broken (?) matrox library
|
||||||
# (from Ted Wright, via Bob Klimek)
|
# (from Ted Wright, via Bob Klimek)
|
||||||
raise KeyError # use default
|
raise KeyError # use default
|
||||||
raise ValueError, "not a scalar"
|
raise ValueError("not a scalar")
|
||||||
return value[0]
|
return value[0]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if default is None:
|
if default is None:
|
||||||
|
@ -379,7 +379,7 @@ class ImageFileDirectory:
|
||||||
data = ifd[8:8+size]
|
data = ifd[8:8+size]
|
||||||
|
|
||||||
if len(data) != size:
|
if len(data) != size:
|
||||||
raise IOError, "not enough data"
|
raise IOError("not enough data")
|
||||||
|
|
||||||
self.tagdata[tag] = typ, data
|
self.tagdata[tag] = typ, data
|
||||||
self.tagtype[tag] = typ
|
self.tagtype[tag] = typ
|
||||||
|
@ -513,7 +513,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
ifh = self.fp.read(8)
|
ifh = self.fp.read(8)
|
||||||
|
|
||||||
if ifh[:4] not in PREFIXES:
|
if ifh[:4] not in PREFIXES:
|
||||||
raise SyntaxError, "not a TIFF file"
|
raise SyntaxError("not a TIFF file")
|
||||||
|
|
||||||
# image file directory (tag dictionary)
|
# image file directory (tag dictionary)
|
||||||
self.tag = self.ifd = ImageFileDirectory(ifh[:2])
|
self.tag = self.ifd = ImageFileDirectory(ifh[:2])
|
||||||
|
@ -547,7 +547,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
self.__next = self.__first
|
self.__next = self.__first
|
||||||
while self.__frame < frame:
|
while self.__frame < frame:
|
||||||
if not self.__next:
|
if not self.__next:
|
||||||
raise EOFError, "no more images in TIFF file"
|
raise EOFError("no more images in TIFF file")
|
||||||
self.fp.seek(self.__next)
|
self.fp.seek(self.__next)
|
||||||
self.tag.load(self.fp)
|
self.tag.load(self.fp)
|
||||||
self.__next = self.tag.next
|
self.__next = self.tag.next
|
||||||
|
@ -589,7 +589,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
"Setup this image object based on current tags"
|
"Setup this image object based on current tags"
|
||||||
|
|
||||||
if self.tag.has_key(0xBC01):
|
if self.tag.has_key(0xBC01):
|
||||||
raise IOError, "Windows Media Photo files not yet supported"
|
raise IOError("Windows Media Photo files not yet supported")
|
||||||
|
|
||||||
getscalar = self.tag.getscalar
|
getscalar = self.tag.getscalar
|
||||||
|
|
||||||
|
@ -633,7 +633,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if Image.DEBUG:
|
if Image.DEBUG:
|
||||||
print "- unsupported format"
|
print "- unsupported format"
|
||||||
raise SyntaxError, "unknown pixel mode"
|
raise SyntaxError("unknown pixel mode")
|
||||||
|
|
||||||
if Image.DEBUG:
|
if Image.DEBUG:
|
||||||
print "- raw mode:", rawmode
|
print "- raw mode:", rawmode
|
||||||
|
@ -751,7 +751,7 @@ def _save(im, fp, filename):
|
||||||
try:
|
try:
|
||||||
rawmode, prefix, photo, format, bits, extra = SAVE_INFO[im.mode]
|
rawmode, prefix, photo, format, bits, extra = SAVE_INFO[im.mode]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise IOError, "cannot write mode %s as TIFF" % im.mode
|
raise IOError("cannot write mode %s as TIFF" % im.mode)
|
||||||
|
|
||||||
ifd = ImageFileDirectory(prefix)
|
ifd = ImageFileDirectory(prefix)
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ class XVThumbImageFile(ImageFile.ImageFile):
|
||||||
# check magic
|
# check magic
|
||||||
s = self.fp.read(6)
|
s = self.fp.read(6)
|
||||||
if s != "P7 332":
|
if s != "P7 332":
|
||||||
raise SyntaxError, "not an XV thumbnail file"
|
raise SyntaxError("not an XV thumbnail file")
|
||||||
|
|
||||||
# Skip to beginning of next line
|
# Skip to beginning of next line
|
||||||
self.fp.readline()
|
self.fp.readline()
|
||||||
|
@ -50,7 +50,7 @@ class XVThumbImageFile(ImageFile.ImageFile):
|
||||||
while 1:
|
while 1:
|
||||||
s = self.fp.readline()
|
s = self.fp.readline()
|
||||||
if not s:
|
if not s:
|
||||||
raise SyntaxError, "Unexpected EOF reading XV thumbnail file"
|
raise SyntaxError("Unexpected EOF reading XV thumbnail file")
|
||||||
if s[0] != '#':
|
if s[0] != '#':
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ class XbmImageFile(ImageFile.ImageFile):
|
||||||
def _save(im, fp, filename):
|
def _save(im, fp, filename):
|
||||||
|
|
||||||
if im.mode != "1":
|
if im.mode != "1":
|
||||||
raise IOError, "cannot write mode %s as XBM" % im.mode
|
raise IOError("cannot write mode %s as XBM" % im.mode)
|
||||||
|
|
||||||
fp.write("#define im_width %d\n" % im.size[0])
|
fp.write("#define im_width %d\n" % im.size[0])
|
||||||
fp.write("#define im_height %d\n" % im.size[1])
|
fp.write("#define im_height %d\n" % im.size[1])
|
||||||
|
|
|
@ -39,13 +39,13 @@ class XpmImageFile(ImageFile.ImageFile):
|
||||||
def _open(self):
|
def _open(self):
|
||||||
|
|
||||||
if not _accept(self.fp.read(9)):
|
if not _accept(self.fp.read(9)):
|
||||||
raise SyntaxError, "not an XPM file"
|
raise SyntaxError("not an XPM file")
|
||||||
|
|
||||||
# skip forward to next string
|
# skip forward to next string
|
||||||
while 1:
|
while 1:
|
||||||
s = self.fp.readline()
|
s = self.fp.readline()
|
||||||
if not s:
|
if not s:
|
||||||
raise SyntaxError, "broken XPM file"
|
raise SyntaxError("broken XPM file")
|
||||||
m = xpm_head.match(s)
|
m = xpm_head.match(s)
|
||||||
if m:
|
if m:
|
||||||
break
|
break
|
||||||
|
@ -56,7 +56,7 @@ class XpmImageFile(ImageFile.ImageFile):
|
||||||
bpp = int(m.group(4))
|
bpp = int(m.group(4))
|
||||||
|
|
||||||
if pal > 256 or bpp != 1:
|
if pal > 256 or bpp != 1:
|
||||||
raise ValueError, "cannot read this XPM file"
|
raise ValueError("cannot read this XPM file")
|
||||||
|
|
||||||
#
|
#
|
||||||
# load palette description
|
# load palette description
|
||||||
|
@ -90,13 +90,13 @@ class XpmImageFile(ImageFile.ImageFile):
|
||||||
chr(rgb & 255)
|
chr(rgb & 255)
|
||||||
else:
|
else:
|
||||||
# unknown colour
|
# unknown colour
|
||||||
raise ValueError, "cannot read this XPM file"
|
raise ValueError("cannot read this XPM file")
|
||||||
break
|
break
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
# missing colour key
|
# missing colour key
|
||||||
raise ValueError, "cannot read this XPM file"
|
raise ValueError("cannot read this XPM file")
|
||||||
|
|
||||||
self.mode = "P"
|
self.mode = "P"
|
||||||
self.palette = ImagePalette.raw("RGB", "".join(palette))
|
self.palette = ImagePalette.raw("RGB", "".join(palette))
|
||||||
|
|
16
Sane/sane.py
16
Sane/sane.py
|
@ -105,7 +105,7 @@ class _SaneIterator:
|
||||||
def next(self):
|
def next(self):
|
||||||
try:
|
try:
|
||||||
self.device.start()
|
self.device.start()
|
||||||
except error, v:
|
except error as v:
|
||||||
if v == 'Document feeder out of documents':
|
if v == 'Document feeder out of documents':
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
else:
|
else:
|
||||||
|
@ -169,11 +169,11 @@ class SaneDev:
|
||||||
self.__dict__[key]=value ; return
|
self.__dict__[key]=value ; return
|
||||||
opt=optdict[key]
|
opt=optdict[key]
|
||||||
if opt.type==TYPE_GROUP:
|
if opt.type==TYPE_GROUP:
|
||||||
raise AttributeError, "Groups can't be set: "+key
|
raise AttributeError("Groups can't be set: "+key)
|
||||||
if not _sane.OPTION_IS_ACTIVE(opt.cap):
|
if not _sane.OPTION_IS_ACTIVE(opt.cap):
|
||||||
raise AttributeError, 'Inactive option: '+key
|
raise AttributeError('Inactive option: '+key)
|
||||||
if not _sane.OPTION_IS_SETTABLE(opt.cap):
|
if not _sane.OPTION_IS_SETTABLE(opt.cap):
|
||||||
raise AttributeError, "Option can't be set by software: "+key
|
raise AttributeError("Option can't be set by software: "+key)
|
||||||
if type(value) == int and opt.type == TYPE_FIXED:
|
if type(value) == int and opt.type == TYPE_FIXED:
|
||||||
# avoid annoying errors of backend if int is given instead float:
|
# avoid annoying errors of backend if int is given instead float:
|
||||||
value = float(value)
|
value = float(value)
|
||||||
|
@ -190,14 +190,14 @@ class SaneDev:
|
||||||
if key=='area':
|
if key=='area':
|
||||||
return (self.tl_x, self.tl_y),(self.br_x, self.br_y)
|
return (self.tl_x, self.tl_y),(self.br_x, self.br_y)
|
||||||
if not optdict.has_key(key):
|
if not optdict.has_key(key):
|
||||||
raise AttributeError, 'No such attribute: '+key
|
raise AttributeError('No such attribute: '+key)
|
||||||
opt=optdict[key]
|
opt=optdict[key]
|
||||||
if opt.type==TYPE_BUTTON:
|
if opt.type==TYPE_BUTTON:
|
||||||
raise AttributeError, "Buttons don't have values: "+key
|
raise AttributeError("Buttons don't have values: "+key)
|
||||||
if opt.type==TYPE_GROUP:
|
if opt.type==TYPE_GROUP:
|
||||||
raise AttributeError, "Groups don't have values: "+key
|
raise AttributeError("Groups don't have values: "+key)
|
||||||
if not _sane.OPTION_IS_ACTIVE(opt.cap):
|
if not _sane.OPTION_IS_ACTIVE(opt.cap):
|
||||||
raise AttributeError, 'Inactive option: '+key
|
raise AttributeError('Inactive option: '+key)
|
||||||
value = dev.get_option(opt.index)
|
value = dev.get_option(opt.index)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ if len(sys.argv) == 1:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opt, argv = getopt.getopt(sys.argv[1:], "c:dfgopq:r")
|
opt, argv = getopt.getopt(sys.argv[1:], "c:dfgopq:r")
|
||||||
except getopt.error, v:
|
except getopt.error as v:
|
||||||
print v
|
print v
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -93,4 +93,4 @@ try:
|
||||||
apply(im.save, (argv[1],), options)
|
apply(im.save, (argv[1],), options)
|
||||||
except:
|
except:
|
||||||
print "cannot convert image",
|
print "cannot convert image",
|
||||||
print "(%s:%s)" % (sys.exc_type, sys.exc_value)
|
print "(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1])
|
||||||
|
|
|
@ -34,7 +34,7 @@ if len(sys.argv) == 1:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opt, args = getopt.getopt(sys.argv[1:], "fqivD")
|
opt, args = getopt.getopt(sys.argv[1:], "fqivD")
|
||||||
except getopt.error, v:
|
except getopt.error as v:
|
||||||
print v
|
print v
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -83,8 +83,8 @@ for file in globfix(args):
|
||||||
except:
|
except:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print "failed to verify image",
|
print "failed to verify image",
|
||||||
print "(%s:%s)" % (sys.exc_type, sys.exc_value)
|
print "(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1])
|
||||||
except IOError, v:
|
except IOError as v:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print file, "failed:", v
|
print file, "failed:", v
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -39,7 +39,7 @@ if len(sys.argv) == 1:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opt, argv = getopt.getopt(sys.argv[1:], "cdpP:")
|
opt, argv = getopt.getopt(sys.argv[1:], "cdpP:")
|
||||||
except getopt.error, v:
|
except getopt.error as v:
|
||||||
print v
|
print v
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -90,4 +90,4 @@ for file in argv:
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print "cannot print image",
|
print "cannot print image",
|
||||||
print "(%s:%s)" % (sys.exc_type, sys.exc_value)
|
print "(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1])
|
||||||
|
|
|
@ -12,7 +12,7 @@ from PIL import ImageMath
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Image.core.ping
|
Image.core.ping
|
||||||
except ImportError, v:
|
except ImportError as v:
|
||||||
print "***", v
|
print "***", v
|
||||||
sys.exit()
|
sys.exit()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user