diff options
author | Guido van Rossum <guido@python.org> | 1993-06-17 12:38:10 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1993-06-17 12:38:10 (GMT) |
commit | 52fc1f607eab013b1e7688b4cfb3b09fb82ce9eb (patch) | |
tree | 33fed994c8981b8d1866362b1708c8d39916f1db /Lib | |
parent | 234f942aefb779efa6cfb7225e21d16a3f7e80f7 (diff) | |
download | cpython-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')
-rw-r--r-- | Lib/aifc.py | 31 | ||||
-rw-r--r-- | Lib/calendar.py | 11 | ||||
-rw-r--r-- | Lib/ftplib.py | 33 |
3 files changed, 49 insertions, 26 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: diff --git a/Lib/calendar.py b/Lib/calendar.py index a2bd398..160b8ba 100644 --- a/Lib/calendar.py +++ b/Lib/calendar.py @@ -9,11 +9,18 @@ # - the order of the elements of a 'struct tm' differs, to ease sorting # - months numbers are 1-12, not 0-11; month arrays have a dummy element 0 # - Monday is the first day of the week (numbered 0) +# - years are expressed in full, e.g. 1970, not 70. +# - timezone is currently hardcoded +# - doesn't know about daylight saving time # These are really parameters of the 'time' module: epoch = 1970 # Time began on January 1 of this year (00:00:00 UTC) day_0 = 3 # The epoch begins on a Thursday (Monday = 0) +# Localization: Minutes West from Greenwich +timezone = -2*60 # Middle-European time with DST on +# timezone = 5*60 # EST (sigh -- THINK time() doesn't return UTC) + # Return 1 for leap years, 0 for non-leap years def isleap(year): return year % 4 == 0 and (year % 100 <> 0 or year % 400 == 0) @@ -97,10 +104,6 @@ def asctime(arg): s = s + ' ' + dd(`hours`) + ':' + dd(`mins`) + ':' + dd(`secs`) return s + ' ' + `year` -# Localization: Minutes West from Greenwich -timezone = -2*60 # Middle-European time with DST on -# timezone = 5*60 # EST (sigh -- THINK time() doesn't return UTC) - # Local time ignores DST issues for now -- adjust 'timezone' to fake it def localtime(secs): return gmtime(secs - timezone*60) diff --git a/Lib/ftplib.py b/Lib/ftplib.py index c886f82..e846ffe 100644 --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -68,16 +68,31 @@ PORT_CYCLE = 1000 # The class itself class FTP: - # Initialize an instance. Arguments: - # - host: hostname to connect to - # - port: port to connect to (default the standard FTP port) - def init(self, host, *args): - if len(args) > 1: raise TypeError, 'too many args' - if args: port = args[0] - else: port = FTP_PORT - self.host = host - self.port = port + # New initialization method (called by class instantiation) + # Initialize host to localhost, port to standard ftp port + def __init__(self, *args): + # Initialize the instance to something mostly harmless self.debugging = 0 + self.host = '' + self.port = FTP_PORT + self.sock = None + self.file = None + self.welcome = None + if args: + apply(self.connect, args) + + # 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) + def init(self, *args): + if args: self.host = args[0] + if args[1:]: self.port = args[1] + if args[2:]: raise TypeError, 'too many args' self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.connect(self.host, self.port) self.file = self.sock.makefile('r') |