diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-10-03 17:31:43 +0200 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-10-03 17:31:43 +0200 |
commit | 9ac08034fb9f3d1fc7e23652f00e7356801eb6cf (patch) | |
tree | 4e1e0ed82e5df0abed42d7d54435ee530e3a504c /modutils.py | |
parent | 64aafff708367f5211b321d478bf2927728b2a4c (diff) | |
download | logilab-common-9ac08034fb9f3d1fc7e23652f00e7356801eb6cf.tar.gz |
[modutils] ensure file is closed, may cause pb depending on the interpreter (eg pypy). Closes #180876
Diffstat (limited to 'modutils.py')
-rw-r--r-- | modutils.py | 5 |
1 files changed, 4 insertions, 1 deletions
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: |