Skip to content

Commit

Permalink
Raise statement normalization in Lib/.
Browse files Browse the repository at this point in the history
  • Loading branch information
collinw committed Aug 30, 2007
1 parent 8b3febe commit ce36ad8
Show file tree
Hide file tree
Showing 80 changed files with 502 additions and 530 deletions.
2 changes: 1 addition & 1 deletion Lib/ConfigParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def getfloat(self, section, option):
def getboolean(self, section, option):
v = self.get(section, option)
if v.lower() not in self._boolean_states:
raise ValueError, 'Not a boolean: %s' % v
raise ValueError('Not a boolean: %s' % v)
return self._boolean_states[v.lower()]

def optionxform(self, optionstr):
Expand Down
6 changes: 3 additions & 3 deletions Lib/UserDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def setdefault(self, key, default=None):
return default
def pop(self, key, *args):
if len(args) > 1:
raise TypeError, "pop expected at most 2 arguments, got "\
+ repr(1 + len(args))
raise TypeError("pop expected at most 2 arguments, got "
+ repr(1 + len(args)))
try:
value = self[key]
except KeyError:
Expand All @@ -141,7 +141,7 @@ def popitem(self):
try:
k, v = next(self.iteritems())
except StopIteration:
raise KeyError, 'container is empty'
raise KeyError('container is empty')
del self[k]
return (k, v)
def update(self, other=None, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion Lib/UserString.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class MutableString(UserString):
def __init__(self, string=""):
self.data = string
def __hash__(self):
raise TypeError, "unhashable type (it is mutable)"
raise TypeError("unhashable type (it is mutable)")
def __setitem__(self, index, sub):
if isinstance(index, slice):
if isinstance(sub, UserString):
Expand Down
78 changes: 39 additions & 39 deletions Lib/aifc.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ def initfp(self, file):
self._soundpos = 0
self._file = Chunk(file)
if self._file.getname() != 'FORM':
raise Error, 'file does not start with FORM id'
raise Error('file does not start with FORM id')
formdata = self._file.read(4)
if formdata == 'AIFF':
self._aifc = 0
elif formdata == 'AIFC':
self._aifc = 1
else:
raise Error, 'not an AIFF or AIFF-C file'
raise Error('not an AIFF or AIFF-C file')
self._comm_chunk_read = 0
while 1:
self._ssnd_seek_needed = 1
Expand All @@ -317,10 +317,10 @@ def initfp(self, file):
elif chunkname in _skiplist:
pass
else:
raise Error, 'unrecognized chunk type '+chunk.chunkname
raise Error('unrecognized chunk type '+chunk.chunkname)
chunk.skip()
if not self._comm_chunk_read or not self._ssnd_chunk:
raise Error, 'COMM chunk and/or SSND chunk missing'
raise Error('COMM chunk and/or SSND chunk missing')
if self._aifc and self._decomp:
import cl
params = [cl.ORIGINAL_FORMAT, 0,
Expand All @@ -331,7 +331,7 @@ def initfp(self, file):
elif self._nchannels == 2:
params[1] = cl.STEREO_INTERLEAVED
else:
raise Error, 'cannot compress more than 2 channels'
raise Error('cannot compress more than 2 channels')
self._decomp.SetParams(params)

def __init__(self, f):
Expand Down Expand Up @@ -394,11 +394,11 @@ def getmark(self, id):
for marker in self._markers:
if id == marker[0]:
return marker
raise Error, 'marker %r does not exist' % (id,)
raise Error('marker %r does not exist' % (id,))

def setpos(self, pos):
if pos < 0 or pos > self._nframes:
raise Error, 'position not in range'
raise Error('position not in range')
self._soundpos = pos
self._ssnd_seek_needed = 1

Expand Down Expand Up @@ -488,15 +488,15 @@ def _read_comm_chunk(self, chunk):
return
except ImportError:
pass
raise Error, 'cannot read compressed AIFF-C files'
raise Error('cannot read compressed AIFF-C files')
if self._comptype == 'ULAW':
scheme = cl.G711_ULAW
self._framesize = self._framesize / 2
elif self._comptype == 'ALAW':
scheme = cl.G711_ALAW
self._framesize = self._framesize / 2
else:
raise Error, 'unsupported compression type'
raise Error('unsupported compression type')
self._decomp = cl.OpenDecompressor(scheme)
self._convert = self._decomp_data
else:
Expand Down Expand Up @@ -594,63 +594,63 @@ def __del__(self):
#
def aiff(self):
if self._nframeswritten:
raise Error, 'cannot change parameters after starting to write'
raise Error('cannot change parameters after starting to write')
self._aifc = 0

def aifc(self):
if self._nframeswritten:
raise Error, 'cannot change parameters after starting to write'
raise Error('cannot change parameters after starting to write')
self._aifc = 1

def setnchannels(self, nchannels):
if self._nframeswritten:
raise Error, 'cannot change parameters after starting to write'
raise Error('cannot change parameters after starting to write')
if nchannels < 1:
raise Error, 'bad # of channels'
raise Error('bad # of channels')
self._nchannels = nchannels

def getnchannels(self):
if not self._nchannels:
raise Error, 'number of channels not set'
raise Error('number of channels not set')
return self._nchannels

def setsampwidth(self, sampwidth):
if self._nframeswritten:
raise Error, 'cannot change parameters after starting to write'
raise Error('cannot change parameters after starting to write')
if sampwidth < 1 or sampwidth > 4:
raise Error, 'bad sample width'
raise Error('bad sample width')
self._sampwidth = sampwidth

def getsampwidth(self):
if not self._sampwidth:
raise Error, 'sample width not set'
raise Error('sample width not set')
return self._sampwidth

def setframerate(self, framerate):
if self._nframeswritten:
raise Error, 'cannot change parameters after starting to write'
raise Error('cannot change parameters after starting to write')
if framerate <= 0:
raise Error, 'bad frame rate'
raise Error('bad frame rate')
self._framerate = framerate

def getframerate(self):
if not self._framerate:
raise Error, 'frame rate not set'
raise Error('frame rate not set')
return self._framerate

def setnframes(self, nframes):
if self._nframeswritten:
raise Error, 'cannot change parameters after starting to write'
raise Error('cannot change parameters after starting to write')
self._nframes = nframes

def getnframes(self):
return self._nframeswritten

def setcomptype(self, comptype, compname):
if self._nframeswritten:
raise Error, 'cannot change parameters after starting to write'
raise Error('cannot change parameters after starting to write')
if comptype not in ('NONE', 'ULAW', 'ALAW', 'G722'):
raise Error, 'unsupported compression type'
raise Error('unsupported compression type')
self._comptype = comptype
self._compname = compname

Expand All @@ -668,9 +668,9 @@ def getcompname(self):
def setparams(self, params):
nchannels, sampwidth, framerate, nframes, comptype, compname = params
if self._nframeswritten:
raise Error, 'cannot change parameters after starting to write'
raise Error('cannot change parameters after starting to write')
if comptype not in ('NONE', 'ULAW', 'ALAW', 'G722'):
raise Error, 'unsupported compression type'
raise Error('unsupported compression type')
self.setnchannels(nchannels)
self.setsampwidth(sampwidth)
self.setframerate(framerate)
Expand All @@ -679,17 +679,17 @@ def setparams(self, params):

def getparams(self):
if not self._nchannels or not self._sampwidth or not self._framerate:
raise Error, 'not all parameters set'
raise Error('not all parameters set')
return self._nchannels, self._sampwidth, self._framerate, \
self._nframes, self._comptype, self._compname

def setmark(self, id, pos, name):
if id <= 0:
raise Error, 'marker ID must be > 0'
raise Error('marker ID must be > 0')
if pos < 0:
raise Error, 'marker position must be >= 0'
raise Error('marker position must be >= 0')
if type(name) != type(''):
raise Error, 'marker name must be a string'
raise Error('marker name must be a string')
for i in range(len(self._markers)):
if id == self._markers[i][0]:
self._markers[i] = id, pos, name
Expand All @@ -700,7 +700,7 @@ def getmark(self, id):
for marker in self._markers:
if id == marker[0]:
return marker
raise Error, 'marker %r does not exist' % (id,)
raise Error('marker %r does not exist' % (id,))

def getmarkers(self):
if len(self._markers) == 0:
Expand Down Expand Up @@ -770,18 +770,18 @@ def _ensure_header_written(self, datasize):
if not self._sampwidth:
self._sampwidth = 2
if self._sampwidth != 2:
raise Error, 'sample width must be 2 when compressing with ULAW or ALAW'
raise Error('sample width must be 2 when compressing with ULAW or ALAW')
if self._comptype == 'G722':
if not self._sampwidth:
self._sampwidth = 2
if self._sampwidth != 2:
raise Error, 'sample width must be 2 when compressing with G7.22 (ADPCM)'
raise Error('sample width must be 2 when compressing with G7.22 (ADPCM)')
if not self._nchannels:
raise Error, '# channels not specified'
raise Error('# channels not specified')
if not self._sampwidth:
raise Error, 'sample width not specified'
raise Error('sample width not specified')
if not self._framerate:
raise Error, 'sampling rate not specified'
raise Error('sampling rate not specified')
self._write_header(datasize)

def _init_compression(self):
Expand All @@ -798,13 +798,13 @@ def _init_compression(self):
return
except ImportError:
pass
raise Error, 'cannot write compressed AIFF-C files'
raise Error('cannot write compressed AIFF-C files')
if self._comptype == 'ULAW':
scheme = cl.G711_ULAW
elif self._comptype == 'ALAW':
scheme = cl.G711_ALAW
else:
raise Error, 'unsupported compression type'
raise Error('unsupported compression type')
self._comp = cl.OpenCompressor(scheme)
params = [cl.ORIGINAL_FORMAT, 0,
cl.BITS_PER_COMPONENT, self._sampwidth * 8,
Expand All @@ -816,7 +816,7 @@ def _init_compression(self):
elif self._nchannels == 2:
params[1] = cl.STEREO_INTERLEAVED
else:
raise Error, 'cannot compress more than 2 channels'
raise Error('cannot compress more than 2 channels')
self._comp.SetParams(params)
# the compressor produces a header which we ignore
dummy = self._comp.Compress(0, '')
Expand Down Expand Up @@ -930,7 +930,7 @@ def open(f, mode=None):
elif mode in ('w', 'wb'):
return Aifc_write(f)
else:
raise Error, "mode must be 'r', 'rb', 'w', or 'wb'"
raise Error("mode must be 'r', 'rb', 'w', or 'wb'")

openfp = open # B/W compatibility

Expand Down
6 changes: 3 additions & 3 deletions Lib/anydbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class error(Exception):
_errors.append(_mod.error)

if not _defaultmod:
raise ImportError, "no dbm clone found; tried %s" % _names
raise ImportError("no dbm clone found; tried %s" % _names)

error = tuple(_errors)

Expand All @@ -74,10 +74,10 @@ def open(file, flag = 'r', mode = 0o666):
# flag was used so use default type
mod = _defaultmod
else:
raise error, "need 'c' or 'n' flag to open new db"
raise error("need 'c' or 'n' flag to open new db")
elif result == "":
# db type cannot be determined
raise error, "db type could not be determined"
raise error("db type could not be determined")
else:
mod = __import__(result)
return mod.open(file, flag, mode)
4 changes: 2 additions & 2 deletions Lib/asynchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ def __init__ (self, conn=None):
asyncore.dispatcher.__init__ (self, conn)

def collect_incoming_data(self, data):
raise NotImplementedError, "must be implemented in subclass"
raise NotImplementedError("must be implemented in subclass")

def found_terminator(self):
raise NotImplementedError, "must be implemented in subclass"
raise NotImplementedError("must be implemented in subclass")

def set_terminator (self, term):
"Set the input delimiter. Can be a fixed string of any length, an integer, or None"
Expand Down
2 changes: 1 addition & 1 deletion Lib/asyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def connect(self, address):
self.connected = True
self.handle_connect()
else:
raise socket.error, (err, errorcode[err])
raise socket.error(err, errorcode[err])

def accept(self):
# XXX can return either an address pair or None
Expand Down
2 changes: 1 addition & 1 deletion Lib/bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def break_here(self, frame):
return False

def do_clear(self, arg):
raise NotImplementedError, "subclass of bdb must implement do_clear()"
raise NotImplementedError("subclass of bdb must implement do_clear()")

def break_anywhere(self, frame):
return self.canonic(frame.f_code.co_filename) in self.breaks
Expand Down
Loading

0 comments on commit ce36ad8

Please sign in to comment.