[Python-checkins] CVS: python/dist/src/Lib ftplib.py,1.51,1.52

Fred L. Drake fdrake@users.sourceforge.net
Wed, 28 Feb 2001 13:46:39 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv28976

Modified Files:
	ftplib.py 
Log Message:

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.)


Index: ftplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ftplib.py,v
retrieving revision 1.51
retrieving revision 1.52
diff -C2 -r1.51 -r1.52
*** ftplib.py	2001/02/15 13:50:36	1.51
--- ftplib.py	2001/02/28 21:46:37	1.52
***************
*** 92,113 ****
  '''
  
      # 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
          if host:
!             resp = self.connect(host)
!             if user: resp = self.login(user, passwd, acct)
  
!     def connect(self, host = '', port = 0):
          '''Connect to host.  Arguments are:
          - host: hostname to connect to (string, default previous host)
--- 92,113 ----
  '''
  
+     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=''):
          if host:
!             self.connect(host)
!             if user: self.login(user, passwd, acct)
  
!     def connect(self, host='', port=0):
          '''Connect to host.  Arguments are:
          - host: hostname to connect to (string, default previous host)
***************
*** 115,119 ****
          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))
--- 115,118 ----
***************
*** 481,487 ****
      def close(self):
          '''Close the connection without assuming anything about it.'''
!         self.file.close()
!         self.sock.close()
!         del self.file, self.sock
  
  
--- 480,487 ----
      def close(self):
          '''Close the connection without assuming anything about it.'''
!         if self.file:
!             self.file.close()
!             self.sock.close()
!             self.file = self.sock = None