diff options
author | Fred Drake <fdrake@acm.org> | 2001-02-28 21:46:37 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-02-28 21:46:37 (GMT) |
commit | 9c98a428ef2d4ec0084d2cbc327ed2b94e9afe66 (patch) | |
tree | 63c483a0886765c34289965839cf5063d8fce392 | |
parent | 2fd456508fe1f6e9d89e153f2d8e83a95b233504 (diff) | |
download | cpython-9c98a428ef2d4ec0084d2cbc327ed2b94e9afe66.zip cpython-9c98a428ef2d4ec0084d2cbc327ed2b94e9afe66.tar.gz cpython-9c98a428ef2d4ec0084d2cbc327ed2b94e9afe66.tar.bz2 |
Move some constant initialization from FTP.__init__() and FTP.connect()
to the class namespace.
Allow FTP.close() to be called more than once without tossing cookies.
(This seems to be a fairly common idiom for .close() methods, so let's
try to be consistent.)
-rw-r--r-- | Lib/ftplib.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py index 6819c1d..1688d9a 100644 --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -91,30 +91,29 @@ class FTP: and PORT or PASV commands. ''' + debugging = 0 + host = '' + port = FTP_PORT + sock = None + file = None + welcome = None + passiveserver = 1 + # Initialization method (called by class instantiation). # Initialize host to localhost, port to standard ftp port # Optional arguments are host (for connect()), # and user, passwd, acct (for login()) - def __init__(self, host = '', user = '', passwd = '', acct = ''): - # 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 - resp = None + def __init__(self, host='', user='', passwd='', acct=''): if host: - resp = self.connect(host) - if user: resp = self.login(user, passwd, acct) + self.connect(host) + if user: self.login(user, passwd, acct) - def connect(self, host = '', port = 0): + def connect(self, host='', port=0): '''Connect to host. Arguments are: - host: hostname to connect to (string, default previous host) - port: port to connect to (integer, default previous port)''' if host: self.host = host if port: self.port = port - self.passiveserver = 1 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.connect((self.host, self.port)) self.file = self.sock.makefile('rb') @@ -480,9 +479,10 @@ class FTP: def close(self): '''Close the connection without assuming anything about it.''' - self.file.close() - self.sock.close() - del self.file, self.sock + if self.file: + self.file.close() + self.sock.close() + self.file = self.sock = None _150_re = None |