[Python-checkins] CVS: python/dist/src/Lib ftplib.py,1.57,1.58 httplib.py,1.39,1.40 poplib.py,1.17,1.18 smtplib.py,1.43,1.44 telnetlib.py,1.15,1.16

Martin v. L?wis loewis@users.sourceforge.net
Sun, 07 Oct 2001 01:53:34 -0700


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

Modified Files:
	ftplib.py httplib.py poplib.py smtplib.py telnetlib.py 
Log Message:
Only close sockets if they have been created. Reported by Blake Winton.


Index: ftplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ftplib.py,v
retrieving revision 1.57
retrieving revision 1.58
diff -C2 -d -r1.57 -r1.58
*** ftplib.py	2001/08/17 17:24:29	1.57
--- ftplib.py	2001/10/07 08:53:32	1.58
***************
*** 123,127 ****
                  self.sock.connect(sa)
              except socket.error, msg:
!                 self.sock.close()
                  self.sock = None
                  continue
--- 123,128 ----
                  self.sock.connect(sa)
              except socket.error, msg:
!                 if self.sock:
!                     self.sock.close()
                  self.sock = None
                  continue
***************
*** 273,276 ****
--- 274,278 ----
          '''Create a new socket and send a PORT command for it.'''
          msg = "getaddrinfo returns an empty list"
+         sock = None
          for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
              af, socktype, proto, canonname, sa = res
***************
*** 279,283 ****
                  sock.bind(sa)
              except socket.error, msg:
!                 sock.close()
                  sock = None
                  continue
--- 281,286 ----
                  sock.bind(sa)
              except socket.error, msg:
!                 if sock:
!                     sock.close()
                  sock = None
                  continue

Index: httplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/httplib.py,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** httplib.py	2001/08/18 09:20:23	1.39
--- httplib.py	2001/10/07 08:53:32	1.40
***************
*** 369,373 ****
                  if self.debuglevel > 0:
                      print 'connect fail:', (self.host, self.port)
!                 self.sock.close()
                  self.sock = None
                  continue
--- 369,374 ----
                  if self.debuglevel > 0:
                      print 'connect fail:', (self.host, self.port)
!                 if self.sock:
!                     self.sock.close()
                  self.sock = None
                  continue

Index: poplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/poplib.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** poplib.py	2001/07/31 08:40:21	1.17
--- poplib.py	2001/10/07 08:53:32	1.18
***************
*** 77,80 ****
--- 77,81 ----
          self.port = port
          msg = "getaddrinfo returns an empty list"
+         self.sock = None
          for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM):
              af, socktype, proto, canonname, sa = res
***************
*** 83,87 ****
                  self.sock.connect(sa)
              except socket.error, msg:
!                 self.sock.close()
                  self.sock = None
                  continue
--- 84,89 ----
                  self.sock.connect(sa)
              except socket.error, msg:
!                 if self.sock:
!                     self.sock.close()
                  self.sock = None
                  continue

Index: smtplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/smtplib.py,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** smtplib.py	2001/09/18 02:26:39	1.43
--- smtplib.py	2001/10/07 08:53:32	1.44
***************
*** 266,269 ****
--- 266,270 ----
          if self.debuglevel > 0: print 'connect:', (host, port)
          msg = "getaddrinfo returns an empty list"
+         self.sock = None
          for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
              af, socktype, proto, canonname, sa = res
***************
*** 274,278 ****
              except socket.error, msg:
                  if self.debuglevel > 0: print 'connect fail:', (host, port)
!                 self.sock.close()
                  self.sock = None
                  continue
--- 275,280 ----
              except socket.error, msg:
                  if self.debuglevel > 0: print 'connect fail:', (host, port)
!                 if self.sock:
!                     self.sock.close()
                  self.sock = None
                  continue

Index: telnetlib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/telnetlib.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** telnetlib.py	2001/09/06 08:51:38	1.15
--- telnetlib.py	2001/10/07 08:53:32	1.16
***************
*** 211,215 ****
                  self.sock.connect(sa)
              except socket.error, msg:
!                 self.sock.close()
                  self.sock = None
                  continue
--- 211,216 ----
                  self.sock.connect(sa)
              except socket.error, msg:
!                 if self.sock:
!                     self.sock.close()
                  self.sock = None
                  continue