From 9ac08034fb9f3d1fc7e23652f00e7356801eb6cf Mon Sep 17 00:00:00 2001 From: Sylvain Th?nault Date: Thu, 3 Oct 2013 17:31:43 +0200 Subject: [modutils] ensure file is closed, may cause pb depending on the interpreter (eg pypy). Closes #180876 --- ChangeLog | 7 +++++-- modutils.py | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index eabe38a..80f2bdb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,8 +2,11 @@ ChangeLog for logilab.common ============================ -- - * modutils: don't propagate IOError when package's __init__.py file doesn't - exist (#174606) + * modutils: + * don't propagate IOError when package's __init__.py file doesn't + exist (#174606) + * ensure file is closed, may cause pb depending on the interpreter, eg + pypy) (#180876) * fix some cases of failing python3 install on windows platform / cross compilation (#180836) diff --git a/modutils.py b/modutils.py index e9615d5..e339a70 100644 --- a/modutils.py +++ b/modutils.py @@ -27,6 +27,8 @@ :type BUILTIN_MODULES: dict :var BUILTIN_MODULES: dictionary with builtin module names has key """ +from __future__ import with_statement + __docformat__ = "restructuredtext en" import sys @@ -657,7 +659,8 @@ def _module_file(modpath, path=None): # XXX guess if package is using pkgutil.extend_path by looking for # those keywords in the first four Kbytes try: - data = open(join(mp_filename, '__init__.py')).read(4096) + with open(join(mp_filename, '__init__.py')) as stream: + data = stream.read(4096) except IOError: path = [mp_filename] else: -- cgit v1.2.1