cpython: f7ddec2e9e93 (original) (raw)

Mercurial > cpython

changeset 95517:f7ddec2e9e93 2.7

Issue #23865: close() methods in multiple modules now are idempotent and more robust at shutdown. If needs to release multiple resources, they are released even if errors are occured. [#23865]

Serhiy Storchaka storchaka@gmail.com
date Fri, 10 Apr 2015 13:24:10 +0300
parents 50ed581fea04
children 0db36098b908
files Lib/aifc.py Lib/binhex.py Lib/chunk.py Lib/distutils/text_file.py Lib/dumbdbm.py Lib/fileinput.py Lib/ftplib.py Lib/gzip.py Lib/httplib.py Lib/logging/__init__.py Lib/logging/handlers.py Lib/mailbox.py Lib/multiprocessing/connection.py Lib/multiprocessing/queues.py Lib/shelve.py Lib/smtplib.py Lib/tarfile.py Lib/telnetlib.py Lib/tempfile.py Lib/urllib.py Lib/wave.py Lib/xml/sax/expatreader.py Lib/xmlrpclib.py Misc/NEWS
diffstat 24 files changed, 263 insertions(+), 175 deletions(-)[+] [-] Lib/aifc.py 11 Lib/binhex.py 44 Lib/chunk.py 6 Lib/distutils/text_file.py 4 Lib/dumbdbm.py 6 Lib/fileinput.py 40 Lib/ftplib.py 15 Lib/gzip.py 26 Lib/httplib.py 21 Lib/logging/__init__.py 21 Lib/logging/handlers.py 23 Lib/mailbox.py 12 Lib/multiprocessing/connection.py 10 Lib/multiprocessing/queues.py 10 Lib/shelve.py 24 Lib/smtplib.py 16 Lib/tarfile.py 61 Lib/telnetlib.py 5 Lib/tempfile.py 8 Lib/urllib.py 15 Lib/wave.py 22 Lib/xml/sax/expatreader.py 14 Lib/xmlrpclib.py 20 Misc/NEWS 4

line wrap: on

line diff

--- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -357,10 +357,13 @@ class Aifc_read: self._soundpos = 0 def close(self):

def tell(self): return self._soundpos

--- a/Lib/binhex.py +++ b/Lib/binhex.py @@ -32,7 +32,8 @@ class Error(Exception): pass

States (what have we written)

-[_DID_HEADER, _DID_DATA, _DID_RSRC] = range(3) +_DID_HEADER = 0 +_DID_DATA = 1

Various constants

REASONABLY_LARGE=32768 # Minimal amount we pass the rle-coder @@ -235,17 +236,22 @@ class BinHex: self._write(data) def close(self):

def binhex(inp, out): """(infilename, outfilename) - Create binhex-encoded copy of a file""" @@ -463,11 +469,15 @@ class HexBin: return self._read(n) def close(self):

def hexbin(inp, out): """(infilename, outfilename) - Decode binhexed file"""

--- a/Lib/chunk.py +++ b/Lib/chunk.py @@ -85,8 +85,10 @@ class Chunk: def close(self): if not self.closed:

def isatty(self): if self.closed:

--- a/Lib/distutils/text_file.py +++ b/Lib/distutils/text_file.py @@ -124,11 +124,11 @@ class TextFile: def close (self): """Close the current file and forget everything we know about it (filename, current line number).""" -

def gen_error (self, msg, line=None):

--- a/Lib/dumbdbm.py +++ b/Lib/dumbdbm.py @@ -209,8 +209,10 @@ class _Database(UserDict.DictMixin): return len(self._index) def close(self):

del = close

--- a/Lib/fileinput.py +++ b/Lib/fileinput.py @@ -233,8 +233,10 @@ class FileInput: self.close() def close(self):

def iter(self): return self @@ -270,23 +272,25 @@ class FileInput: output = self._output self._output = 0

-

-

def readline(self): try:

--- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -594,11 +594,16 @@ class FTP: def close(self): '''Close the connection without assuming anything about it.'''

try: import ssl

--- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -369,19 +369,21 @@ class GzipFile(io.BufferedIOBase): return self.fileobj is None def close(self):

def flush(self,zlib_mode=zlib.Z_SYNC_FLUSH): self._check_closed()

--- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -560,9 +560,10 @@ class HTTPResponse: return True def close(self):

def isclosed(self): # NOTE: it is possible that we will not ever call self.close(). This @@ -835,13 +836,17 @@ class HTTPConnection: def close(self): """Close the connection to the HTTP server."""

def send(self, data): """Send `data' to the server."""

--- a/Lib/logging/init.py +++ b/Lib/logging/init.py @@ -916,14 +916,19 @@ class FileHandler(StreamHandler): """ self.acquire() try:

--- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -588,9 +588,10 @@ class SocketHandler(logging.Handler): """ self.acquire() try:

@@ -1160,8 +1161,10 @@ class BufferingHandler(logging.Handler): This version just flushes and chains to the parent class' close(). """

class MemoryHandler(BufferingHandler): """ @@ -1213,10 +1216,12 @@ class MemoryHandler(BufferingHandler): """ Flush, set the target to None and lose the buffer. """

--- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -719,10 +719,14 @@ class _singlefileMailbox(Mailbox): def close(self): """Flush and close the mailbox."""

def _lookup(self, key=None): """Return (start, stop) or raise KeyError."""

--- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -285,9 +285,13 @@ class SocketListener(object): return conn def close(self):

def SocketClient(address):

--- a/Lib/multiprocessing/queues.py +++ b/Lib/multiprocessing/queues.py @@ -156,9 +156,13 @@ class Queue(object): def close(self): self._closed = True

def join_thread(self): debug('Queue.join_thread()')

--- a/Lib/shelve.py +++ b/Lib/shelve.py @@ -140,17 +140,21 @@ class Shelf(UserDict.DictMixin): pass def close(self):

def del(self): if not hasattr(self, 'writeback'):

--- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -750,12 +750,16 @@ class SMTP: def close(self): """Close the connection to the SMTP server."""

def quit(self):

--- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -492,26 +492,26 @@ class _Stream: if self.closed: return

-

-

def _init_read_gz(self): """Initialize for reading a gzip compressed fileobj. @@ -1796,18 +1796,19 @@ class TarFile(object): if self.closed: return

-

def getmember(self, name): """Return a TarInfo object for member name'. If name' can not be

--- a/Lib/telnetlib.py +++ b/Lib/telnetlib.py @@ -254,12 +254,13 @@ class Telnet: def close(self): """Close the connection."""

def get_socket(self): """Return the socket object used internally."""

--- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -413,9 +413,11 @@ class _TemporaryFileWrapper: def close(self): if not self.close_called: self.close_called = True

def del(self): self.close()

--- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -994,11 +994,16 @@ class addclosehook(addbase): self.hookargs = hookargs def close(self):

+ class addinfo(addbase): """class to add an info() method to an open file."""

--- a/Lib/wave.py +++ b/Lib/wave.py @@ -180,10 +180,11 @@ class Wave_read: self._soundpos = 0 def close(self):

def tell(self): return self._soundpos @@ -444,17 +445,18 @@ class Wave_write: self._patchheader() def close(self):

# # Internal methods.

--- a/Lib/xml/sax/expatreader.py +++ b/Lib/xml/sax/expatreader.py @@ -214,14 +214,16 @@ class ExpatParser(xmlreader.IncrementalP self._err_handler.fatalError(exc) def close(self):

def _reset_cont_handler(self): self._parser.ProcessingInstructionHandler = [](#l22.25)

--- a/Lib/xmlrpclib.py +++ b/Lib/xmlrpclib.py @@ -558,8 +558,13 @@ else: self._parser.Parse(data, 0) def close(self):

class SlowParser: """Default XML parser (based on xmllib.XMLParser).""" @@ -1214,8 +1219,10 @@ class GzipDecodedResponse(gzip.GzipFile gzip.GzipFile.init(self, mode="rb", fileobj=self.stringio) def close(self):

--------------------------------------------------------------------

@@ -1384,9 +1391,10 @@ class Transport: # Used in the event of socket errors. # def close(self):

## # Send request header.

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -21,6 +21,10 @@ Core and Builtins Library ------- +- Issue #23865: close() methods in multiple modules now are idempotent and more