]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 85497 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 14 Oct 2010 21:17:39 +0000 (21:17 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 14 Oct 2010 21:17:39 +0000 (21:17 +0000)
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)
........

Lib/base64.py
Lib/mimetypes.py
Python/traceback.c

index b31c410aaa08978bce25f9d4b764e9599da01723..f93b3a4f81681ea8b0e783da87c197cb4bb70707 100755 (executable)
@@ -383,7 +383,8 @@ def main():
         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)
 
index f0da453da05e8ea7cd5f915dc8edf31cf42bd627..874037e8710f3f9b69fb90470b81d01b53ac0268 100644 (file)
@@ -193,9 +193,8 @@ class MimeTypes:
         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 @@ def init(files=None):
         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]
index c101933931bc26a0c9ccdfed42944314fd63c7fe..e74d4426326027795aac771e61f1bb128ad257e3 100644 (file)
@@ -209,6 +209,7 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
     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 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
             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);