@@ -287,15 +287,14 @@ def _write_float(f, x):
287287 _write_long (f , lomant )
288288
289289class Chunk :
290- def init (self , file ):
290+ def __init__ (self , file ):
291291 self .file = file
292292 self .chunkname = self .file .read (4 )
293293 if len (self .chunkname ) < 4 :
294294 raise EOFError
295295 self .chunksize = _read_long (self .file )
296296 self .size_read = 0
297297 self .offset = self .file .tell ()
298- return self
299298
300299 def rewind (self ):
301300 self .file .seek (self .offset , 0 )
@@ -333,7 +332,7 @@ class Aifc_read:
333332 # These variables are available to the user though appropriate
334333 # methods of this class:
335334 # _file -- the open file with methods read(), close(), and seek()
336- # set through the init() ir initfp () method
335+ # set through the __init__ () method
337336 # _nchannels -- the number of audio channels
338337 # available through the getnchannels() method
339338 # _nframes -- the number of audio frames
@@ -389,7 +388,7 @@ def initfp(self, file):
389388 #DEBUG: SGI's soundfiler has a bug. There should
390389 # be no need to check for EOF here.
391390 try :
392- chunk = Chunk (). init ( self ._file )
391+ chunk = Chunk (self ._file )
393392 except EOFError :
394393 if formlength == 8 :
395394 print 'Warning: FORM chunk size too large'
@@ -433,10 +432,12 @@ def initfp(self, file):
433432 else :
434433 params [3 ] = 24
435434 self ._decomp .SetParams (params )
436- return self
437435
438- def init (self , filename ):
439- return self .initfp (builtin .open (filename , 'r' ))
436+ def __init__ (self , f ):
437+ if type (f ) == type ('' ):
438+ f = builtin .open (f , 'r' )
439+ # else, assume it is an open file object already
440+ self .initfp (f )
440441
441442 def __del__ (self ):
442443 if self ._file :
@@ -610,7 +611,7 @@ class Aifc_write:
610611 # These variables are user settable through appropriate methods
611612 # of this class:
612613 # _file -- the open file with methods write(), close(), tell(), seek()
613- # set through the init() or initfp () method
614+ # set through the __init__ () method
614615 # _comptype -- the AIFF-C compression type ('NONE' in AIFF)
615616 # set through the setcomptype() or setparams() method
616617 # _compname -- the human-readable AIFF-C compression type
@@ -634,13 +635,15 @@ class Aifc_write:
634635 # _datalength -- the size of the audio samples written to the header
635636 # _datawritten -- the size of the audio samples actually written
636637
637- def init (self , filename ):
638- self = self .initfp (builtin .open (filename , 'w' ))
638+ def __init__ (self , f ):
639+ if type (f ) == type ('' ):
640+ f = builtin .open (f , 'w' )
641+ # else, assume it is an open file object already
642+ self .initfp (f )
639643 if filename [- 5 :] == '.aiff' :
640644 self ._aifc = 0
641645 else :
642646 self ._aifc = 1
643- return self
644647
645648 def initfp (self , file ):
646649 self ._file = file
@@ -659,7 +662,6 @@ def initfp(self, file):
659662 self ._markers = []
660663 self ._marklength = 0
661664 self ._aifc = 1 # AIFF-C is default
662- return self
663665
664666 def __del__ (self ):
665667 if self ._file :
@@ -976,18 +978,12 @@ def _writemarkers(self):
976978 _write_long (self ._file , pos )
977979 _write_string (self ._file , name )
978980
979- def open (filename , mode ):
981+ def open (f , mode ):
980982 if mode == 'r' :
981- return Aifc_read (). init ( filename )
983+ return Aifc_read (f )
982984 elif mode == 'w' :
983- return Aifc_write (). init ( filename )
985+ return Aifc_write (f )
984986 else :
985987 raise Error , 'mode must be \' r\' or \' w\' '
986988
987- def openfp (filep , mode ):
988- if mode == 'r' :
989- return Aifc_read ().initfp (filep )
990- elif mode == 'w' :
991- return Aifc_write ().initfp (filep )
992- else :
993- raise Error , 'mode must be \' r\' or \' w\' '
989+ openfp = open # B/W compatibility
0 commit comments