summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2001-10-07 08:53:32 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2001-10-07 08:53:32 (GMT)
commit322c0d187d834013d70ffdb0f7f1b6f72eef6443 (patch)
treeca8bbe6526e9f3c88b6311691e7936bfdc0480b0 /Lib
parentfb163784ab8ec237fdc3bffd018efe653ae07a1d (diff)
downloadcpython-322c0d187d834013d70ffdb0f7f1b6f72eef6443.zip
cpython-322c0d187d834013d70ffdb0f7f1b6f72eef6443.tar.gz
cpython-322c0d187d834013d70ffdb0f7f1b6f72eef6443.tar.bz2
Only close sockets if they have been created. Reported by Blake Winton.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/ftplib.py7
-rw-r--r--Lib/httplib.py3
-rw-r--r--Lib/poplib.py4
-rwxr-xr-xLib/smtplib.py4
-rw-r--r--Lib/telnetlib.py3
5 files changed, 15 insertions, 6 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index 4aa6244..4d5ac1a 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -122,7 +122,8 @@ class FTP:
self.sock = socket.socket(af, socktype, proto)
self.sock.connect(sa)
except socket.error, msg:
- self.sock.close()
+ if self.sock:
+ self.sock.close()
self.sock = None
continue
break
@@ -272,13 +273,15 @@ class FTP:
def makeport(self):
'''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
try:
sock = socket.socket(af, socktype, proto)
sock.bind(sa)
except socket.error, msg:
- sock.close()
+ if sock:
+ sock.close()
sock = None
continue
break
diff --git a/Lib/httplib.py b/Lib/httplib.py
index 0e0ec56..fa63787 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -368,7 +368,8 @@ class HTTPConnection:
except socket.error, msg:
if self.debuglevel > 0:
print 'connect fail:', (self.host, self.port)
- self.sock.close()
+ if self.sock:
+ self.sock.close()
self.sock = None
continue
break
diff --git a/Lib/poplib.py b/Lib/poplib.py
index 98b81ce..cb3e004 100644
--- a/Lib/poplib.py
+++ b/Lib/poplib.py
@@ -76,13 +76,15 @@ class POP3:
self.host = host
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
try:
self.sock = socket.socket(af, socktype, proto)
self.sock.connect(sa)
except socket.error, msg:
- self.sock.close()
+ if self.sock:
+ self.sock.close()
self.sock = None
continue
break
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 4527a84..8e98608 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -265,6 +265,7 @@ class SMTP:
if not port: port = SMTP_PORT
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
try:
@@ -273,7 +274,8 @@ class SMTP:
self.sock.connect(sa)
except socket.error, msg:
if self.debuglevel > 0: print 'connect fail:', (host, port)
- self.sock.close()
+ if self.sock:
+ self.sock.close()
self.sock = None
continue
break
diff --git a/Lib/telnetlib.py b/Lib/telnetlib.py
index c8ddd97..15721c6 100644
--- a/Lib/telnetlib.py
+++ b/Lib/telnetlib.py
@@ -210,7 +210,8 @@ class Telnet:
self.sock = socket.socket(af, socktype, proto)
self.sock.connect(sa)
except socket.error, msg:
- self.sock.close()
+ if self.sock:
+ self.sock.close()
self.sock = None
continue
break