summaryrefslogtreecommitdiffstats
path: root/Lib/socket.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-01-21 10:35:10 (GMT)
committerGeorg Brandl <georg@python.org>2007-01-21 10:35:10 (GMT)
commitdd7b0525e902ee12a612611ea082e12f5999c823 (patch)
treeea6fda1769b0311d8f166d05d32d112afaa82c25 /Lib/socket.py
parentb84c13792db49abdfac97663badfeda0bba11279 (diff)
downloadcpython-dd7b0525e902ee12a612611ea082e12f5999c823.zip
cpython-dd7b0525e902ee12a612611ea082e12f5999c823.tar.gz
cpython-dd7b0525e902ee12a612611ea082e12f5999c823.tar.bz2
Patch #1627441: close sockets properly in urllib2.
Diffstat (limited to 'Lib/socket.py')
-rw-r--r--Lib/socket.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/socket.py b/Lib/socket.py
index 52fb8e3..b4969bd 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -204,9 +204,10 @@ class _fileobject(object):
__slots__ = ["mode", "bufsize", "softspace",
# "closed" is a property, see below
- "_sock", "_rbufsize", "_wbufsize", "_rbuf", "_wbuf"]
+ "_sock", "_rbufsize", "_wbufsize", "_rbuf", "_wbuf",
+ "_close"]
- def __init__(self, sock, mode='rb', bufsize=-1):
+ def __init__(self, sock, mode='rb', bufsize=-1, close=False):
self._sock = sock
self.mode = mode # Not actually used in this version
if bufsize < 0:
@@ -222,6 +223,7 @@ class _fileobject(object):
self._wbufsize = bufsize
self._rbuf = "" # A string
self._wbuf = [] # A list of strings
+ self._close = close
def _getclosed(self):
return self._sock is None
@@ -232,6 +234,8 @@ class _fileobject(object):
if self._sock:
self.flush()
finally:
+ if self._close:
+ self._sock.close()
self._sock = None
def __del__(self):