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