diff options
Diffstat (limited to 'Lib/socket.py')
-rw-r--r-- | Lib/socket.py | 8 |
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): |