Skip to content

Commit

Permalink
* Mass change: get rid of all init() methods, in favor of __init__()
Browse files Browse the repository at this point in the history
  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)
  • Loading branch information
gvanrossum committed Dec 17, 1993
1 parent aa14837 commit 7bc817d
Show file tree
Hide file tree
Showing 42 changed files with 153 additions and 207 deletions.
4 changes: 1 addition & 3 deletions Lib/Queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ class Queue:

# Initialize a queue object with a given maximum size
# (If maxsize is <= 0, the maximum size is infinite)
def init(self, maxsize):
import thread
def __init__(self, maxsize):
self._init(maxsize)
self.mutex = thread.allocate_lock()
self.esema = thread.allocate_lock()
self.esema.acquire_lock()
self.fsema = thread.allocate_lock()
return self

# Get an approximation of the queue size (not reliable!)
def qsize(self):
Expand Down
40 changes: 18 additions & 22 deletions Lib/aifc.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,14 @@ def _write_float(f, x):
_write_long(f, lomant)

class Chunk:
def init(self, file):
def __init__(self, file):
self.file = file
self.chunkname = self.file.read(4)
if len(self.chunkname) < 4:
raise EOFError
self.chunksize = _read_long(self.file)
self.size_read = 0
self.offset = self.file.tell()
return self

def rewind(self):
self.file.seek(self.offset, 0)
Expand Down Expand Up @@ -333,7 +332,7 @@ class Aifc_read:
# These variables are available to the user though appropriate
# methods of this class:
# _file -- the open file with methods read(), close(), and seek()
# set through the init() ir initfp() method
# set through the __init__() method
# _nchannels -- the number of audio channels
# available through the getnchannels() method
# _nframes -- the number of audio frames
Expand Down Expand Up @@ -389,7 +388,7 @@ def initfp(self, file):
#DEBUG: SGI's soundfiler has a bug. There should
# be no need to check for EOF here.
try:
chunk = Chunk().init(self._file)
chunk = Chunk(self._file)
except EOFError:
if formlength == 8:
print 'Warning: FORM chunk size too large'
Expand Down Expand Up @@ -433,10 +432,12 @@ def initfp(self, file):
else:
params[3] = 24
self._decomp.SetParams(params)
return self

def init(self, filename):
return self.initfp(builtin.open(filename, 'r'))
def __init__(self, f):
if type(f) == type(''):
f = builtin.open(f, 'r')
# else, assume it is an open file object already
self.initfp(f)

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

def init(self, filename):
self = self.initfp(builtin.open(filename, 'w'))
def __init__(self, f):
if type(f) == type(''):
f = builtin.open(f, 'w')
# else, assume it is an open file object already
self.initfp(f)
if filename[-5:] == '.aiff':
self._aifc = 0
else:
self._aifc = 1
return self

def initfp(self, file):
self._file = file
Expand All @@ -659,7 +662,6 @@ def initfp(self, file):
self._markers = []
self._marklength = 0
self._aifc = 1 # AIFF-C is default
return self

def __del__(self):
if self._file:
Expand Down Expand Up @@ -976,18 +978,12 @@ def _writemarkers(self):
_write_long(self._file, pos)
_write_string(self._file, name)

def open(filename, mode):
def open(f, mode):
if mode == 'r':
return Aifc_read().init(filename)
return Aifc_read(f)
elif mode == 'w':
return Aifc_write().init(filename)
return Aifc_write(f)
else:
raise Error, 'mode must be \'r\' or \'w\''

def openfp(filep, mode):
if mode == 'r':
return Aifc_read().initfp(filep)
elif mode == 'w':
return Aifc_write().initfp(filep)
else:
raise Error, 'mode must be \'r\' or \'w\''
openfp = open # B/W compatibility
3 changes: 0 additions & 3 deletions Lib/bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ class Bdb: # Basic Debugger

def __init__(self):
self.breaks = {}

def init(self): # BW compat only
return self

def reset(self):
self.botframe = None
Expand Down
3 changes: 0 additions & 3 deletions Lib/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ def __init__(self):
self.prompt = PROMPT
self.identchars = IDENTCHARS
self.lastcmd = ''

def init(self): # BW compat only
return self

def cmdloop(self):
stop = None
Expand Down
7 changes: 1 addition & 6 deletions Lib/ftplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ def __init__(self, *args):
if args[1:]:
apply(self.login, args[1:])

# Old init method (explicitly called by caller)
def init(self, *args):
if args:
apply(self.connect, args)

# Connect to host. Arguments:
# - host: hostname to connect to (default previous host)
# - port: port to connect to (default previous port)
Expand All @@ -105,7 +100,7 @@ def connect(self, *args):
self.welcome = self.getresp()

# Get the welcome message from the server
# (this is read and squirreled away by init())
# (this is read and squirreled away by connect())
def getwelcome(self):
if self.debugging: print '*welcome*', `self.welcome`
return self.welcome
Expand Down
8 changes: 3 additions & 5 deletions Lib/irix5/flp.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ def _unpack_cache(altforms):
forms = {}
for name in altforms.keys():
altobj, altlist = altforms[name]
obj = _newobj().init()
obj = _newobj()
obj.make(altobj)
list = []
for altobj in altlist:
nobj = _newobj().init()
nobj = _newobj()
nobj.make(altobj)
list.append(nobj)
forms[name] = obj, list
Expand Down Expand Up @@ -235,8 +235,6 @@ def _parse_fd_form(file, name):
# Internal class: a convient place to store object info fields
#
class _newobj:
def init(self):
return self
def add(self, name, value):
self.__dict__[name] = value
def make(self, dict):
Expand Down Expand Up @@ -320,7 +318,7 @@ def _skip_object(file):
file.seek(pos)

def _parse_object(file):
obj = _newobj().init()
obj = _newobj()
while 1:
pos = file.tell()
datum = _parse_1_line(file)
Expand Down
2 changes: 1 addition & 1 deletion Lib/irix5/readcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, *arg):
elif len(arg) == 2:
self.player = cd.open(arg[0], arg[1])
else:
raise Error, 'bad init call'
raise Error, 'bad __init__ call'
self.list = []
self.callbacks = [(None, None)] * 8
self.parser = cd.createparser()
Expand Down
14 changes: 7 additions & 7 deletions Lib/irix5/torgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,40 @@

table = {}

t = pipes.Template().init()
t = pipes.Template()
t.append('fromppm $IN $OUT', 'ff')
table['ppm'] = t

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

t = pipes.Template().init()
t = pipes.Template()
t.append('fromgif $IN $OUT', 'ff')
table['gif'] = t

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

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

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

uncompress = pipes.Template().init()
uncompress = pipes.Template()
uncompress.append('uncompress', '--')


Expand Down
2 changes: 1 addition & 1 deletion Lib/lib-stdwin/WindowSched.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def delayfunc(msecs):
if event[0] <> WE_TIMER:
mainloop.dispatch(event)

q = sched.scheduler().init(time.millitimer, delayfunc)
q = sched.scheduler(time.millitimer, delayfunc)

# Export functions enter, enterabs and cancel just like a scheduler
#
Expand Down
3 changes: 1 addition & 2 deletions Lib/lib-stdwin/basewin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

class BaseWindow:

def init(self, title):
def __init__(self, title):
self.win = stdwin.open(title)
self.win.dispatch = self.dispatch
mainloop.register(self.win)
return self

# def reopen(self):
# title = self.win.gettitle()
Expand Down
5 changes: 2 additions & 3 deletions Lib/lib-stdwin/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class formatter:
# Pass the window's drawing object, and left, top, right
# coordinates of the drawing space as arguments.
#
def init(self, d, left, top, right):
def __init__(self, d, left, top, right):
self.d = d # Drawing object
self.left = left # Left margin
self.right = right # Right margin
Expand All @@ -22,7 +22,6 @@ def init(self, d, left, top, right):
self.justify = 1
self.setfont('') # Default font
self._reset() # Prepare for new line
return self
#
# Reset for start of fresh line.
#
Expand Down Expand Up @@ -190,7 +189,7 @@ def test():
w.change((0, 0), (1000, 1000))
elif type == WE_DRAW:
width, height = winsize
f = formatter().init(w.begindrawing(), 0, 0, width)
f = formatter(w.begindrawing(), 0, 0, width)
f.center = center
f.justify = justify
if not center:
Expand Down
3 changes: 1 addition & 2 deletions Lib/lib-stdwin/mainloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,10 @@ def dispatch(event):
#
class Dialog:
#
def init(self, title):
def __init__(self, title):
self.window = stdwin.open(title)
self.window.dispatch = self.dispatch
register(self.window)
return self
#
def close(self):
unregister(self.window)
Expand Down
11 changes: 5 additions & 6 deletions Lib/lib-stdwin/srcwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class TextWindow(basewin.BaseWindow):

def init(self, title, contents):
def __init__(self, title, contents):
self.contents = contents
self.linecount = countlines(self.contents)
#
Expand All @@ -23,11 +23,10 @@ def init(self, title, contents):
width = WIDTH*stdwin.textwidth('0')
height = lh*min(MAXHEIGHT, self.linecount)
stdwin.setdefwinsize(width, height)
self = basewin.BaseWindow.init(self, title)
basewin.BaseWindow.__init__(self, title)
#
self.win.setdocsize(0, self.bottom)
self.initeditor()
return self

def initeditor(self):
r = (self.leftmargin, self.top), (self.rightmargin, self.bottom)
Expand Down Expand Up @@ -113,18 +112,18 @@ def countlines(text):

class SourceWindow(TextWindow):

def init(self, filename):
def __init__(self, filename):
self.filename = filename
f = open(self.filename, 'r')
contents = f.read()
f.close()
return TextWindow.init(self, self.filename, contents)
TextWindow.__init__(self, self.filename, contents)

# ------------------------------ testing ------------------------------

TESTFILE = 'srcwin.py'

def test():
import mainloop
sw = SourceWindow().init(TESTFILE)
sw = SourceWindow(TESTFILE)
mainloop.mainloop()
Loading

0 comments on commit 7bc817d

Please sign in to comment.