]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
* Mass change: get rid of all init() methods, in favor of __init__()
authorGuido van Rossum <guido@python.org>
Fri, 17 Dec 1993 15:25:27 +0000 (15:25 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 17 Dec 1993 15:25:27 +0000 (15:25 +0000)
  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)

42 files changed:
Lib/Queue.py
Lib/aifc.py
Lib/bdb.py
Lib/cmd.py
Lib/ftplib.py
Lib/irix5/flp.py
Lib/irix5/readcd.py
Lib/irix5/torgb.py
Lib/lib-stdwin/WindowSched.py
Lib/lib-stdwin/basewin.py
Lib/lib-stdwin/formatter.py
Lib/lib-stdwin/mainloop.py
Lib/lib-stdwin/srcwin.py
Lib/lib-stdwin/wdb.py
Lib/lib-stdwin/wdbframewin.py
Lib/lib-stdwin/wdbsrcwin.py
Lib/mimetools.py
Lib/multifile.py
Lib/mutex.py
Lib/nntplib.py
Lib/pdb.py
Lib/pipes.py
Lib/plat-irix5/flp.py
Lib/plat-irix5/readcd.py
Lib/plat-irix5/torgb.py
Lib/profile.py
Lib/regexp.py
Lib/repr.py
Lib/rfc822.py
Lib/sched.py
Lib/stdwin/WindowSched.py
Lib/stdwin/basewin.py
Lib/stdwin/formatter.py
Lib/stdwin/mainloop.py
Lib/stdwin/srcwin.py
Lib/stdwin/wdb.py
Lib/stdwin/wdbframewin.py
Lib/stdwin/wdbsrcwin.py
Lib/sunau.py
Lib/test/autotest.py
Lib/toaiff.py
Lib/whrandom.py

index eb089b88a5836aff5f3d4a4b324a31da1cabb687..0d69777b447e0434feb4a6faae4544cd0bc86f3d 100644 (file)
@@ -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):
index f833e921cf1773dd1ffb279b1cf496d10626bbca..a603314697a32af703bdc6079fe673bdc900c6cf 100644 (file)
@@ -287,7 +287,7 @@ 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:
@@ -295,7 +295,6 @@ class Chunk:
                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)
@@ -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
@@ -389,7 +388,7 @@ class Aifc_read:
                        #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'
@@ -433,10 +432,12 @@ class Aifc_read:
                        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:
@@ -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
@@ -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
@@ -659,7 +662,6 @@ class Aifc_write:
                self._markers = []
                self._marklength = 0
                self._aifc = 1          # AIFF-C is default
-               return self
 
        def __del__(self):
                if self._file:
@@ -976,18 +978,12 @@ class Aifc_write:
                        _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
index bc0b282e01f040f6905aa902442e4d382d50df90..6b3eab9564f317fb56c502f4c29582f9dcd0ab8e 100644 (file)
@@ -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
index c4a347d2a6a35fa542cc6a96a623d95dfc793070..87ddcfa7e72aa2ea9e04d3962156a83124890675 100644 (file)
@@ -13,9 +13,6 @@ class Cmd:
                self.prompt = PROMPT
                self.identchars = IDENTCHARS
                self.lastcmd = ''
-       
-       def init(self):                 # BW compat only
-               return self
 
        def cmdloop(self):
                stop = None
index bfb0b5b2d52599b252bd461db2e53f3f9a939d54..c441f1f739503a7869687d6ce5a86d65ef6d99f4 100644 (file)
@@ -87,11 +87,6 @@ class FTP:
                        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)
@@ -105,7 +100,7 @@ class FTP:
                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
index ced559836a7785692b0d4dc2fec22a99184acd0e..c3f6f3b2c533c3e1f92af5f60a1b44acc23cd834 100755 (executable)
@@ -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
@@ -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):
@@ -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)
index 7af6882b89d3e8f7886456a15c606617f76ec4a1..fffb6fe8c65096a7ddef9085fa96b70deccef963 100755 (executable)
@@ -30,7 +30,7 @@ class Readcd:
                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()
index 61297d0c7b0704bb2e5381ebff2b565c6884eeba..f283063c000c7936bc4b468db380c0e8e79c120d 100755 (executable)
@@ -13,40 +13,40 @@ import imghdr
 
 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', '--')
 
 
index 67c3afbe22c2e1e6840eac11f1e7919d5d0f3d52..56ca6f853b0c15d5c84082ebb8c0f92209be2b2b 100644 (file)
@@ -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
 #
index f896fe2a059ee434416ad24bfaa14bacfe3d4cbd..7a435369678b80bacd8ef168164ac335b5b4bcb8 100644 (file)
@@ -6,11 +6,10 @@ from stdwinevents import *
 
 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()
index ac34ce952c649f870d6177dd27164242ba66e8ea..7ddfc1d6806253dabe004060fef0ee3e3d06721c 100644 (file)
@@ -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
@@ -22,7 +22,6 @@ class formatter:
                self.justify = 1
                self.setfont('')        # Default font
                self._reset()           # Prepare for new line
-               return self
        #
        # Reset for start of fresh line.
        #
@@ -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:
index ca3e9ac4c54360ae9071b0c0481cde4cc4623c68..aa40c34b4ec508fa48a25b3ada1f7b9d4f20c8e0 100644 (file)
@@ -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)
index a71c568ace9031b4030fa8e912fd7921ef095eb4..29b78010a616b9060aec78d8427c38f5db4075fa 100644 (file)
@@ -10,7 +10,7 @@ MAXHEIGHT = 24
 
 class TextWindow(basewin.BaseWindow):
        
-       def init(self, title, contents):
+       def __init__(self, title, contents):
                self.contents = contents
                self.linecount = countlines(self.contents)
                #
@@ -23,11 +23,10 @@ class TextWindow(basewin.BaseWindow):
                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)
@@ -113,12 +112,12 @@ 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 ------------------------------
 
@@ -126,5 +125,5 @@ TESTFILE = 'srcwin.py'
 
 def test():
        import mainloop
-       sw = SourceWindow().init(TESTFILE)
+       sw = SourceWindow(TESTFILE)
        mainloop.mainloop()
index c499296c8a01c383a7743c6b02bc4a4aa3e9d74c..d5c28bb9f17f601483bca6b45452f308bff2d686 100644 (file)
@@ -19,16 +19,15 @@ WdbDone = 'wdb.WdbDone' # Exception to continue execution
 
 class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
        
-       def init(self):
+       def __init__(self):
                self.sourcewindows = {}
                self.framewindows = {}
-               self = bdb.Bdb.init(self)
+               bdb.Bdb.__init__(self)
                width = WIDTH*stdwin.textwidth('0')
                height = HEIGHT*stdwin.lineheight()
                stdwin.setdefwinsize(width, height)
-               self = basewin.BaseWindow.init(self, '--Stack--')
+               basewin.BaseWindow.__init__(self, '--Stack--')
                self.closed = 0
-               return self
        
        def reset(self):
                if self.closed: raise RuntimeError, 'already closed'
@@ -151,9 +150,8 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
                if not self.sourcewindows.has_key(fn):
                        import wdbsrcwin
                        try:
-                               self.sourcewindows[fn] = \
-                                       wdbsrcwin.DebuggerSourceWindow(). \
-                                       init(self, fn)
+                               self.sourcewindows[fn] = wdbsrcwin. \
+                                         DebuggerSourceWindow(self, fn)
                        except IOError:
                                stdwin.fleep()
                                return
@@ -170,7 +168,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
                else:
                        import wdbframewin
                        self.framewindows[name] = \
