Commit 3d400b7a authored by Antoine Pitrou's avatar Antoine Pitrou

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)
........
parent 51be0f47
...@@ -383,7 +383,8 @@ def main(): ...@@ -383,7 +383,8 @@ def main():
if o == '-u': func = decode if o == '-u': func = decode
if o == '-t': test(); return if o == '-t': test(); return
if args and args[0] != '-': 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: else:
func(sys.stdin.buffer, sys.stdout.buffer) func(sys.stdin.buffer, sys.stdout.buffer)
......
...@@ -193,9 +193,8 @@ class MimeTypes: ...@@ -193,9 +193,8 @@ class MimeTypes:
list of standard types, else to the list of non-standard list of standard types, else to the list of non-standard
types. types.
""" """
fp = open(filename) with open(filename) as fp:
self.readfp(fp, strict) self.readfp(fp, strict)
fp.close()
def readfp(self, fp, strict=True): def readfp(self, fp, strict=True):
""" """
...@@ -302,7 +301,7 @@ def init(files=None): ...@@ -302,7 +301,7 @@ def init(files=None):
files = knownfiles files = knownfiles
for file in files: for file in files:
if os.path.isfile(file): if os.path.isfile(file):
db.readfp(open(file)) db.read(file)
encodings_map = db.encodings_map encodings_map = db.encodings_map
suffix_map = db.suffix_map suffix_map = db.suffix_map
types_map = db.types_map[True] types_map = db.types_map[True]
......
...@@ -209,6 +209,7 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent) ...@@ -209,6 +209,7 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
PyObject *binary; PyObject *binary;
PyObject *fob = NULL; PyObject *fob = NULL;
PyObject *lineobj = NULL; PyObject *lineobj = NULL;
PyObject *res;
char buf[MAXPATHLEN+1]; char buf[MAXPATHLEN+1];
Py_UNICODE *u, *p; Py_UNICODE *u, *p;
Py_ssize_t len; Py_ssize_t len;
...@@ -254,6 +255,11 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent) ...@@ -254,6 +255,11 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent)
break; break;
} }
} }
res = PyObject_CallMethod(fob, "close", "");
if (res)
Py_DECREF(res);
else
PyErr_Clear();
Py_DECREF(fob); Py_DECREF(fob);
if (!lineobj || !PyUnicode_Check(lineobj)) { if (!lineobj || !PyUnicode_Check(lineobj)) {
Py_XDECREF(lineobj); Py_XDECREF(lineobj);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment