Skip to content

Commit 7bc817d

Browse files
committed
* Mass change: get rid of all init() methods, in favor of __init__()
constructors. There is no backward compatibility. Not everything has been tested. * aiff.{py,doc}: deleted in favor of aifc.py (which contains its docs as comments)
1 parent aa14837 commit 7bc817d

42 files changed

Lines changed: 153 additions & 207 deletions

Some content is hidden

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

Lib/Queue.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ class Queue:
66

77
# Initialize a queue object with a given maximum size
88
# (If maxsize is <= 0, the maximum size is infinite)
9-
def init(self, maxsize):
10-
import thread
9+
def __init__(self, maxsize):
1110
self._init(maxsize)
1211
self.mutex = thread.allocate_lock()
1312
self.esema = thread.allocate_lock()
1413
self.esema.acquire_lock()
1514
self.fsema = thread.allocate_lock()
16-
return self
1715

1816
# Get an approximation of the queue size (not reliable!)
1917
def qsize(self):

Lib/aifc.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,14 @@ def _write_float(f, x):
287287
_write_long(f, lomant)
288288

289289
class Chunk:
290-
def init(self, file):
290+
def __init__(self, file):
291291
self.file = file
292292
self.chunkname = self.file.read(4)
293293
if len(self.chunkname) < 4:
294294
raise EOFError
295295
self.chunksize = _read_long(self.file)
296296
self.size_read = 0
297297
self.offset = self.file.tell()
298-
return self
299298

300299
def rewind(self):
301300
self.file.seek(self.offset, 0)
@@ -333,7 +332,7 @@ class Aifc_read:
333332
# These variables are available to the user though appropriate
334333
# methods of this class:
335334
# _file -- the open file with methods read(), close(), and seek()
336-
# set through the init() ir initfp() method
335+
# set through the __init__() method
337336
# _nchannels -- the number of audio channels
338337
# available through the getnchannels() method
339338
# _nframes -- the number of audio frames
@@ -389,7 +388,7 @@ def initfp(self, file):
389388
#DEBUG: SGI's soundfiler has a bug. There should
390389
# be no need to check for EOF here.
391390
try:
392-
chunk = Chunk().init(self._file)
391+
chunk = Chunk(self._file)
393392
except EOFError:
394393
if formlength == 8:
395394
print 'Warning: FORM chunk size too large'
@@ -433,10 +432,12 @@ def initfp(self, file):
433432
else:
434433
params[3] = 24
435434
self._decomp.SetParams(params)
436-
return self
437435

438-
def init(self, filename):
439-
return self.initfp(builtin.open(filename, 'r'))
436+
def __init__(self, f):
437+
if type(f) == type(''):
438+
f = builtin.open(f, 'r')
439+
# else, assume it is an open file object already
440+
self.initfp(f)
440441

441442
def __del__(self):
442443
if self._file:
@@ -610,7 +611,7 @@ class Aifc_write:
610611
# These variables are user settable through appropriate methods
611612
# of this class:
612613
# _file -- the open file with methods write(), close(), tell(), seek()
613-
# set through the init() or initfp() method
614+
# set through the __init__() method
614615
# _comptype -- the AIFF-C compression type ('NONE' in AIFF)
615616
# set through the setcomptype() or setparams() method
616617
# _compname -- the human-readable AIFF-C compression type
@@ -634,13 +635,15 @@ class Aifc_write:
634635
# _datalength -- the size of the audio samples written to the header
635636
# _datawritten -- the size of the audio samples actually written
636637

637-
def init(self, filename):
638-
self = self.initfp(builtin.open(filename, 'w'))
638+
def __init__(self, f):
639+
if type(f) == type(''):
640+
f = builtin.open(f, 'w')
641+
# else, assume it is an open file object already
642+
self.initfp(f)
639643
if filename[-5:] == '.aiff':
640644
self._aifc = 0
641645
else:
642646
self._aifc = 1
643-
return self
644647

645648
def initfp(self, file):
646649
self._file = file
@@ -659,7 +662,6 @@ def initfp(self, file):
659662
self._markers = []
660663
self._marklength = 0
661664
self._aifc = 1 # AIFF-C is default
662-
return self
663665

664666
def __del__(self):
665667
if self._file:
@@ -976,18 +978,12 @@ def _writemarkers(self):
976978
_write_long(self._file, pos)
977979
_write_string(self._file, name)
978980

979-
def open(filename, mode):
981+
def open(f, mode):
980982
if mode == 'r':
981-
return Aifc_read().init(filename)
983+
return Aifc_read(f)
982984
elif mode == 'w':
983-
return Aifc_write().init(filename)
985+
return Aifc_write(f)
984986
else:
985987
raise Error, 'mode must be \'r\' or \'w\''
986988

987-
def openfp(filep, mode):
988-
if mode == 'r':
989-
return Aifc_read().initfp(filep)
990-
elif mode == 'w':
991-
return Aifc_write().initfp(filep)
992-
else:
993-
raise Error, 'mode must be \'r\' or \'w\''
989+
openfp = open # B/W compatibility

Lib/bdb.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ class Bdb: # Basic Debugger
1515

1616
def __init__(self):
1717
self.breaks = {}
18-
19-
def init(self): # BW compat only
20-
return self
2118

2219
def reset(self):
2320
self.botframe = None

Lib/cmd.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ def __init__(self):
1313
self.prompt = PROMPT
1414
self.identchars = IDENTCHARS
1515
self.lastcmd = ''
16-
17-
def init(self): # BW compat only
18-
return self
1916

2017
def cmdloop(self):
2118
stop = None

Lib/ftplib.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ def __init__(self, *args):
8787
if args[1:]:
8888
apply(self.login, args[1:])
8989

90-
# Old init method (explicitly called by caller)
91-
def init(self, *args):
92-
if args:
93-
apply(self.connect, args)
94-
9590
# Connect to host. Arguments:
9691
# - host: hostname to connect to (default previous host)
9792
# - port: port to connect to (default previous port)
@@ -105,7 +100,7 @@ def connect(self, *args):
105100
self.welcome = self.getresp()
106101

107102
# Get the welcome message from the server
108-
# (this is read and squirreled away by init())
103+
# (this is read and squirreled away by connect())
109104
def getwelcome(self):
110105
if self.debugging: print '*welcome*', `self.welcome`
111106
return self.welcome

Lib/irix5/flp.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ def _unpack_cache(altforms):
9292
forms = {}
9393
for name in altforms.keys():
9494
altobj, altlist = altforms[name]
95-
obj = _newobj().init()
95+
obj = _newobj()
9696
obj.make(altobj)
9797
list = []
9898
for altobj in altlist:
99-
nobj = _newobj().init()
99+
nobj = _newobj()
100100
nobj.make(altobj)
101101
list.append(nobj)
102102
forms[name] = obj, list
@@ -235,8 +235,6 @@ def _parse_fd_form(file, name):
235235
# Internal class: a convient place to store object info fields
236236
#
237237
class _newobj:
238-
def init(self):
239-
return self
240238
def add(self, name, value):
241239
self.__dict__[name] = value
242240
def make(self, dict):
@@ -320,7 +318,7 @@ def _skip_object(file):
320318
file.seek(pos)
321319

322320
def _parse_object(file):
323-
obj = _newobj().init()
321+
obj = _newobj()
324322
while 1:
325323
pos = file.tell()
326324
datum = _parse_1_line(file)

Lib/irix5/readcd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, *arg):
3030
elif len(arg) == 2:
3131
self.player = cd.open(arg[0], arg[1])
3232
else:
33-
raise Error, 'bad init call'
33+
raise Error, 'bad __init__ call'
3434
self.list = []
3535
self.callbacks = [(None, None)] * 8
3636
self.parser = cd.createparser()

Lib/irix5/torgb.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,40 @@
1313

1414
table = {}
1515

16-
t = pipes.Template().init()
16+
t = pipes.Template()
1717
t.append('fromppm $IN $OUT', 'ff')
1818
table['ppm'] = t
1919

20-
t = pipes.Template().init()
20+
t = pipes.Template()
2121
t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
2222
t.append('fromppm $IN $OUT', 'ff')
2323
table['pnm'] = t
2424
table['pgm'] = t
2525
table['pbm'] = t
2626

27-
t = pipes.Template().init()
27+
t = pipes.Template()
2828
t.append('fromgif $IN $OUT', 'ff')
2929
table['gif'] = t
3030

31-
t = pipes.Template().init()
31+
t = pipes.Template()
3232
t.append('tifftopnm', '--')
3333
t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
3434
t.append('fromppm $IN $OUT', 'ff')
3535
table['tiff'] = t
3636

37-
t = pipes.Template().init()
37+
t = pipes.Template()
3838
t.append('rasttopnm', '--')
3939
t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
4040
t.append('fromppm $IN $OUT', 'ff')
4141
table['rast'] = t
4242

43-
t = pipes.Template().init()
43+
t = pipes.Template()
4444
t.append('djpeg', '--')
4545
t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
4646
t.append('fromppm $IN $OUT', 'ff')
4747
table['jpeg'] = t
4848

49-
uncompress = pipes.Template().init()
49+
uncompress = pipes.Template()
5050
uncompress.append('uncompress', '--')
5151

5252

Lib/lib-stdwin/WindowSched.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def delayfunc(msecs):
3535
if event[0] <> WE_TIMER:
3636
mainloop.dispatch(event)
3737

38-
q = sched.scheduler().init(time.millitimer, delayfunc)
38+
q = sched.scheduler(time.millitimer, delayfunc)
3939

4040
# Export functions enter, enterabs and cancel just like a scheduler
4141
#

Lib/lib-stdwin/basewin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

77
class BaseWindow:
88

9-
def init(self, title):
9+
def __init__(self, title):
1010
self.win = stdwin.open(title)
1111
self.win.dispatch = self.dispatch
1212
mainloop.register(self.win)
13-
return self
1413

1514
# def reopen(self):
1615
# title = self.win.gettitle()

0 commit comments

Comments
 (0)