[Python-checkins] r85498 - in python/branches/release31-maint: Lib/base64.py Lib/mimetypes.py Python/traceback.c

antoine.pitrou python-checkins at python.org
Thu Oct 14 23:17:39 CEST 2010


Author: antoine.pitrou
Date: Thu Oct 14 23:17:39 2010
New Revision: 85498

Log:
Merged revisions 85497 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r85497 | antoine.pitrou | 2010-10-14 23:15:17 +0200 (jeu., 14 oct. 2010) | 3 lines
  
  Explicitly close some files (from issue #10093)
........


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Lib/base64.py
   python/branches/release31-maint/Lib/mimetypes.py
   python/branches/release31-maint/Python/traceback.c

Modified: python/branches/release31-maint/Lib/base64.py
==============================================================================
--- python/branches/release31-maint/Lib/base64.py	(original)
+++ python/branches/release31-maint/Lib/base64.py	Thu Oct 14 23:17:39 2010
@@ -383,7 +383,8 @@
         if o == '-u': func = decode
         if o == '-t': test(); return
     if args and args[0] != '-':
-        func(open(args[0], 'rb'), sys.stdout.buffer)
+        with open(args[0], 'rb') as f:
+            func(f, sys.stdout.buffer)
     else:
         func(sys.stdin.buffer, sys.stdout.buffer)
 

Modified: python/branches/release31-maint/Lib/mimetypes.py
==============================================================================
--- python/branches/release31-maint/Lib/mimetypes.py	(original)
+++ python/branches/release31-maint/Lib/mimetypes.py	Thu Oct 14 23:17:39 2010
@@ -193,9 +193,8 @@
         list of standard types, else to the list of non-standard
         types.
         """
-        fp = open(filename)
-        self.readfp(fp, strict)
-        fp.close()
+        with open(filename) as fp:
+            self.readfp(fp, strict)
 
     def readfp(self, fp, strict=True):
         """
@@ -302,7 +301,7 @@
         files = knownfiles
     for file in files:
         if os.path.isfile(file):
-            db.readfp(open(file))
+            db.read(file)
     encodings_map = db.encodings_map
     suffix_map = db.suffix_map
     types_map = db.types_map[True]

Modified: python/branches/release31-maint/Python/traceback.c
==============================================================================
--- python/branches/release31-maint/Python/traceback.c	(original)
+++ python/branches/release31-maint/Python/traceback.c	Thu Oct 14 23:17:39 2010
@@ -209,6 +209,7 @@
     PyObject *binary;
     PyObject *fob = NULL;
     PyObject *lineobj = NULL;
+    PyObject *res;
     char buf[MAXPATHLEN+1];
     Py_UNICODE *u, *p;
     Py_ssize_t len;
@@ -254,6 +255,11 @@
             break;
         }
     }
+    res = PyObject_CallMethod(fob, "close", "");
+    if (res)
+        Py_DECREF(res);
+    else
+        PyErr_Clear();
     Py_DECREF(fob);
     if (!lineobj || !PyUnicode_Check(lineobj)) {
         Py_XDECREF(lineobj);


More information about the Python-checkins mailing list