Skip to content

Commit

Permalink
Merged revisions 85497 via svnmerge from
Browse files Browse the repository at this point in the history
svn+ssh://[email protected]/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 python#10093)
........
  • Loading branch information
pitrou committed Oct 14, 2010
1 parent 51be0f4 commit 3d400b7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Lib/base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 3 additions & 4 deletions Lib/mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,8 @@ def read(self, filename, strict=True):
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):
"""
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions Python/traceback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3d400b7

Please sign in to comment.