Skip to content

Commit ce36ad8

Browse files
committed
Raise statement normalization in Lib/.
1 parent 8b3febe commit ce36ad8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+502
-530
lines changed

Lib/ConfigParser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def getfloat(self, section, option):
344344
def getboolean(self, section, option):
345345
v = self.get(section, option)
346346
if v.lower() not in self._boolean_states:
347-
raise ValueError, 'Not a boolean: %s' % v
347+
raise ValueError('Not a boolean: %s' % v)
348348
return self._boolean_states[v.lower()]
349349

350350
def optionxform(self, optionstr):

Lib/UserDict.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def setdefault(self, key, default=None):
127127
return default
128128
def pop(self, key, *args):
129129
if len(args) > 1:
130-
raise TypeError, "pop expected at most 2 arguments, got "\
131-
+ repr(1 + len(args))
130+
raise TypeError("pop expected at most 2 arguments, got "
131+
+ repr(1 + len(args)))
132132
try:
133133
value = self[key]
134134
except KeyError:
@@ -141,7 +141,7 @@ def popitem(self):
141141
try:
142142
k, v = next(self.iteritems())
143143
except StopIteration:
144-
raise KeyError, 'container is empty'
144+
raise KeyError('container is empty')
145145
del self[k]
146146
return (k, v)
147147
def update(self, other=None, **kwargs):

Lib/UserString.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class MutableString(UserString):
183183
def __init__(self, string=""):
184184
self.data = string
185185
def __hash__(self):
186-
raise TypeError, "unhashable type (it is mutable)"
186+
raise TypeError("unhashable type (it is mutable)")
187187
def __setitem__(self, index, sub):
188188
if isinstance(index, slice):
189189
if isinstance(sub, UserString):

Lib/aifc.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,14 @@ def initfp(self, file):
287287
self._soundpos = 0
288288
self._file = Chunk(file)
289289
if self._file.getname() != 'FORM':
290-
raise Error, 'file does not start with FORM id'
290+
raise Error('file does not start with FORM id')
291291
formdata = self._file.read(4)
292292
if formdata == 'AIFF':
293293
self._aifc = 0
294294
elif formdata == 'AIFC':
295295
self._aifc = 1
296296
else:
297-
raise Error, 'not an AIFF or AIFF-C file'
297+
raise Error('not an AIFF or AIFF-C file')
298298
self._comm_chunk_read = 0
299299
while 1:
300300
self._ssnd_seek_needed = 1
@@ -317,10 +317,10 @@ def initfp(self, file):
317317
elif chunkname in _skiplist:
318318
pass
319319
else:
320-
raise Error, 'unrecognized chunk type '+chunk.chunkname
320+
raise Error('unrecognized chunk type '+chunk.chunkname)
321321
chunk.skip()
322322
if not self._comm_chunk_read or not self._ssnd_chunk:
323-
raise Error, 'COMM chunk and/or SSND chunk missing'
323+
raise Error('COMM chunk and/or SSND chunk missing')
324324
if self._aifc and self._decomp:
325325
import cl
326326
params = [cl.ORIGINAL_FORMAT, 0,
@@ -331,7 +331,7 @@ def initfp(self, file):
331331
elif self._nchannels == 2:
332332
params[1] = cl.STEREO_INTERLEAVED
333333
else:
334-
raise Error, 'cannot compress more than 2 channels'
334+
raise Error('cannot compress more than 2 channels')
335335
self._decomp.SetParams(params)
336336

337337
def __init__(self, f):
@@ -394,11 +394,11 @@ def getmark(self, id):
394394
for marker in self._markers:
395395
if id == marker[0]:
396396
return marker
397-
raise Error, 'marker %r does not exist' % (id,)
397+
raise Error('marker %r does not exist' % (id,))
398398

399399
def setpos(self, pos):
400400
if pos < 0 or pos > self._nframes:
401-
raise Error, 'position not in range'
401+
raise Error('position not in range')
402402
self._soundpos = pos
403403
self._ssnd_seek_needed = 1
404404

@@ -488,15 +488,15 @@ def _read_comm_chunk(self, chunk):
488488
return
489489
except ImportError:
490490
pass
491-
raise Error, 'cannot read compressed AIFF-C files'
491+
raise Error('cannot read compressed AIFF-C files')
492492
if self._comptype == 'ULAW':
493493
scheme = cl.G711_ULAW
494494
self._framesize = self._framesize / 2
495495
elif self._comptype == 'ALAW':
496496
scheme = cl.G711_ALAW
497497
self._framesize = self._framesize / 2
498498
else:
499-
raise Error, 'unsupported compression type'
499+
raise Error('unsupported compression type')
500500
self._decomp = cl.OpenDecompressor(scheme)
501501
self._convert = self._decomp_data
502502
else:
@@ -594,63 +594,63 @@ def __del__(self):
594594
#
595595
def aiff(self):
596596
if self._nframeswritten:
597-
raise Error, 'cannot change parameters after starting to write'
597+
raise Error('cannot change parameters after starting to write')
598598
self._aifc = 0
599599

600600
def aifc(self):
601601
if self._nframeswritten:
602-
raise Error, 'cannot change parameters after starting to write'
602+
raise Error('cannot change parameters after starting to write')
603603
self._aifc = 1
604604

605605
def setnchannels(self, nchannels):
606606
if self._nframeswritten:
607-
raise Error, 'cannot change parameters after starting to write'
607+
raise Error('cannot change parameters after starting to write')
608608
if nchannels < 1:
609-
raise Error, 'bad # of channels'
609+
raise Error('bad # of channels')
610610
self._nchannels = nchannels
611611

612612
def getnchannels(self):
613613
if not self._nchannels:
614-
raise Error, 'number of channels not set'
614+
raise Error('number of channels not set')
615615
return self._nchannels
616616

617617
def setsampwidth(self, sampwidth):
618618
if self._nframeswritten:
619-
raise Error, 'cannot change parameters after starting to write'
619+
raise Error('cannot change parameters after starting to write')
620620
if sampwidth < 1 or sampwidth > 4:
621-
raise Error, 'bad sample width'
621+
raise Error('bad sample width')
622622
self._sampwidth = sampwidth
623623

624624
def getsampwidth(self):
625625
if not self._sampwidth:
626-
raise Error, 'sample width not set'
626+
raise Error('sample width not set')
627627
return self._sampwidth
628628

629629
def setframerate(self, framerate):
630630
if self._nframeswritten:
631-
raise Error, 'cannot change parameters after starting to write'
631+
raise Error('cannot change parameters after starting to write')
632632
if framerate <= 0:
633-
raise Error, 'bad frame rate'
633+
raise Error('bad frame rate')
634634
self._framerate = framerate
635635

636636
def getframerate(self):
637637
if not self._framerate:
638-
raise Error, 'frame rate not set'
638+
raise Error('frame rate not set')
639639
return self._framerate
640640

641641
def setnframes(self, nframes):
642642
if self._nframeswritten:
643-
raise Error, 'cannot change parameters after starting to write'
643+
raise Error('cannot change parameters after starting to write')
644644
self._nframes = nframes
645645

646646
def getnframes(self):
647647
return self._nframeswritten
648648

649649
def setcomptype(self, comptype, compname):
650650
if self._nframeswritten:
651-
raise Error, 'cannot change parameters after starting to write'
651+
raise Error('cannot change parameters after starting to write')
652652
if comptype not in ('NONE', 'ULAW', 'ALAW', 'G722'):
653-
raise Error, 'unsupported compression type'
653+
raise Error('unsupported compression type')
654654
self._comptype = comptype
655655
self._compname = compname
656656

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

680680
def getparams(self):
681681
if not self._nchannels or not self._sampwidth or not self._framerate:
682-
raise Error, 'not all parameters set'
682+
raise Error('not all parameters set')
683683
return self._nchannels, self._sampwidth, self._framerate, \
684684
self._nframes, self._comptype, self._compname
685685

686686
def setmark(self, id, pos, name):
687687
if id <= 0:
688-
raise Error, 'marker ID must be > 0'
688+
raise Error('marker ID must be > 0')
689689
if pos < 0:
690-
raise Error, 'marker position must be >= 0'
690+
raise Error('marker position must be >= 0')
691691
if type(name) != type(''):
692-
raise Error, 'marker name must be a string'
692+
raise Error('marker name must be a string')
693693
for i in range(len(self._markers)):
694694
if id == self._markers[i][0]:
695695
self._markers[i] = id, pos, name
@@ -700,7 +700,7 @@ def getmark(self, id):
700700
for marker in self._markers:
701701
if id == marker[0]:
702702
return marker
703-
raise Error, 'marker %r does not exist' % (id,)
703+
raise Error('marker %r does not exist' % (id,))
704704

705705
def getmarkers(self):
706706
if len(self._markers) == 0:
@@ -770,18 +770,18 @@ def _ensure_header_written(self, datasize):
770770
if not self._sampwidth:
771771
self._sampwidth = 2
772772
if self._sampwidth != 2:
773-
raise Error, 'sample width must be 2 when compressing with ULAW or ALAW'
773+
raise Error('sample width must be 2 when compressing with ULAW or ALAW')
774774
if self._comptype == 'G722':
775775
if not self._sampwidth:
776776
self._sampwidth = 2
777777
if self._sampwidth != 2:
778-
raise Error, 'sample width must be 2 when compressing with G7.22 (ADPCM)'
778+
raise Error('sample width must be 2 when compressing with G7.22 (ADPCM)')
779779
if not self._nchannels:
780-
raise Error, '# channels not specified'
780+
raise Error('# channels not specified')
781781
if not self._sampwidth:
782-
raise Error, 'sample width not specified'
782+
raise Error('sample width not specified')
783783
if not self._framerate:
784-
raise Error, 'sampling rate not specified'
784+
raise Error('sampling rate not specified')
785785
self._write_header(datasize)
786786

787787
def _init_compression(self):
@@ -798,13 +798,13 @@ def _init_compression(self):
798798
return
799799
except ImportError:
800800
pass
801-
raise Error, 'cannot write compressed AIFF-C files'
801+
raise Error('cannot write compressed AIFF-C files')
802802
if self._comptype == 'ULAW':
803803
scheme = cl.G711_ULAW
804804
elif self._comptype == 'ALAW':
805805
scheme = cl.G711_ALAW
806806
else:
807-
raise Error, 'unsupported compression type'
807+
raise Error('unsupported compression type')
808808
self._comp = cl.OpenCompressor(scheme)
809809
params = [cl.ORIGINAL_FORMAT, 0,
810810
cl.BITS_PER_COMPONENT, self._sampwidth * 8,
@@ -816,7 +816,7 @@ def _init_compression(self):
816816
elif self._nchannels == 2:
817817
params[1] = cl.STEREO_INTERLEAVED
818818
else:
819-
raise Error, 'cannot compress more than 2 channels'
819+
raise Error('cannot compress more than 2 channels')
820820
self._comp.SetParams(params)
821821
# the compressor produces a header which we ignore
822822
dummy = self._comp.Compress(0, '')
@@ -930,7 +930,7 @@ def open(f, mode=None):
930930
elif mode in ('w', 'wb'):
931931
return Aifc_write(f)
932932
else:
933-
raise Error, "mode must be 'r', 'rb', 'w', or 'wb'"
933+
raise Error("mode must be 'r', 'rb', 'w', or 'wb'")
934934

935935
openfp = open # B/W compatibility
936936

Lib/anydbm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class error(Exception):
5959
_errors.append(_mod.error)
6060

6161
if not _defaultmod:
62-
raise ImportError, "no dbm clone found; tried %s" % _names
62+
raise ImportError("no dbm clone found; tried %s" % _names)
6363

6464
error = tuple(_errors)
6565

@@ -74,10 +74,10 @@ def open(file, flag = 'r', mode = 0o666):
7474
# flag was used so use default type
7575
mod = _defaultmod
7676
else:
77-
raise error, "need 'c' or 'n' flag to open new db"
77+
raise error("need 'c' or 'n' flag to open new db")
7878
elif result == "":
7979
# db type cannot be determined
80-
raise error, "db type could not be determined"
80+
raise error("db type could not be determined")
8181
else:
8282
mod = __import__(result)
8383
return mod.open(file, flag, mode)

Lib/asynchat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ def __init__ (self, conn=None):
6666
asyncore.dispatcher.__init__ (self, conn)
6767

6868
def collect_incoming_data(self, data):
69-
raise NotImplementedError, "must be implemented in subclass"
69+
raise NotImplementedError("must be implemented in subclass")
7070

7171
def found_terminator(self):
72-
raise NotImplementedError, "must be implemented in subclass"
72+
raise NotImplementedError("must be implemented in subclass")
7373

7474
def set_terminator (self, term):
7575
"Set the input delimiter. Can be a fixed string of any length, an integer, or None"

Lib/asyncore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def connect(self, address):
313313
self.connected = True
314314
self.handle_connect()
315315
else:
316-
raise socket.error, (err, errorcode[err])
316+
raise socket.error(err, errorcode[err])
317317

318318
def accept(self):
319319
# XXX can return either an address pair or None

Lib/bdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def break_here(self, frame):
130130
return False
131131

132132
def do_clear(self, arg):
133-
raise NotImplementedError, "subclass of bdb must implement do_clear()"
133+
raise NotImplementedError("subclass of bdb must implement do_clear()")
134134

135135
def break_anywhere(self, frame):
136136
return self.canonic(frame.f_code.co_filename) in self.breaks

0 commit comments

Comments
 (0)