summaryrefslogtreecommitdiffstats
path: root/Lib/aifc.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-06-17 12:38:10 (GMT)
committerGuido van Rossum <guido@python.org>1993-06-17 12:38:10 (GMT)
commit52fc1f607eab013b1e7688b4cfb3b09fb82ce9eb (patch)
tree33fed994c8981b8d1866362b1708c8d39916f1db /Lib/aifc.py
parent234f942aefb779efa6cfb7225e21d16a3f7e80f7 (diff)
downloadcpython-52fc1f607eab013b1e7688b4cfb3b09fb82ce9eb.zip
cpython-52fc1f607eab013b1e7688b4cfb3b09fb82ce9eb.tar.gz
cpython-52fc1f607eab013b1e7688b4cfb3b09fb82ce9eb.tar.bz2
* calendar.py: minor cleanups
* ftplib.py: support __init__ with optional host, port args * aifc.py: ensure header is written on close even when no data is written
Diffstat (limited to 'Lib/aifc.py')
-rw-r--r--Lib/aifc.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/Lib/aifc.py b/Lib/aifc.py
index e45792e..8c04ea3 100644
--- a/Lib/aifc.py
+++ b/Lib/aifc.py
@@ -619,6 +619,7 @@ class Aifc_write:
self._nframes = 0
self._nframeswritten = 0
self._datawritten = 0
+ self._datalength = 0
self._markers = []
self._marklength = 0
self._aifc = 1 # AIFF-C is default
@@ -743,19 +744,7 @@ class Aifc_write:
return self._markers
def writeframesraw(self, data):
- if not self._nframeswritten:
- if self._comptype in ('ULAW', 'ALAW'):
- if not self._sampwidth:
- self._sampwidth = AL.SAMPLE_16
- if self._sampwidth != AL.SAMPLE_16:
- raise Error, 'sample width must be 2 when compressing with ULAW or ALAW'
- if not self._nchannels:
- raise Error, '# channels not specified'
- if not self._sampwidth:
- raise Error, 'sample width not specified'
- if not self._framerate:
- raise Error, 'sampling rate not specified'
- self._write_header(len(data))
+ self._ensure_header_written(len(data))
nframes = len(data) / (self._sampwidth * self._nchannels)
if self._comp:
dummy = self._comp.SetParam(CL.FRAME_BUFFER_SIZE, \
@@ -774,6 +763,7 @@ class Aifc_write:
self._patchheader()
def close(self):
+ self._ensure_header_written(0)
if self._datawritten & 1:
# quick pad to even size
self._file.write(chr(0))
@@ -792,6 +782,21 @@ class Aifc_write:
#
# Internal methods.
#
+ def _ensure_header_written(self, datasize):
+ if not self._nframeswritten:
+ if self._comptype in ('ULAW', 'ALAW'):
+ if not self._sampwidth:
+ self._sampwidth = AL.SAMPLE_16
+ if self._sampwidth != AL.SAMPLE_16:
+ raise Error, 'sample width must be 2 when compressing with ULAW or ALAW'
+ if not self._nchannels:
+ raise Error, '# channels not specified'
+ if not self._sampwidth:
+ raise Error, 'sample width not specified'
+ if not self._framerate:
+ raise Error, 'sampling rate not specified'
+ self._write_header(datasize)
+
def _write_header(self, initlength):
if self._aifc and self._comptype != 'NONE':
try: