Commit 7bc817d5 authored by Guido van Rossum's avatar Guido van Rossum

* 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)
parent aa14837b
...@@ -6,14 +6,12 @@ class Queue: ...@@ -6,14 +6,12 @@ class Queue:
# Initialize a queue object with a given maximum size # Initialize a queue object with a given maximum size
# (If maxsize is <= 0, the maximum size is infinite) # (If maxsize is <= 0, the maximum size is infinite)
def init(self, maxsize): def __init__(self, maxsize):
import thread
self._init(maxsize) self._init(maxsize)
self.mutex = thread.allocate_lock() self.mutex = thread.allocate_lock()
self.esema = thread.allocate_lock() self.esema = thread.allocate_lock()
self.esema.acquire_lock() self.esema.acquire_lock()
self.fsema = thread.allocate_lock() self.fsema = thread.allocate_lock()
return self
# Get an approximation of the queue size (not reliable!) # Get an approximation of the queue size (not reliable!)
def qsize(self): def qsize(self):
......
...@@ -287,7 +287,7 @@ def _write_float(f, x): ...@@ -287,7 +287,7 @@ def _write_float(f, x):
_write_long(f, lomant) _write_long(f, lomant)
class Chunk: class Chunk:
def init(self, file): def __init__(self, file):
self.file = file self.file = file
self.chunkname = self.file.read(4) self.chunkname = self.file.read(4)
if len(self.chunkname) < 4: if len(self.chunkname) < 4:
...@@ -295,7 +295,6 @@ class Chunk: ...@@ -295,7 +295,6 @@ class Chunk:
self.chunksize = _read_long(self.file) self.chunksize = _read_long(self.file)
self.size_read = 0 self.size_read = 0
self.offset = self.file.tell() self.offset = self.file.tell()
return self
def rewind(self): def rewind(self):
self.file.seek(self.offset, 0) self.file.seek(self.offset, 0)
...@@ -333,7 +332,7 @@ class Aifc_read: ...@@ -333,7 +332,7 @@ class Aifc_read:
# These variables are available to the user though appropriate # These variables are available to the user though appropriate
# methods of this class: # methods of this class:
# _file -- the open file with methods read(), close(), and seek() # _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 # _nchannels -- the number of audio channels
# available through the getnchannels() method # available through the getnchannels() method
# _nframes -- the number of audio frames # _nframes -- the number of audio frames
...@@ -389,7 +388,7 @@ class Aifc_read: ...@@ -389,7 +388,7 @@ class Aifc_read:
#DEBUG: SGI's soundfiler has a bug. There should #DEBUG: SGI's soundfiler has a bug. There should
# be no need to check for EOF here. # be no need to check for EOF here.
try: try:
chunk = Chunk().init(self._file) chunk = Chunk(self._file)
except EOFError: except EOFError:
if formlength == 8: if formlength == 8:
print 'Warning: FORM chunk size too large' print 'Warning: FORM chunk size too large'
...@@ -433,10 +432,12 @@ class Aifc_read: ...@@ -433,10 +432,12 @@ class Aifc_read:
else: else:
params[3] = 24 params[3] = 24
self._decomp.SetParams(params) self._decomp.SetParams(params)
return self
def init(self, filename): def __init__(self, f):
return self.initfp(builtin.open(filename, 'r')) if type(f) == type(''):
f = builtin.open(f, 'r')
# else, assume it is an open file object already
self.initfp(f)
def __del__(self): def __del__(self):
if self._file: if self._file:
...@@ -610,7 +611,7 @@ class Aifc_write: ...@@ -610,7 +611,7 @@ class Aifc_write:
# These variables are user settable through appropriate methods # These variables are user settable through appropriate methods
# of this class: # of this class:
# _file -- the open file with methods write(), close(), tell(), seek() # _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) # _comptype -- the AIFF-C compression type ('NONE' in AIFF)
# set through the setcomptype() or setparams() method # set through the setcomptype() or setparams() method
# _compname -- the human-readable AIFF-C compression type # _compname -- the human-readable AIFF-C compression type
...@@ -634,13 +635,15 @@ class Aifc_write: ...@@ -634,13 +635,15 @@ class Aifc_write:
# _datalength -- the size of the audio samples written to the header # _datalength -- the size of the audio samples written to the header
# _datawritten -- the size of the audio samples actually written # _datawritten -- the size of the audio samples actually written
def init(self, filename): def __init__(self, f):
self = self.initfp(builtin.open(filename, 'w')) 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': if filename[-5:] == '.aiff':
self._aifc = 0 self._aifc = 0
else: else:
self._aifc = 1 self._aifc = 1
return self
def initfp(self, file): def initfp(self, file):
self._file = file self._file = file
...@@ -659,7 +662,6 @@ class Aifc_write: ...@@ -659,7 +662,6 @@ class Aifc_write:
self._markers = [] self._markers = []
self._marklength = 0 self._marklength = 0
self._aifc = 1 # AIFF-C is default self._aifc = 1 # AIFF-C is default
return self
def __del__(self): def __del__(self):
if self._file: if self._file:
...@@ -976,18 +978,12 @@ class Aifc_write: ...@@ -976,18 +978,12 @@ class Aifc_write:
_write_long(self._file, pos) _write_long(self._file, pos)
_write_string(self._file, name) _write_string(self._file, name)
def open(filename, mode): def open(f, mode):
if mode == 'r': if mode == 'r':
return Aifc_read().init(filename) return Aifc_read(f)
elif mode == 'w': elif mode == 'w':
return Aifc_write().init(filename) return Aifc_write(f)
else: else:
raise Error, 'mode must be \'r\' or \'w\'' raise Error, 'mode must be \'r\' or \'w\''
def openfp(filep, mode): openfp = open # B/W compatibility
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\''
...@@ -16,9 +16,6 @@ class Bdb: # Basic Debugger ...@@ -16,9 +16,6 @@ class Bdb: # Basic Debugger
def __init__(self): def __init__(self):
self.breaks = {} self.breaks = {}
def init(self): # BW compat only
return self
def reset(self): def reset(self):
self.botframe = None self.botframe = None
self.stopframe = None self.stopframe = None
......
...@@ -14,9 +14,6 @@ class Cmd: ...@@ -14,9 +14,6 @@ class Cmd:
self.identchars = IDENTCHARS self.identchars = IDENTCHARS
self.lastcmd = '' self.lastcmd = ''
def init(self): # BW compat only
return self
def cmdloop(self): def cmdloop(self):
stop = None stop = None
while not stop: while not stop:
......
...@@ -87,11 +87,6 @@ class FTP: ...@@ -87,11 +87,6 @@ class FTP:
if args[1:]: if args[1:]:
apply(self.login, 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: # Connect to host. Arguments:
# - host: hostname to connect to (default previous host) # - host: hostname to connect to (default previous host)
# - port: port to connect to (default previous port) # - port: port to connect to (default previous port)
...@@ -105,7 +100,7 @@ class FTP: ...@@ -105,7 +100,7 @@ class FTP:
self.welcome = self.getresp() self.welcome = self.getresp()
# Get the welcome message from the server # 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): def getwelcome(self):
if self.debugging: print '*welcome*', `self.welcome` if self.debugging: print '*welcome*', `self.welcome`
return self.welcome return self.welcome
......
...@@ -92,11 +92,11 @@ def _unpack_cache(altforms): ...@@ -92,11 +92,11 @@ def _unpack_cache(altforms):
forms = {} forms = {}
for name in altforms.keys(): for name in altforms.keys():
altobj, altlist = altforms[name] altobj, altlist = altforms[name]
obj = _newobj().init() obj = _newobj()
obj.make(altobj) obj.make(altobj)
list = [] list = []
for altobj in altlist: for altobj in altlist:
nobj = _newobj().init() nobj = _newobj()
nobj.make(altobj) nobj.make(altobj)
list.append(nobj) list.append(nobj)
forms[name] = obj, list forms[name] = obj, list
...@@ -235,8 +235,6 @@ def _parse_fd_form(file, name): ...@@ -235,8 +235,6 @@ def _parse_fd_form(file, name):
# Internal class: a convient place to store object info fields # Internal class: a convient place to store object info fields
# #
class _newobj: class _newobj:
def init(self):
return self
def add(self, name, value): def add(self, name, value):
self.__dict__[name] = value self.__dict__[name] = value
def make(self, dict): def make(self, dict):
...@@ -320,7 +318,7 @@ def _skip_object(file): ...@@ -320,7 +318,7 @@ def _skip_object(file):
file.seek(pos) file.seek(pos)
def _parse_object(file): def _parse_object(file):
obj = _newobj().init() obj = _newobj()
while 1: while 1:
pos = file.tell() pos = file.tell()
datum = _parse_1_line(file) datum = _parse_1_line(file)
......
...@@ -30,7 +30,7 @@ class Readcd: ...@@ -30,7 +30,7 @@ class Readcd:
elif len(arg) == 2: elif len(arg) == 2:
self.player = cd.open(arg[0], arg[1]) self.player = cd.open(arg[0], arg[1])
else: else:
raise Error, 'bad init call' raise Error, 'bad __init__ call'
self.list = [] self.list = []
self.callbacks = [(None, None)] * 8 self.callbacks = [(None, None)] * 8
self.parser = cd.createparser() self.parser = cd.createparser()
......
...@@ -13,40 +13,40 @@ import imghdr ...@@ -13,40 +13,40 @@ import imghdr
table = {} table = {}
t = pipes.Template().init() t = pipes.Template()
t.append('fromppm $IN $OUT', 'ff') t.append('fromppm $IN $OUT', 'ff')
table['ppm'] = t table['ppm'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--') t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
t.append('fromppm $IN $OUT', 'ff') t.append('fromppm $IN $OUT', 'ff')
table['pnm'] = t table['pnm'] = t
table['pgm'] = t table['pgm'] = t
table['pbm'] = t table['pbm'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('fromgif $IN $OUT', 'ff') t.append('fromgif $IN $OUT', 'ff')
table['gif'] = t table['gif'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('tifftopnm', '--') t.append('tifftopnm', '--')
t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--') t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
t.append('fromppm $IN $OUT', 'ff') t.append('fromppm $IN $OUT', 'ff')
table['tiff'] = t table['tiff'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('rasttopnm', '--') t.append('rasttopnm', '--')
t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--') t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
t.append('fromppm $IN $OUT', 'ff') t.append('fromppm $IN $OUT', 'ff')
table['rast'] = t table['rast'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('djpeg', '--') t.append('djpeg', '--')
t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--') t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
t.append('fromppm $IN $OUT', 'ff') t.append('fromppm $IN $OUT', 'ff')
table['jpeg'] = t table['jpeg'] = t
uncompress = pipes.Template().init() uncompress = pipes.Template()
uncompress.append('uncompress', '--') uncompress.append('uncompress', '--')
......
...@@ -35,7 +35,7 @@ def delayfunc(msecs): ...@@ -35,7 +35,7 @@ def delayfunc(msecs):
if event[0] <> WE_TIMER: if event[0] <> WE_TIMER:
mainloop.dispatch(event) 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 # Export functions enter, enterabs and cancel just like a scheduler
# #
......
...@@ -6,11 +6,10 @@ from stdwinevents import * ...@@ -6,11 +6,10 @@ from stdwinevents import *
class BaseWindow: class BaseWindow:
def init(self, title): def __init__(self, title):
self.win = stdwin.open(title) self.win = stdwin.open(title)
self.win.dispatch = self.dispatch self.win.dispatch = self.dispatch
mainloop.register(self.win) mainloop.register(self.win)
return self
# def reopen(self): # def reopen(self):
# title = self.win.gettitle() # title = self.win.gettitle()
......
...@@ -13,7 +13,7 @@ class formatter: ...@@ -13,7 +13,7 @@ class formatter:
# Pass the window's drawing object, and left, top, right # Pass the window's drawing object, and left, top, right
# coordinates of the drawing space as arguments. # 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.d = d # Drawing object
self.left = left # Left margin self.left = left # Left margin
self.right = right # Right margin self.right = right # Right margin
...@@ -22,7 +22,6 @@ class formatter: ...@@ -22,7 +22,6 @@ class formatter:
self.justify = 1 self.justify = 1
self.setfont('') # Default font self.setfont('') # Default font
self._reset() # Prepare for new line self._reset() # Prepare for new line
return self
# #
# Reset for start of fresh line. # Reset for start of fresh line.
# #
...@@ -190,7 +189,7 @@ def test(): ...@@ -190,7 +189,7 @@ def test():
w.change((0, 0), (1000, 1000)) w.change((0, 0), (1000, 1000))
elif type == WE_DRAW: elif type == WE_DRAW:
width, height = winsize width, height = winsize
f = formatter().init(w.begindrawing(), 0, 0, width) f = formatter(w.begindrawing(), 0, 0, width)
f.center = center f.center = center
f.justify = justify f.justify = justify
if not center: if not center:
......
...@@ -224,11 +224,10 @@ def dispatch(event): ...@@ -224,11 +224,10 @@ def dispatch(event):
# #
class Dialog: class Dialog:
# #
def init(self, title): def __init__(self, title):
self.window = stdwin.open(title) self.window = stdwin.open(title)
self.window.dispatch = self.dispatch self.window.dispatch = self.dispatch
register(self.window) register(self.window)
return self
# #
def close(self): def close(self):
unregister(self.window) unregister(self.window)
......
...@@ -10,7 +10,7 @@ MAXHEIGHT = 24 ...@@ -10,7 +10,7 @@ MAXHEIGHT = 24
class TextWindow(basewin.BaseWindow): class TextWindow(basewin.BaseWindow):
def init(self, title, contents): def __init__(self, title, contents):
self.contents = contents self.contents = contents
self.linecount = countlines(self.contents) self.linecount = countlines(self.contents)
# #
...@@ -23,11 +23,10 @@ class TextWindow(basewin.BaseWindow): ...@@ -23,11 +23,10 @@ class TextWindow(basewin.BaseWindow):
width = WIDTH*stdwin.textwidth('0') width = WIDTH*stdwin.textwidth('0')
height = lh*min(MAXHEIGHT, self.linecount) height = lh*min(MAXHEIGHT, self.linecount)
stdwin.setdefwinsize(width, height) stdwin.setdefwinsize(width, height)
self = basewin.BaseWindow.init(self, title) basewin.BaseWindow.__init__(self, title)
# #
self.win.setdocsize(0, self.bottom) self.win.setdocsize(0, self.bottom)
self.initeditor() self.initeditor()
return self
def initeditor(self): def initeditor(self):
r = (self.leftmargin, self.top), (self.rightmargin, self.bottom) r = (self.leftmargin, self.top), (self.rightmargin, self.bottom)
...@@ -113,12 +112,12 @@ def countlines(text): ...@@ -113,12 +112,12 @@ def countlines(text):
class SourceWindow(TextWindow): class SourceWindow(TextWindow):
def init(self, filename): def __init__(self, filename):
self.filename = filename self.filename = filename
f = open(self.filename, 'r') f = open(self.filename, 'r')
contents = f.read() contents = f.read()
f.close() f.close()
return TextWindow.init(self, self.filename, contents) TextWindow.__init__(self, self.filename, contents)
# ------------------------------ testing ------------------------------ # ------------------------------ testing ------------------------------
...@@ -126,5 +125,5 @@ TESTFILE = 'srcwin.py' ...@@ -126,5 +125,5 @@ TESTFILE = 'srcwin.py'
def test(): def test():
import mainloop import mainloop
sw = SourceWindow().init(TESTFILE) sw = SourceWindow(TESTFILE)
mainloop.mainloop() mainloop.mainloop()
...@@ -19,16 +19,15 @@ WdbDone = 'wdb.WdbDone' # Exception to continue execution ...@@ -19,16 +19,15 @@ WdbDone = 'wdb.WdbDone' # Exception to continue execution
class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
def init(self): def __init__(self):
self.sourcewindows = {} self.sourcewindows = {}
self.framewindows = {} self.framewindows = {}
self = bdb.Bdb.init(self) bdb.Bdb.__init__(self)
width = WIDTH*stdwin.textwidth('0') width = WIDTH*stdwin.textwidth('0')
height = HEIGHT*stdwin.lineheight() height = HEIGHT*stdwin.lineheight()
stdwin.setdefwinsize(width, height) stdwin.setdefwinsize(width, height)
self = basewin.BaseWindow.init(self, '--Stack--') basewin.BaseWindow.__init__(self, '--Stack--')
self.closed = 0 self.closed = 0
return self
def reset(self): def reset(self):
if self.closed: raise RuntimeError, 'already closed' if self.closed: raise RuntimeError, 'already closed'
...@@ -151,9 +150,8 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger ...@@ -151,9 +150,8 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
if not self.sourcewindows.has_key(fn): if not self.sourcewindows.has_key(fn):
import wdbsrcwin import wdbsrcwin
try: try:
self.sourcewindows[fn] = \ self.sourcewindows[fn] = wdbsrcwin. \
wdbsrcwin.DebuggerSourceWindow(). \ DebuggerSourceWindow(self, fn)
init(self, fn)
except IOError: except IOError:
stdwin.fleep() stdwin.fleep()
return return
...@@ -170,7 +168,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger ...@@ -170,7 +168,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
else: else:
import wdbframewin import wdbframewin
self.framewindows[name] = \ self.framewindows[name] = \
wdbframewin.FrameWindow().init(self, \ wdbframewin.FrameWindow(self, \
self.curframe, \ self.curframe, \
self.curframe.f_locals, name) self.curframe.f_locals, name)
do_f = do_frame do_f = do_frame
...@@ -182,7 +180,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger ...@@ -182,7 +180,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
else: else:
import wdbframewin import wdbframewin
self.framewindows[name] = \ self.framewindows[name] = \
wdbframewin.FrameWindow().init(self, \ wdbframewin.FrameWindow(self, \
self.curframe, \ self.curframe, \
self.curframe.f_globals, name) self.curframe.f_globals, name)
do_g = do_globalframe do_g = do_globalframe
...@@ -274,27 +272,27 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger ...@@ -274,27 +272,27 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
# Simplified interface # Simplified interface
def run(statement): def run(statement):
x = Wdb().init() x = Wdb()
try: x.run(statement) try: x.run(statement)
finally: x.close() finally: x.close()
def runctx(statement, globals, locals): def runctx(statement, globals, locals):
x = Wdb().init() x = Wdb()
try: x.runctx(statement, globals, locals) try: x.runctx(statement, globals, locals)
finally: x.close() finally: x.close()
def runcall(*args): def runcall(*args):
x = Wdb().init() x = Wdb()
try: apply(Pdb().init().runcall, args) try: apply(x.runcall, args)
finally: x.close() finally: x.close()
# Post-Mortem interface # Post-Mortem interface
def post_mortem(traceback): def post_mortem(traceback):
p = Pdb().init() x = Wdb()
p.reset() x.reset()
p.interaction(None, traceback) x.interaction(None, traceback)
def pm(): def pm():
import sys import sys
......
...@@ -17,7 +17,7 @@ MAXHEIGHT = 16 ...@@ -17,7 +17,7 @@ MAXHEIGHT = 16
class FrameWindow(basewin.BaseWindow): class FrameWindow(basewin.BaseWindow):
def init(self, debugger, frame, dict, name): def __init__(self, debugger, frame, dict, name):
self.debugger = debugger self.debugger = debugger
self.frame = frame # Not used except for identity tests self.frame = frame # Not used except for identity tests
self.dict = dict self.dict = dict
...@@ -27,12 +27,12 @@ class FrameWindow(basewin.BaseWindow): ...@@ -27,12 +27,12 @@ class FrameWindow(basewin.BaseWindow):
width = WIDTH*stdwin.textwidth('0') width = WIDTH*stdwin.textwidth('0')
height = nl*stdwin.lineheight() height = nl*stdwin.lineheight()
stdwin.setdefwinsize(width, height) stdwin.setdefwinsize(width, height)
self = basewin.BaseWindow.init(self, '--Frame ' + name + '--') basewin.BaseWindow.__init__(
self, '--Frame ' + name + '--')
# XXX Should use current function name # XXX Should use current function name
self.initeditor() self.initeditor()
self.displaylist = ['>>>', '', '-'*WIDTH] self.displaylist = ['>>>', '', '-'*WIDTH]
self.refreshframe() self.refreshframe()
return self
def initeditor(self): def initeditor(self):
r = (stdwin.textwidth('>>> '), 0), (30000, stdwin.lineheight()) r = (stdwin.textwidth('>>> '), 0), (30000, stdwin.lineheight())
...@@ -81,7 +81,7 @@ class FrameWindow(basewin.BaseWindow): ...@@ -81,7 +81,7 @@ class FrameWindow(basewin.BaseWindow):
self.debugger.framewindows[name].popup() self.debugger.framewindows[name].popup()
else: else:
self.debugger.framewindows[name] = \ self.debugger.framewindows[name] = \
FrameWindow().init(self.debugger, FrameWindow(self.debugger,
self.frame, value.__dict__, self.frame, value.__dict__,
name) name)
return return
......
...@@ -7,11 +7,11 @@ import srcwin ...@@ -7,11 +7,11 @@ import srcwin
class DebuggerSourceWindow(srcwin.SourceWindow): class DebuggerSourceWindow(srcwin.SourceWindow):
def init(self, debugger, filename): def __init__(self, debugger, filename):
self.debugger = debugger self.debugger = debugger
self.curlineno = 0 self.curlineno = 0
self.focus = 0 self.focus = 0
return srcwin.SourceWindow.init(self, filename) srcwin.SourceWindow.__init__(self, filename)
def close(self): def close(self):
del self.debugger.sourcewindows[self.filename] del self.debugger.sourcewindows[self.filename]
......
...@@ -10,15 +10,14 @@ import rfc822 ...@@ -10,15 +10,14 @@ import rfc822
class Message(rfc822.Message): class Message(rfc822.Message):
def init(self, fp): def __init__(self, fp):
self = rfc822.Message.init(self, fp) rfc822.Message.__init__(self, fp)
self.encodingheader = \ self.encodingheader = \
self.getheader('content-transfer-encoding') self.getheader('content-transfer-encoding')
self.typeheader = \ self.typeheader = \
self.getheader('content-type') self.getheader('content-type')
self.parsetype() self.parsetype()
self.parseplist() self.parseplist()
return self
def parsetype(self): def parsetype(self):
str = self.typeheader str = self.typeheader
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
# Suggested use: # Suggested use:
# #
# real_fp = open(...) # real_fp = open(...)
# fp = MultiFile().init(real_fp) # fp = MultiFile(real_fp)
# #
# "read some lines from fp" # "read some lines from fp"
# fp.push(separator) # fp.push(separator)
...@@ -31,14 +31,13 @@ Error = 'multifile.Error' ...@@ -31,14 +31,13 @@ Error = 'multifile.Error'
class MultiFile: class MultiFile:
# #
def init(self, fp): def __init__(self, fp):
self.fp = fp self.fp = fp
self.stack = [] # Grows down self.stack = [] # Grows down
self.level = 0 self.level = 0
self.last = 0 self.last = 0
self.start = self.fp.tell() self.start = self.fp.tell()
self.posstack = [] # Grows down self.posstack = [] # Grows down
return self
# #
def tell(self): def tell(self):
if self.level > 0: if self.level > 0:
......
...@@ -15,10 +15,9 @@ class mutex: ...@@ -15,10 +15,9 @@ class mutex:
# #
# Create a new mutex -- initially unlocked # Create a new mutex -- initially unlocked
# #
def init(self): def __init__(self):
self.locked = 0 self.locked = 0
self.queue = [] self.queue = []
return self
# #
# Test the locked bit of the mutex # Test the locked bit of the mutex
# #
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# Example: # Example:
# #
# >>> from nntplib import NNTP # >>> from nntplib import NNTP
# >>> s = NNTP().init('charon') # >>> s = NNTP('charon')
# >>> resp, count, first, last, name = s.group('nlnet.misc') # >>> resp, count, first, last, name = s.group('nlnet.misc')
# >>> print 'Group', name, 'has', count, 'articles, range', first, 'to', last # >>> print 'Group', name, 'has', count, 'articles, range', first, 'to', last
# Group nlnet.misc has 525 articles, range 6960 to 7485 # Group nlnet.misc has 525 articles, range 6960 to 7485
...@@ -60,7 +60,7 @@ class NNTP: ...@@ -60,7 +60,7 @@ class NNTP:
# - host: hostname to connect to # - host: hostname to connect to
# - port: port to connect to (default the standard NNTP port) # - port: port to connect to (default the standard NNTP port)
def init(self, host, *args): def __init__(self, host, *args):
if len(args) > 1: raise TypeError, 'too many args' if len(args) > 1: raise TypeError, 'too many args'
if args: port = args[0] if args: port = args[0]
else: port = NNTP_PORT else: port = NNTP_PORT
...@@ -71,10 +71,9 @@ class NNTP: ...@@ -71,10 +71,9 @@ class NNTP:
self.file = self.sock.makefile('r') self.file = self.sock.makefile('r')
self.debugging = 0 self.debugging = 0
self.welcome = self.getresp() self.welcome = self.getresp()
return self
# Get the welcome message from the server # Get the welcome message from the server
# (this is read and squirreled away by init()). # (this is read and squirreled away by __init__()).
# If the response code is 200, posting is allowed; # If the response code is 200, posting is allowed;
# if it 201, posting is not allowed # if it 201, posting is not allowed
......
...@@ -17,9 +17,6 @@ class Pdb(bdb.Bdb, cmd.Cmd): ...@@ -17,9 +17,6 @@ class Pdb(bdb.Bdb, cmd.Cmd):
cmd.Cmd.__init__(self) cmd.Cmd.__init__(self)
self.prompt = '(Pdb) ' self.prompt = '(Pdb) '
def init(self): # BW compat only
return self
def reset(self): def reset(self):
bdb.Bdb.reset(self) bdb.Bdb.reset(self)
self.forget() self.forget()
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
# ----------- # -----------
# #
# To create a template: # To create a template:
# t = Template().init() # t = Template()
# #
# To add a conversion step to a template: # To add a conversion step to a template:
# t.append(command, kind) # t.append(command, kind)
...@@ -85,11 +85,10 @@ stepkinds = [FILEIN_FILEOUT, STDIN_FILEOUT, FILEIN_STDOUT, STDIN_STDOUT, \ ...@@ -85,11 +85,10 @@ stepkinds = [FILEIN_FILEOUT, STDIN_FILEOUT, FILEIN_STDOUT, STDIN_STDOUT, \
class Template: class Template:
# Template().init() returns a fresh pipeline template # Template() returns a fresh pipeline template
def init(self): def __init__(self):
self.debugging = 0 self.debugging = 0
self.reset() self.reset()
return self
# t.__repr__() implements `t` # t.__repr__() implements `t`
def __repr__(self): def __repr__(self):
...@@ -102,7 +101,7 @@ class Template: ...@@ -102,7 +101,7 @@ class Template:
# t.clone() returns a new pipeline template with identical # t.clone() returns a new pipeline template with identical
# initial state as the current one # initial state as the current one
def clone(self): def clone(self):
t = Template().init() t = Template()
t.steps = self.steps[:] t.steps = self.steps[:]
t.debugging = self.debugging t.debugging = self.debugging
return t return t
...@@ -291,7 +290,7 @@ def quote(file): ...@@ -291,7 +290,7 @@ def quote(file):
def test(): def test():
import os import os
print 'Testing...' print 'Testing...'
t = Template().init() t = Template()
t.append('togif $IN $OUT', 'ff') t.append('togif $IN $OUT', 'ff')
t.append('giftoppm', '--') t.append('giftoppm', '--')
t.append('ppmtogif >$OUT', '-f') t.append('ppmtogif >$OUT', '-f')
......
...@@ -92,11 +92,11 @@ def _unpack_cache(altforms): ...@@ -92,11 +92,11 @@ def _unpack_cache(altforms):
forms = {} forms = {}
for name in altforms.keys(): for name in altforms.keys():
altobj, altlist = altforms[name] altobj, altlist = altforms[name]
obj = _newobj().init() obj = _newobj()
obj.make(altobj) obj.make(altobj)
list = [] list = []
for altobj in altlist: for altobj in altlist:
nobj = _newobj().init() nobj = _newobj()
nobj.make(altobj) nobj.make(altobj)
list.append(nobj) list.append(nobj)
forms[name] = obj, list forms[name] = obj, list
...@@ -235,8 +235,6 @@ def _parse_fd_form(file, name): ...@@ -235,8 +235,6 @@ def _parse_fd_form(file, name):
# Internal class: a convient place to store object info fields # Internal class: a convient place to store object info fields
# #
class _newobj: class _newobj:
def init(self):
return self
def add(self, name, value): def add(self, name, value):
self.__dict__[name] = value self.__dict__[name] = value
def make(self, dict): def make(self, dict):
...@@ -320,7 +318,7 @@ def _skip_object(file): ...@@ -320,7 +318,7 @@ def _skip_object(file):
file.seek(pos) file.seek(pos)
def _parse_object(file): def _parse_object(file):
obj = _newobj().init() obj = _newobj()
while 1: while 1:
pos = file.tell() pos = file.tell()
datum = _parse_1_line(file) datum = _parse_1_line(file)
......
...@@ -30,7 +30,7 @@ class Readcd: ...@@ -30,7 +30,7 @@ class Readcd:
elif len(arg) == 2: elif len(arg) == 2:
self.player = cd.open(arg[0], arg[1]) self.player = cd.open(arg[0], arg[1])
else: else:
raise Error, 'bad init call' raise Error, 'bad __init__ call'
self.list = [] self.list = []
self.callbacks = [(None, None)] * 8 self.callbacks = [(None, None)] * 8
self.parser = cd.createparser() self.parser = cd.createparser()
......
...@@ -13,40 +13,40 @@ import imghdr ...@@ -13,40 +13,40 @@ import imghdr
table = {} table = {}
t = pipes.Template().init() t = pipes.Template()
t.append('fromppm $IN $OUT', 'ff') t.append('fromppm $IN $OUT', 'ff')
table['ppm'] = t table['ppm'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--') t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
t.append('fromppm $IN $OUT', 'ff') t.append('fromppm $IN $OUT', 'ff')
table['pnm'] = t table['pnm'] = t
table['pgm'] = t table['pgm'] = t
table['pbm'] = t table['pbm'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('fromgif $IN $OUT', 'ff') t.append('fromgif $IN $OUT', 'ff')
table['gif'] = t table['gif'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('tifftopnm', '--') t.append('tifftopnm', '--')
t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--') t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
t.append('fromppm $IN $OUT', 'ff') t.append('fromppm $IN $OUT', 'ff')
table['tiff'] = t table['tiff'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('rasttopnm', '--') t.append('rasttopnm', '--')
t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--') t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
t.append('fromppm $IN $OUT', 'ff') t.append('fromppm $IN $OUT', 'ff')
table['rast'] = t table['rast'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('djpeg', '--') t.append('djpeg', '--')
t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--') t.append('(PATH=$PATH:/ufs/guido/bin/sgi; exec pnmtoppm)', '--')
t.append('fromppm $IN $OUT', 'ff') t.append('fromppm $IN $OUT', 'ff')
table['jpeg'] = t table['jpeg'] = t
uncompress = pipes.Template().init() uncompress = pipes.Template()
uncompress.append('uncompress', '--') uncompress.append('uncompress', '--')
......
...@@ -14,13 +14,12 @@ import marshal ...@@ -14,13 +14,12 @@ import marshal
class Profile: class Profile:
def init(self): def __init__(self):
self.timings = {} self.timings = {}
self.debug = None self.debug = None
self.call_level = 0 self.call_level = 0
self.profile_func = None self.profile_func = None
self.profiling = 0 self.profiling = 0
return self
def profile(self, funcname): def profile(self, funcname):
if not self.profile_func: if not self.profile_func:
...@@ -230,12 +229,11 @@ def depth(frame): ...@@ -230,12 +229,11 @@ def depth(frame):
return d return d
class Stats: class Stats:
def init(self, file): def __init__(self, file):
f = open(file, 'r') f = open(file, 'r')
self.stats = marshal.load(f) self.stats = marshal.load(f)
f.close() f.close()
self.stats_list = None self.stats_list = None
return self
def print_stats(self): def print_stats(self):
print_title() print_title()
...@@ -354,7 +352,7 @@ def f8(x): ...@@ -354,7 +352,7 @@ def f8(x):
# simplified user interface # simplified user interface
def run(statement, *args): def run(statement, *args):
prof = Profile().init() prof = Profile()
try: try:
prof.run(statement) prof.run(statement)
except SystemExit: except SystemExit:
...@@ -366,7 +364,7 @@ def run(statement, *args): ...@@ -366,7 +364,7 @@ def run(statement, *args):
# test command with debugging # test command with debugging
def debug(): def debug():
prof = Profile().init() prof = Profile()
prof.debug = 1 prof.debug = 1
try: try:
prof.run('import x; x.main()') prof.run('import x; x.main()')
......
...@@ -4,13 +4,12 @@ import regex ...@@ -4,13 +4,12 @@ import regex
from regex_syntax import * from regex_syntax import *
class Prog: class Prog:
def init(self, pat): def __init__(self, pat):
save_syntax = regex.set_syntax(RE_SYNTAX_AWK) save_syntax = regex.set_syntax(RE_SYNTAX_AWK)
try: try:
self.prog = regex.compile(pat) self.prog = regex.compile(pat)
finally: finally:
xxx = regex.set_syntax(save_syntax) xxx = regex.set_syntax(save_syntax)
return self
def match(self, *args): def match(self, *args):
if len(args) == 2: if len(args) == 2:
str, offset = args str, offset = args
...@@ -27,7 +26,7 @@ class Prog: ...@@ -27,7 +26,7 @@ class Prog:
return regs[:i] return regs[:i]
def compile(pat): def compile(pat):
return Prog().init(pat) return Prog(pat)
cache_pat = None cache_pat = None
cache_prog = None cache_prog = None
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import string import string
class Repr: class Repr:
def init(self): def __init__(self):
self.maxlevel = 6 self.maxlevel = 6
self.maxtuple = 6 self.maxtuple = 6
self.maxlist = 6 self.maxlist = 6
...@@ -11,7 +11,6 @@ class Repr: ...@@ -11,7 +11,6 @@ class Repr:
self.maxstring = 30 self.maxstring = 30
self.maxlong = 40 self.maxlong = 40
self.maxother = 20 self.maxother = 20
return self
def repr(self, x): def repr(self, x):
return self.repr1(x, self.maxlevel) return self.repr1(x, self.maxlevel)
def repr1(self, x, level): def repr1(self, x, level):
...@@ -79,5 +78,5 @@ class Repr: ...@@ -79,5 +78,5 @@ class Repr:
s = s[:i] + '...' + s[len(s)-j:] s = s[:i] + '...' + s[len(s)-j:]
return s return s
aRepr = Repr().init() aRepr = Repr()
repr = aRepr.repr repr = aRepr.repr
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
# fp = open(file, 'r') # fp = open(file, 'r')
# (or use any other legal way of getting an open file object, e.g. use # (or use any other legal way of getting an open file object, e.g. use
# sys.stdin or call os.popen()). # sys.stdin or call os.popen()).
# Then pass the open file object to the init() method of Message: # Then pass the open file object to the Message() constructor:
# m = Message().init(fp) # m = Message(fp)
# #
# To get the text of a particular header there are several methods: # To get the text of a particular header there are several methods:
# str = m.getheader(name) # str = m.getheader(name)
...@@ -35,7 +35,7 @@ class Message: ...@@ -35,7 +35,7 @@ class Message:
# Initialize the class instance and read the headers. # Initialize the class instance and read the headers.
def init(self, fp): def __init__(self, fp):
self.fp = fp self.fp = fp
# #
try: try:
...@@ -49,8 +49,6 @@ class Message: ...@@ -49,8 +49,6 @@ class Message:
self.startofbody = self.fp.tell() self.startofbody = self.fp.tell()
except IOError: except IOError:
self.startofbody = None self.startofbody = None
#
return self
# Rewind the file to the start of the body (if seekable). # Rewind the file to the start of the body (if seekable).
......
...@@ -34,11 +34,10 @@ class scheduler: ...@@ -34,11 +34,10 @@ class scheduler:
# #
# Initialize a new instance, passing the time and delay functions # Initialize a new instance, passing the time and delay functions
# #
def init(self, timefunc, delayfunc): def __init__(self, timefunc, delayfunc):
self.queue = [] self.queue = []
self.timefunc = timefunc self.timefunc = timefunc
self.delayfunc = delayfunc self.delayfunc = delayfunc
return self
# #
# Enter a new event in the queue at an absolute time. # Enter a new event in the queue at an absolute time.
# Returns an ID for the event which can be used # Returns an ID for the event which can be used
......
...@@ -35,7 +35,7 @@ def delayfunc(msecs): ...@@ -35,7 +35,7 @@ def delayfunc(msecs):
if event[0] <> WE_TIMER: if event[0] <> WE_TIMER:
mainloop.dispatch(event) 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 # Export functions enter, enterabs and cancel just like a scheduler
# #
......
...@@ -6,11 +6,10 @@ from stdwinevents import * ...@@ -6,11 +6,10 @@ from stdwinevents import *
class BaseWindow: class BaseWindow:
def init(self, title): def __init__(self, title):
self.win = stdwin.open(title) self.win = stdwin.open(title)
self.win.dispatch = self.dispatch self.win.dispatch = self.dispatch
mainloop.register(self.win) mainloop.register(self.win)
return self
# def reopen(self): # def reopen(self):
# title = self.win.gettitle() # title = self.win.gettitle()
......
...@@ -13,7 +13,7 @@ class formatter: ...@@ -13,7 +13,7 @@ class formatter:
# Pass the window's drawing object, and left, top, right # Pass the window's drawing object, and left, top, right
# coordinates of the drawing space as arguments. # 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.d = d # Drawing object
self.left = left # Left margin self.left = left # Left margin
self.right = right # Right margin self.right = right # Right margin
...@@ -22,7 +22,6 @@ class formatter: ...@@ -22,7 +22,6 @@ class formatter:
self.justify = 1 self.justify = 1
self.setfont('') # Default font self.setfont('') # Default font
self._reset() # Prepare for new line self._reset() # Prepare for new line
return self
# #
# Reset for start of fresh line. # Reset for start of fresh line.
# #
...@@ -190,7 +189,7 @@ def test(): ...@@ -190,7 +189,7 @@ def test():
w.change((0, 0), (1000, 1000)) w.change((0, 0), (1000, 1000))
elif type == WE_DRAW: elif type == WE_DRAW:
width, height = winsize width, height = winsize
f = formatter().init(w.begindrawing(), 0, 0, width) f = formatter(w.begindrawing(), 0, 0, width)
f.center = center f.center = center
f.justify = justify f.justify = justify
if not center: if not center:
......
...@@ -224,11 +224,10 @@ def dispatch(event): ...@@ -224,11 +224,10 @@ def dispatch(event):
# #
class Dialog: class Dialog:
# #
def init(self, title): def __init__(self, title):
self.window = stdwin.open(title) self.window = stdwin.open(title)
self.window.dispatch = self.dispatch self.window.dispatch = self.dispatch
register(self.window) register(self.window)
return self
# #
def close(self): def close(self):
unregister(self.window) unregister(self.window)
......
...@@ -10,7 +10,7 @@ MAXHEIGHT = 24 ...@@ -10,7 +10,7 @@ MAXHEIGHT = 24
class TextWindow(basewin.BaseWindow): class TextWindow(basewin.BaseWindow):
def init(self, title, contents): def __init__(self, title, contents):
self.contents = contents self.contents = contents
self.linecount = countlines(self.contents) self.linecount = countlines(self.contents)
# #
...@@ -23,11 +23,10 @@ class TextWindow(basewin.BaseWindow): ...@@ -23,11 +23,10 @@ class TextWindow(basewin.BaseWindow):
width = WIDTH*stdwin.textwidth('0') width = WIDTH*stdwin.textwidth('0')
height = lh*min(MAXHEIGHT, self.linecount) height = lh*min(MAXHEIGHT, self.linecount)
stdwin.setdefwinsize(width, height) stdwin.setdefwinsize(width, height)
self = basewin.BaseWindow.init(self, title) basewin.BaseWindow.__init__(self, title)
# #
self.win.setdocsize(0, self.bottom) self.win.setdocsize(0, self.bottom)
self.initeditor() self.initeditor()
return self
def initeditor(self): def initeditor(self):
r = (self.leftmargin, self.top), (self.rightmargin, self.bottom) r = (self.leftmargin, self.top), (self.rightmargin, self.bottom)
...@@ -113,12 +112,12 @@ def countlines(text): ...@@ -113,12 +112,12 @@ def countlines(text):
class SourceWindow(TextWindow): class SourceWindow(TextWindow):
def init(self, filename): def __init__(self, filename):
self.filename = filename self.filename = filename
f = open(self.filename, 'r') f = open(self.filename, 'r')
contents = f.read() contents = f.read()
f.close() f.close()
return TextWindow.init(self, self.filename, contents) TextWindow.__init__(self, self.filename, contents)
# ------------------------------ testing ------------------------------ # ------------------------------ testing ------------------------------
...@@ -126,5 +125,5 @@ TESTFILE = 'srcwin.py' ...@@ -126,5 +125,5 @@ TESTFILE = 'srcwin.py'
def test(): def test():
import mainloop import mainloop
sw = SourceWindow().init(TESTFILE) sw = SourceWindow(TESTFILE)
mainloop.mainloop() mainloop.mainloop()
...@@ -19,16 +19,15 @@ WdbDone = 'wdb.WdbDone' # Exception to continue execution ...@@ -19,16 +19,15 @@ WdbDone = 'wdb.WdbDone' # Exception to continue execution
class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
def init(self): def __init__(self):
self.sourcewindows = {} self.sourcewindows = {}
self.framewindows = {} self.framewindows = {}
self = bdb.Bdb.init(self) bdb.Bdb.__init__(self)
width = WIDTH*stdwin.textwidth('0') width = WIDTH*stdwin.textwidth('0')
height = HEIGHT*stdwin.lineheight() height = HEIGHT*stdwin.lineheight()
stdwin.setdefwinsize(width, height) stdwin.setdefwinsize(width, height)
self = basewin.BaseWindow.init(self, '--Stack--') basewin.BaseWindow.__init__(self, '--Stack--')
self.closed = 0 self.closed = 0
return self
def reset(self): def reset(self):
if self.closed: raise RuntimeError, 'already closed' if self.closed: raise RuntimeError, 'already closed'
...@@ -151,9 +150,8 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger ...@@ -151,9 +150,8 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
if not self.sourcewindows.has_key(fn): if not self.sourcewindows.has_key(fn):
import wdbsrcwin import wdbsrcwin
try: try:
self.sourcewindows[fn] = \ self.sourcewindows[fn] = wdbsrcwin. \
wdbsrcwin.DebuggerSourceWindow(). \ DebuggerSourceWindow(self, fn)
init(self, fn)
except IOError: except IOError:
stdwin.fleep() stdwin.fleep()
return return
...@@ -170,7 +168,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger ...@@ -170,7 +168,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
else: else:
import wdbframewin import wdbframewin
self.framewindows[name] = \ self.framewindows[name] = \
wdbframewin.FrameWindow().init(self, \ wdbframewin.FrameWindow(self, \
self.curframe, \ self.curframe, \
self.curframe.f_locals, name) self.curframe.f_locals, name)
do_f = do_frame do_f = do_frame
...@@ -182,7 +180,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger ...@@ -182,7 +180,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
else: else:
import wdbframewin import wdbframewin
self.framewindows[name] = \ self.framewindows[name] = \
wdbframewin.FrameWindow().init(self, \ wdbframewin.FrameWindow(self, \
self.curframe, \ self.curframe, \
self.curframe.f_globals, name) self.curframe.f_globals, name)
do_g = do_globalframe do_g = do_globalframe
...@@ -274,27 +272,27 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger ...@@ -274,27 +272,27 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
# Simplified interface # Simplified interface
def run(statement): def run(statement):
x = Wdb().init() x = Wdb()
try: x.run(statement) try: x.run(statement)
finally: x.close() finally: x.close()
def runctx(statement, globals, locals): def runctx(statement, globals, locals):
x = Wdb().init() x = Wdb()
try: x.runctx(statement, globals, locals) try: x.runctx(statement, globals, locals)
finally: x.close() finally: x.close()
def runcall(*args): def runcall(*args):
x = Wdb().init() x = Wdb()
try: apply(Pdb().init().runcall, args) try: apply(x.runcall, args)
finally: x.close() finally: x.close()
# Post-Mortem interface # Post-Mortem interface
def post_mortem(traceback): def post_mortem(traceback):
p = Pdb().init() x = Wdb()
p.reset() x.reset()
p.interaction(None, traceback) x.interaction(None, traceback)
def pm(): def pm():
import sys import sys
......
...@@ -17,7 +17,7 @@ MAXHEIGHT = 16 ...@@ -17,7 +17,7 @@ MAXHEIGHT = 16
class FrameWindow(basewin.BaseWindow): class FrameWindow(basewin.BaseWindow):
def init(self, debugger, frame, dict, name): def __init__(self, debugger, frame, dict, name):
self.debugger = debugger self.debugger = debugger
self.frame = frame # Not used except for identity tests self.frame = frame # Not used except for identity tests
self.dict = dict self.dict = dict
...@@ -27,12 +27,12 @@ class FrameWindow(basewin.BaseWindow): ...@@ -27,12 +27,12 @@ class FrameWindow(basewin.BaseWindow):
width = WIDTH*stdwin.textwidth('0') width = WIDTH*stdwin.textwidth('0')
height = nl*stdwin.lineheight() height = nl*stdwin.lineheight()
stdwin.setdefwinsize(width, height) stdwin.setdefwinsize(width, height)
self = basewin.BaseWindow.init(self, '--Frame ' + name + '--') basewin.BaseWindow.__init__(
self, '--Frame ' + name + '--')
# XXX Should use current function name # XXX Should use current function name
self.initeditor() self.initeditor()
self.displaylist = ['>>>', '', '-'*WIDTH] self.displaylist = ['>>>', '', '-'*WIDTH]
self.refreshframe() self.refreshframe()
return self
def initeditor(self): def initeditor(self):
r = (stdwin.textwidth('>>> '), 0), (30000, stdwin.lineheight()) r = (stdwin.textwidth('>>> '), 0), (30000, stdwin.lineheight())
...@@ -81,7 +81,7 @@ class FrameWindow(basewin.BaseWindow): ...@@ -81,7 +81,7 @@ class FrameWindow(basewin.BaseWindow):
self.debugger.framewindows[name].popup() self.debugger.framewindows[name].popup()
else: else:
self.debugger.framewindows[name] = \ self.debugger.framewindows[name] = \
FrameWindow().init(self.debugger, FrameWindow(self.debugger,
self.frame, value.__dict__, self.frame, value.__dict__,
name) name)
return return
......
...@@ -7,11 +7,11 @@ import srcwin ...@@ -7,11 +7,11 @@ import srcwin
class DebuggerSourceWindow(srcwin.SourceWindow): class DebuggerSourceWindow(srcwin.SourceWindow):
def init(self, debugger, filename): def __init__(self, debugger, filename):
self.debugger = debugger self.debugger = debugger
self.curlineno = 0 self.curlineno = 0
self.focus = 0 self.focus = 0
return srcwin.SourceWindow.init(self, filename) srcwin.SourceWindow.__init__(self, filename)
def close(self): def close(self):
del self.debugger.sourcewindows[self.filename] del self.debugger.sourcewindows[self.filename]
......
...@@ -192,11 +192,12 @@ class Au_read: ...@@ -192,11 +192,12 @@ class Au_read:
break break
else: else:
self._info = '' self._info = ''
return self
def init(self, filename): def __init__(self, f):
if type(f) == type(''):
import builtin import builtin
return self.initfp(builtin.open(filename, 'r')) f = builtin.open(f, 'r')
self.initfp(f)
def __del__(self): def __del__(self):
if self._file: if self._file:
...@@ -277,9 +278,11 @@ class Au_read: ...@@ -277,9 +278,11 @@ class Au_read:
self._file = None self._file = None
class Au_write: class Au_write:
def init(self, filename): def __init__(self, f):
if type(f) == type(''):
import builtin import builtin
return self.initfp(builtin.open(filename, 'w')) f = builtin.open(f, 'w')
self.initfp(f)
def initfp(self, file): def initfp(self, file):
self._file = file self._file = file
...@@ -293,7 +296,6 @@ class Au_write: ...@@ -293,7 +296,6 @@ class Au_write:
self._datalength = 0 self._datalength = 0
self._info = '' self._info = ''
self._comptype = 'ULAW' # default is U-law self._comptype = 'ULAW' # default is U-law
return self
def __del__(self): def __del__(self):
if self._file: if self._file:
...@@ -453,18 +455,12 @@ class Au_write: ...@@ -453,18 +455,12 @@ class Au_write:
self._datalength = self._datawritten self._datalength = self._datawritten
self._file.seek(0, 2) self._file.seek(0, 2)
def open(filename, mode): def open(f, mode):
if mode == 'r': if mode == 'r':
return Au_read().init(filename) return Au_read(f)
elif mode == 'w': elif mode == 'w':
return Au_write().init(filename) return Au_write(f)
else: else:
raise Error, "mode must be 'r' or 'w'" raise Error, "mode must be 'r' or 'w'"
def openfp(filep, mode): openfp = open
if mode == 'r':
return Au_read().initfp(filep)
elif mode == 'w':
return Au_write().initfp(filep)
else:
raise Error, "mode must be 'r' or 'w'"
...@@ -42,9 +42,8 @@ TestFailed = 'autotest.TestFailed' ...@@ -42,9 +42,8 @@ TestFailed = 'autotest.TestFailed'
# Class substituted for sys.stdout, to compare it with the given file # Class substituted for sys.stdout, to compare it with the given file
class Compare: class Compare:
def init(self, filename): def __init__(self, filename):
self.fp = open(filename, 'r') self.fp = open(filename, 'r')
return self
def write(self, data): def write(self, data):
expected = self.fp.read(len(data)) expected = self.fp.read(len(data))
if data <> expected: if data <> expected:
...@@ -59,7 +58,7 @@ def main(): ...@@ -59,7 +58,7 @@ def main():
filename = findfile('testall.out') filename = findfile('testall.out')
real_stdout = sys.stdout real_stdout = sys.stdout
try: try:
sys.stdout = Compare().init(filename) sys.stdout = Compare(filename)
import testall import testall
finally: finally:
sys.stdout = real_stdout sys.stdout = real_stdout
......
...@@ -13,7 +13,7 @@ import whatsound ...@@ -13,7 +13,7 @@ import whatsound
table = {} table = {}
t = pipes.Template().init() t = pipes.Template()
t.append('sox -t au - -t aiff -r 8000 -', '--') t.append('sox -t au - -t aiff -r 8000 -', '--')
table['au'] = t table['au'] = t
...@@ -23,31 +23,31 @@ table['au'] = t ...@@ -23,31 +23,31 @@ table['au'] = t
# XXX files sampled at 5.5k or 7.333k; however this means that files # XXX files sampled at 5.5k or 7.333k; however this means that files
# XXX sampled at 11k are unnecessarily expanded. # XXX sampled at 11k are unnecessarily expanded.
# XXX Similar comments apply to some other file types. # XXX Similar comments apply to some other file types.
t = pipes.Template().init() t = pipes.Template()
t.append('sox -t hcom - -t aiff -r 22050 -', '--') t.append('sox -t hcom - -t aiff -r 22050 -', '--')
table['hcom'] = t table['hcom'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('sox -t voc - -t aiff -r 11025 -', '--') t.append('sox -t voc - -t aiff -r 11025 -', '--')
table['voc'] = t table['voc'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('sox -t wav - -t aiff -', '--') t.append('sox -t wav - -t aiff -', '--')
table['wav'] = t table['wav'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('sox -t 8svx - -t aiff -r 16000 -', '--') t.append('sox -t 8svx - -t aiff -r 16000 -', '--')
table['8svx'] = t table['8svx'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('sox -t sndt - -t aiff -r 16000 -', '--') t.append('sox -t sndt - -t aiff -r 16000 -', '--')
table['sndt'] = t table['sndt'] = t
t = pipes.Template().init() t = pipes.Template()
t.append('sox -t sndr - -t aiff -r 16000 -', '--') t.append('sox -t sndr - -t aiff -r 16000 -', '--')
table['sndr'] = t table['sndr'] = t
uncompress = pipes.Template().init() uncompress = pipes.Template()
uncompress.append('uncompress', '--') uncompress.append('uncompress', '--')
......
...@@ -35,7 +35,7 @@ class whrandom: ...@@ -35,7 +35,7 @@ class whrandom:
# Without arguments, initialize from current time. # Without arguments, initialize from current time.
# With arguments (x, y, z), initialize from them. # With arguments (x, y, z), initialize from them.
# #
def init(self, *xyz): def __init__(self, *xyz):
if not xyz: if not xyz:
# Initialize from current time # Initialize from current time
import time import time
...@@ -47,7 +47,6 @@ class whrandom: ...@@ -47,7 +47,6 @@ class whrandom:
# Initialize from arguments (x, y, z) # Initialize from arguments (x, y, z)
x, y, z = xyz x, y, z = xyz
self.seed(x, y, z) self.seed(x, y, z)
return self
# #
# Set the seed from (x, y, z). # Set the seed from (x, y, z).
# These must be integers in the range [0, 256). # These must be integers in the range [0, 256).
...@@ -97,7 +96,7 @@ class whrandom: ...@@ -97,7 +96,7 @@ class whrandom:
# Initialize from the current time # Initialize from the current time
# #
_inst = whrandom().init() _inst = whrandom()
seed = _inst.seed seed = _inst.seed
random = _inst.random random = _inst.random
uniform = _inst.uniform uniform = _inst.uniform
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment