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/ftplib.py | |
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/ftplib.py')
-rw-r--r-- | Lib/ftplib.py | 33 |
1 files changed, 24 insertions, 9 deletions
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') |