-                               wdbframewin.FrameWindow().init(self, \
+                               wdbframewin.FrameWindow(self, \
                                        self.curframe, \
                                        self.curframe.f_locals, name)
        do_f = do_frame
@@ -182,7 +180,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
                else:
                        import wdbframewin
                        self.framewindows[name] = \
-                               wdbframewin.FrameWindow().init(self, \
+                               wdbframewin.FrameWindow(self, \
                                        self.curframe, \
                                        self.curframe.f_globals, name)
        do_g = do_globalframe
@@ -274,27 +272,27 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
 # Simplified interface
 
 def run(statement):
-       x = Wdb().init()
+       x = Wdb()
        try: x.run(statement)
        finally: x.close()
 
 def runctx(statement, globals, locals):
-       x = Wdb().init()
+       x = Wdb()
        try: x.runctx(statement, globals, locals)
        finally: x.close()
 
 def runcall(*args):
-       x = Wdb().init()
-       try: apply(Pdb().init().runcall, args)
+       x = Wdb()
+       try: apply(x.runcall, args)
        finally: x.close()
 
 
 # Post-Mortem interface
 
 def post_mortem(traceback):
-       p = Pdb().init()
-       p.reset()
-       p.interaction(None, traceback)
+       x = Wdb()
+       x.reset()
+       x.interaction(None, traceback)
 
 def pm():
        import sys
index f8b84e3ab0cefde8018ee7e1afa79e9aa12b7327..13bd1731a9cac03fab164588cb10defbe547606a 100644 (file)
@@ -17,7 +17,7 @@ MAXHEIGHT = 16
 
 class FrameWindow(basewin.BaseWindow):
 
-       def init(self, debugger, frame, dict, name):
+       def __init__(self, debugger, frame, dict, name):
                self.debugger = debugger
                self.frame = frame # Not used except for identity tests
                self.dict = dict
@@ -27,12 +27,12 @@ class FrameWindow(basewin.BaseWindow):
                width = WIDTH*stdwin.textwidth('0')
                height = nl*stdwin.lineheight()
                stdwin.setdefwinsize(width, height)
-               self = basewin.BaseWindow.init(self, '--Frame ' + name + '--')
+               basewin.BaseWindow.__init__(
+                         self, '--Frame ' + name + '--')
                # XXX Should use current function name
                self.initeditor()
                self.displaylist = ['>>>', '', '-'*WIDTH]
                self.refreshframe()
-               return self
        
        def initeditor(self):
                r = (stdwin.textwidth('>>> '), 0), (30000, stdwin.lineheight())
@@ -81,7 +81,7 @@ class FrameWindow(basewin.BaseWindow):
                                self.debugger.framewindows[name].popup()
                        else:
                                self.debugger.framewindows[name] = \
-                                         FrameWindow().init(self.debugger,
+                                         FrameWindow(self.debugger,
                                                  self.frame, value.__dict__,
                                                  name)
                        return
index 6c5cde8e0231a526d07f6f5e9dff4f0bcab46b9d..f79fab94be5303f0c7e6fe6c15ca34fe1c0feb9b 100644 (file)
@@ -7,11 +7,11 @@ import srcwin
 
 class DebuggerSourceWindow(srcwin.SourceWindow):
        
-       def init(self, debugger, filename):
+       def __init__(self, debugger, filename):
                self.debugger = debugger
                self.curlineno = 0
                self.focus = 0
-               return srcwin.SourceWindow.init(self, filename)
+               srcwin.SourceWindow.__init__(self, filename)
        
        def close(self):
                del self.debugger.sourcewindows[self.filename]
index 84eff9d0d3288edb848ad6f0af80c057bb2371ba..2a076f03459a9c1082334d8db976fbe02f6e6448 100644 (file)
@@ -10,15 +10,14 @@ import rfc822
 
 class Message(rfc822.Message):
 
-       def init(self, fp):
-               self = rfc822.Message.init(self, fp)
+       def __init__(self, fp):
+               rfc822.Message.__init__(self, fp)
                self.encodingheader = \
                        self.getheader('content-transfer-encoding')
                self.typeheader = \
                        self.getheader('content-type')
                self.parsetype()
                self.parseplist()
-               return self
 
        def parsetype(self):
                str = self.typeheader
index 4dd1b52c54d5ec9048ba156bfbbd41ae037708bb..7a52ab61335bfcbe7cd0699f56d48b5e46ab55d8 100644 (file)
@@ -6,7 +6,7 @@
 # Suggested use:
 #
 # real_fp = open(...)
-# fp = MultiFile().init(real_fp)
+# fp = MultiFile(real_fp)
 #
 # "read some lines from fp"
 # fp.push(separator)
@@ -31,14 +31,13 @@ Error = 'multifile.Error'
 
 class MultiFile:
        #
-       def init(self, fp):
+       def __init__(self, fp):
                self.fp = fp
                self.stack = [] # Grows down
                self.level = 0
                self.last = 0
                self.start = self.fp.tell()
                self.posstack = [] # Grows down
-               return self
        #
        def tell(self):
                if self.level > 0:
index 374f457dbc4982e725ec209effd091b558e747d1..b897863574d16cdbefcebd065c1df218b6e43e62 100644 (file)
@@ -15,10 +15,9 @@ class mutex:
        #
        # Create a new mutex -- initially unlocked
        #
-       def init(self):
+       def __init__(self):
                self.locked = 0
                self.queue = []
-               return self
        #
        # Test the locked bit of the mutex
        #
index c448d48241b2a74a179709f05f849e08d12c0bf1..e7f062759511f8071194c5c2d3c3e85a80ce88b9 100644 (file)
@@ -5,7 +5,7 @@
 # Example:
 #
 # >>> from nntplib import NNTP
-# >>> s = NNTP().init('charon')
+# >>> s = NNTP('charon')
 # >>> resp, count, first, last, name = s.group('nlnet.misc')
 # >>> print 'Group', name, 'has', count, 'articles, range', first, 'to', last
 # Group nlnet.misc has 525 articles, range 6960 to 7485
@@ -60,7 +60,7 @@ class NNTP:
        # - host: hostname to connect to
        # - 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 args: port = args[0]
                else: port = NNTP_PORT
@@ -71,10 +71,9 @@ class NNTP:
                self.file = self.sock.makefile('r')
                self.debugging = 0
                self.welcome = self.getresp()
-               return self
 
        # 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 it 201, posting is not allowed
 
index fd8835b14bdec5d51592b09633f9d8bcff3fa1a4..64451d5f4e8c3179c84e15e579f4bbdbd79d220a 100755 (executable)
@@ -16,9 +16,6 @@ class Pdb(bdb.Bdb, cmd.Cmd):
                bdb.Bdb.__init__(self)
                cmd.Cmd.__init__(self)
                self.prompt = '(Pdb) '
-
-       def init(self):                 # BW compat only
-               return self
        
        def reset(self):
                bdb.Bdb.reset(self)
index 426c3774722f84eaf0b6aa78ad8daf123f30703f..0ae0b8c9edd2deb6f7615b9b594a4af6df9d7505 100644 (file)
@@ -29,7 +29,7 @@
 # -----------
 #
 # To create a template:
-#   t = Template().init()
+#   t = Template()
 #
 # To add a conversion step to a template:
 #   t.append(command, kind)
@@ -85,11 +85,10 @@ stepkinds = [FILEIN_FILEOUT, STDIN_FILEOUT, FILEIN_STDOUT, STDIN_STDOUT, \
 
 class Template:
 
-       # Template().init() returns a fresh pipeline template
-       def init(self):
+       # Template() returns a fresh pipeline template
+       def __init__(self):
                self.debugging = 0
                self.reset()
-               return self
 
        # t.__repr__() implements `t`
        def __repr__(self):
@@ -102,7 +101,7 @@ class Template:
        # t.clone() returns a new pipeline template with identical
        # initial state as the current one
        def clone(self):
-               t = Template().init()
+               t = Template()
                t.steps = self.steps[:]
                t.debugging = self.debugging
                return t
@@ -291,7 +290,7 @@ def quote(file):
 def test():
        import os
        print 'Testing...'
-       t = Template().init()
+       t = Template()
        t.append('togif $IN $OUT', 'ff')
        t.append('giftoppm', '--')
        t.append('ppmtogif >$OUT', '-f')
index ced559836a7785692b0d4dc2fec22a99184acd0e..c3f6f3b2c533c3e1f92af5f60a1b44acc23cd834 100755 (executable)
@@ -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
@@ -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):
@@ -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)
index 7af6882b89d3e8f7886456a15c606617f76ec4a1..fffb6fe8c65096a7ddef9085fa96b70deccef963 100755 (executable)
@@ -30,7 +30,7 @@ class Readcd:
                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()
index 61297d0c7b0704bb2e5381ebff2b565c6884eeba..f283063c000c7936bc4b468db380c0e8e79c120d 100755 (executable)
@@ -13,40 +13,40 @@ import imghdr
 
 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', '--')
 
 
index 19b0476f3959cc8de538fb938a027e0cd5b56921..502a4dbfa727f1189e7c0dd0b2809b03b31da5e8 100755 (executable)
@@ -14,13 +14,12 @@ import marshal
 
 class Profile:
 
-       def init(self):
+       def __init__(self):
                self.timings = {}
                self.debug = None
                self.call_level = 0
                self.profile_func = None
                self.profiling = 0
-               return self
 
        def profile(self, funcname):
                if not self.profile_func:
@@ -230,12 +229,11 @@ def depth(frame):
        return d
 
 class Stats:
-       def init(self, file):
+       def __init__(self, file):
                f = open(file, 'r')
                self.stats = marshal.load(f)
                f.close()
                self.stats_list = None
-               return self
 
        def print_stats(self):
                print_title()
@@ -354,7 +352,7 @@ def f8(x):
 
 # simplified user interface
 def run(statement, *args):
-       prof = Profile().init()
+       prof = Profile()
        try:
                prof.run(statement)
        except SystemExit:
@@ -366,7 +364,7 @@ def run(statement, *args):
 
 # test command with debugging
 def debug():
-       prof = Profile().init()
+       prof = Profile()
        prof.debug = 1
        try:
                prof.run('import x; x.main()')
index 755f65ad7f45804ce08a11ed4bba9b20f8492ea8..613681488b1bda29ef81277000b15c90efaacc60 100644 (file)
@@ -4,13 +4,12 @@ import regex
 from regex_syntax import *
 
 class Prog:
-       def init(self, pat):
+       def __init__(self, pat):
                save_syntax = regex.set_syntax(RE_SYNTAX_AWK)
                try:
                        self.prog = regex.compile(pat)
                finally:
                        xxx = regex.set_syntax(save_syntax)
-               return self
        def match(self, *args):
                if len(args) == 2:
                        str, offset = args
@@ -27,7 +26,7 @@ class Prog:
                return regs[:i]
 
 def compile(pat):
-       return Prog().init(pat)
+       return Prog(pat)
 
 cache_pat = None
 cache_prog = None
index 68f374c7a2e3d32ed5ddfc860ab08050f423849d..50ee6c95c79a433608bc09de10c0843a549473a6 100644 (file)
@@ -3,7 +3,7 @@
 import string
 
 class Repr:
-       def init(self):
+       def __init__(self):
                self.maxlevel = 6
                self.maxtuple = 6
                self.maxlist = 6
@@ -11,7 +11,6 @@ class Repr:
                self.maxstring = 30
                self.maxlong = 40
                self.maxother = 20
-               return self
        def repr(self, x):
                return self.repr1(x, self.maxlevel)
        def repr1(self, x, level):
@@ -79,5 +78,5 @@ class Repr:
                        s = s[:i] + '...' + s[len(s)-j:]
                return s
 
-aRepr = Repr().init()
+aRepr = Repr()
 repr = aRepr.repr
index 63f2fb61f0d43664c774650da809ef473505f7cf..39ab6a608c4b8c745d016995383675d6459f6b19 100644 (file)
@@ -10,8 +10,8 @@
 #   fp = open(file, 'r')
 # (or use any other legal way of getting an open file object, e.g. use
 # sys.stdin or call os.popen()).
-# Then pass the open file object to the init() method of Message:
-#   m = Message().init(fp)
+# Then pass the open file object to the Message() constructor:
+#   m = Message(fp)
 #
 # To get the text of a particular header there are several methods:
 #   str = m.getheader(name)
@@ -35,7 +35,7 @@ class Message:
 
        # Initialize the class instance and read the headers.
        
-       def init(self, fp):
+       def __init__(self, fp):
                self.fp = fp
                #
                try:
@@ -49,8 +49,6 @@ class Message:
                        self.startofbody = self.fp.tell()
                except IOError:
                        self.startofbody = None
-               #
-               return self
 
 
        # Rewind the file to the start of the body (if seekable).
index 29ccc2add3a8fb1fcaf349a9f789a697e7db3260..c838bade820d33bd6aa72df13c58cbbb19e3194c 100644 (file)
@@ -34,11 +34,10 @@ class scheduler:
        #
        # Initialize a new instance, passing the time and delay functions
        #
-       def init(self, timefunc, delayfunc):
+       def __init__(self, timefunc, delayfunc):
                self.queue = []
                self.timefunc = timefunc
                self.delayfunc = delayfunc
-               return self
        #
        # Enter a new event in the queue at an absolute time.
        # Returns an ID for the event which can be used
index 67c3afbe22c2e1e6840eac11f1e7919d5d0f3d52..56ca6f853b0c15d5c84082ebb8c0f92209be2b2b 100755 (executable)
@@ -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
 #
index f896fe2a059ee434416ad24bfaa14bacfe3d4cbd..7a435369678b80bacd8ef168164ac335b5b4bcb8 100755 (executable)
@@ -6,11 +6,10 @@ from stdwinevents import *
 
 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()
index ac34ce952c649f870d6177dd27164242ba66e8ea..7ddfc1d6806253dabe004060fef0ee3e3d06721c 100755 (executable)
@@ -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
@@ -22,7 +22,6 @@ class formatter:
                self.justify = 1
                self.setfont('')        # Default font
                self._reset()           # Prepare for new line
-               return self
        #
        # Reset for start of fresh line.
        #
@@ -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:
index ca3e9ac4c54360ae9071b0c0481cde4cc4623c68..aa40c34b4ec508fa48a25b3ada1f7b9d4f20c8e0 100755 (executable)
@@ -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)
index a71c568ace9031b4030fa8e912fd7921ef095eb4..29b78010a616b9060aec78d8427c38f5db4075fa 100755 (executable)
@@ -10,7 +10,7 @@ MAXHEIGHT = 24
 
 class TextWindow(basewin.BaseWindow):
        
-       def init(self, title, contents):
+       def __init__(self, title, contents):
                self.contents = contents
                self.linecount = countlines(self.contents)
                #
@@ -23,11 +23,10 @@ class TextWindow(basewin.BaseWindow):
                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)
@@ -113,12 +112,12 @@ 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 ------------------------------
 
@@ -126,5 +125,5 @@ TESTFILE = 'srcwin.py'
 
 def test():
        import mainloop
-       sw = SourceWindow().init(TESTFILE)
+       sw = SourceWindow(TESTFILE)
        mainloop.mainloop()
index c499296c8a01c383a7743c6b02bc4a4aa3e9d74c..d5c28bb9f17f601483bca6b45452f308bff2d686 100755 (executable)
@@ -19,16 +19,15 @@ WdbDone = 'wdb.WdbDone' # Exception to continue execution
 
 class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
        
-       def init(self):
+       def __init__(self):
                self.sourcewindows = {}
                self.framewindows = {}
-               self = bdb.Bdb.init(self)
+               bdb.Bdb.__init__(self)
                width = WIDTH*stdwin.textwidth('0')
                height = HEIGHT*stdwin.lineheight()
                stdwin.setdefwinsize(width, height)
-               self = basewin.BaseWindow.init(self, '--Stack--')
+               basewin.BaseWindow.__init__(self, '--Stack--')
                self.closed = 0
-               return self
        
        def reset(self):
                if self.closed: raise RuntimeError, 'already closed'
@@ -151,9 +150,8 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
                if not self.sourcewindows.has_key(fn):
                        import wdbsrcwin
                        try:
-                               self.sourcewindows[fn] = \
-                                       wdbsrcwin.DebuggerSourceWindow(). \
-                                       init(self, fn)
+                               self.sourcewindows[fn] = wdbsrcwin. \
+                                         DebuggerSourceWindow(self, fn)
                        except IOError:
                                stdwin.fleep()
                                return
@@ -170,7 +168,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
                else:
                        import wdbframewin
                        self.framewindows[name] = \
-                               wdbframewin.FrameWindow().init(self, \
+                               wdbframewin.FrameWindow(self, \
                                        self.curframe, \
                                        self.curframe.f_locals, name)
        do_f = do_frame
@@ -182,7 +180,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
                else:
                        import wdbframewin
                        self.framewindows[name] = \
-                               wdbframewin.FrameWindow().init(self, \
+                               wdbframewin.FrameWindow(self, \
                                        self.curframe, \
                                        self.curframe.f_globals, name)
        do_g = do_globalframe
@@ -274,27 +272,27 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
 # Simplified interface
 
 def run(statement):
-       x = Wdb().init()
+       x = Wdb()
        try: x.run(statement)
        finally: x.close()
 
 def runctx(statement, globals, locals):
-       x = Wdb().init()
+       x = Wdb()
        try: x.runctx(statement, globals, locals)
        finally: x.close()
 
 def runcall(*args):
-       x = Wdb().init()
-       try: apply(Pdb().init().runcall, args)
+       x = Wdb()
+       try: apply(x.runcall, args)
        finally: x.close()
 
 
 # Post-Mortem interface
 
 def post_mortem(traceback):
-       p = Pdb().init()
-       p.reset()
-       p.interaction(None, traceback)
+       x = Wdb()
+       x.reset()
+       x.interaction(None, traceback)
 
 def pm():
        import sys
index f8b84e3ab0cefde8018ee7e1afa79e9aa12b7327..13bd1731a9cac03fab164588cb10defbe547606a 100755 (executable)
@@ -17,7 +17,7 @@ MAXHEIGHT = 16
 
 class FrameWindow(basewin.BaseWindow):
 
-       def init(self, debugger, frame, dict, name):
+       def __init__(self, debugger, frame, dict, name):
                self.debugger = debugger
                self.frame = frame # Not used except for identity tests
                self.dict = dict
@@ -27,12 +27,12 @@ class FrameWindow(basewin.BaseWindow):
                width = WIDTH*stdwin.textwidth('0')
                height = nl*stdwin.lineheight()
                stdwin.setdefwinsize(width, height)
-               self = basewin.BaseWindow.init(self, '--Frame ' + name + '--')
+               basewin.BaseWindow.__init__(
+                         self, '--Frame ' + name + '--')
                # XXX Should use current function name
                self.initeditor()
                self.displaylist = ['>>>', '', '-'*WIDTH]
                self.refreshframe()
-               return self
        
        def initeditor(self):
                r = (stdwin.textwidth('>>> '), 0), (30000, stdwin.lineheight())
@@ -81,7 +81,7 @@ class FrameWindow(basewin.BaseWindow):
                                self.debugger.framewindows[name].popup()
                        else:
                                self.debugger.framewindows[name] = \
-                                         FrameWindow().init(self.debugger,
+                                         FrameWindow(self.debugger,
                                                  self.frame, value.__dict__,
                                                  name)
                        return
index 6c5cde8e0231a526d07f6f5e9dff4f0bcab46b9d..f79fab94be5303f0c7e6fe6c15ca34fe1c0feb9b 100755 (executable)
@@ -7,11 +7,11 @@ import srcwin
 
 class DebuggerSourceWindow(srcwin.SourceWindow):
        
-       def init(self, debugger, filename):
+       def __init__(self, debugger, filename):
                self.debugger = debugger
                self.curlineno = 0
                self.focus = 0
-               return srcwin.SourceWindow.init(self, filename)
+               srcwin.SourceWindow.__init__(self, filename)
        
        def close(self):
                del self.debugger.sourcewindows[self.filename]
index 2cb35a7ebdcb789d123a57aacbc332318b341a09..08e4d208a2ac1850483a04792f4e0f7a0764c064 100644 (file)
@@ -192,11 +192,12 @@ class Au_read:
                                        break
                else:
                        self._info = ''
-               return self
 
-       def init(self, filename):
-               import builtin
-               return self.initfp(builtin.open(filename, 'r'))
+       def __init__(self, f):
+               if type(f) == type(''):
+                       import builtin
+                       f = builtin.open(f, 'r')
+               self.initfp(f)
 
        def __del__(self):
                if self._file:
@@ -277,9 +278,11 @@ class Au_read:
                self._file = None
 
 class Au_write:
-       def init(self, filename):
-               import builtin
-               return self.initfp(builtin.open(filename, 'w'))
+       def __init__(self, f):
+               if type(f) == type(''):
+                       import builtin
+                       f = builtin.open(f, 'w')
+               self.initfp(f)
 
        def initfp(self, file):
                self._file = file
@@ -293,7 +296,6 @@ class Au_write:
                self._datalength = 0
                self._info = ''
                self._comptype = 'ULAW' # default is U-law
-               return self
 
        def __del__(self):
                if self._file:
@@ -453,18 +455,12 @@ class Au_write:
                self._datalength = self._datawritten
                self._file.seek(0, 2)
 
-def open(filename, mode):
+def open(f, mode):
        if mode == 'r':
-               return Au_read().init(filename)
+               return Au_read(f)
        elif mode == 'w':
-               return Au_write().init(filename)
+               return Au_write(f)
        else:
                raise Error, "mode must be 'r' or 'w'"
 
-def openfp(filep, mode):
-       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'"
+openfp = open
index 57e3674865bbad905d7e7eb56ed437ea485ff010..79d9b11553ec39dc8bce43f08fd3c4684cbe3158 100644 (file)
@@ -42,9 +42,8 @@ TestFailed = 'autotest.TestFailed'
 
 # Class substituted for sys.stdout, to compare it with the given file
 class Compare:
-       def init(self, filename):
+       def __init__(self, filename):
                self.fp = open(filename, 'r')
-               return self
        def write(self, data):
                expected = self.fp.read(len(data))
                if data <> expected:
@@ -59,7 +58,7 @@ def main():
        filename = findfile('testall.out')
        real_stdout = sys.stdout
        try:
-               sys.stdout = Compare().init(filename)
+               sys.stdout = Compare(filename)
                import testall
        finally:
                sys.stdout = real_stdout
index d2f5cd769c6281d5f0123ae8360d27a057588177..0001be022fd2dff67e46778becf52c258f79baa6 100644 (file)
@@ -13,7 +13,7 @@ import whatsound
 
 table = {}
 
-t = pipes.Template().init()
+t = pipes.Template()
 t.append('sox -t au - -t aiff -r 8000 -', '--')
 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 sampled at 11k are unnecessarily expanded.
 # 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 -', '--')
 table['hcom'] = t
 
-t = pipes.Template().init()
+t = pipes.Template()
 t.append('sox -t voc - -t aiff -r 11025 -', '--')
 table['voc'] = t
 
-t = pipes.Template().init()
+t = pipes.Template()
 t.append('sox -t wav - -t aiff -', '--')
 table['wav'] = t
 
-t = pipes.Template().init()
+t = pipes.Template()
 t.append('sox -t 8svx - -t aiff -r 16000 -', '--')
 table['8svx'] = t
 
-t = pipes.Template().init()
+t = pipes.Template()
 t.append('sox -t sndt - -t aiff -r 16000 -', '--')
 table['sndt'] = t
 
-t = pipes.Template().init()
+t = pipes.Template()
 t.append('sox -t sndr - -t aiff -r 16000 -', '--')
 table['sndr'] = t
 
-uncompress = pipes.Template().init()
+uncompress = pipes.Template()
 uncompress.append('uncompress', '--')
 
 
index 0a346903c847bc3e88ded35db355926764dc0ee7..c7881b551b5a9d16234d402339fa21f2fb444291 100644 (file)
@@ -35,7 +35,7 @@ class whrandom:
        # Without arguments, initialize from current time.
        # With arguments (x, y, z), initialize from them.
        #
-       def init(self, *xyz):
+       def __init__(self, *xyz):
                if not xyz:
                        # Initialize from current time
                        import time
@@ -47,7 +47,6 @@ class whrandom:
                        # Initialize from arguments (x, y, z)
                        x, y, z = xyz
                self.seed(x, y, z)
-               return self
        #
        # Set the seed from (x, y, z).
        # These must be integers in the range [0, 256).
@@ -97,7 +96,7 @@ class whrandom:
 
 # Initialize from the current time
 #
-_inst = whrandom().init()
+_inst = whrandom()
 seed = _inst.seed
 random = _inst.random
 uniform = _inst.uniform