]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
* calendar.py: minor cleanups
authorGuido van Rossum <guido@python.org>
Thu, 17 Jun 1993 12:38:10 +0000 (12:38 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 17 Jun 1993 12:38:10 +0000 (12:38 +0000)
* ftplib.py: support __init__ with optional host, port args
* aifc.py: ensure header is written on close even when no data is written

Lib/aifc.py
Lib/calendar.py
Lib/ftplib.py

index e45792e0a2f9c91ec46e271d2fc7c4b453dd07a0..8c04ea30b3e06f5b18cfecd8196caad104a82e2d 100644 (file)
@@ -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:
index a2bd398f45f424b5a93fda30c13e4f3ccda8e012..160b8babd4934a587965735a6a5a60473b9550fb 100644 (file)
@@ -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)
index c886f8226c3042576cfc3f4118a24b9d1c3d0889..e846ffe30b207125363cdcd51a9820ac24266969 100644 (file)
@@ -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')