summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2013-10-03 17:31:43 +0200
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2013-10-03 17:31:43 +0200
commit9ac08034fb9f3d1fc7e23652f00e7356801eb6cf (patch)
tree4e1e0ed82e5df0abed42d7d54435ee530e3a504c
parent64aafff708367f5211b321d478bf2927728b2a4c (diff)
downloadlogilab-common-9ac08034fb9f3d1fc7e23652f00e7356801eb6cf.tar.gz
[modutils] ensure file is closed, may cause pb depending on the interpreter (eg pypy). Closes #180876
-rw-r--r--ChangeLog7
-rw-r--r--modutils.py5
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: