[modutils] fix python3.3 crash on file_from_modpath. Closes #137244

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset5a8fb4b4a7f5
branchstable
phasepublic
hiddenno
parent revision#4e579e9a9792 [modutils test] enhance some test names
child revision#cd9817f175b4 [modutils] setuptools pkg_resources support. Closes #8796, #e1a6f9f362b4 testlib: fix for python 3.3, #ce288b12f533 testlib: fix for python 3.3, #d40ffc71c1e9 graph: use codecs.open
files modified by this revision
ChangeLog
modutils.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1367930788 -7200
# Tue May 07 14:46:28 2013 +0200
# Branch stable
# Node ID 5a8fb4b4a7f567b65b8f935282316be0b1f9018e
# Parent 4e579e9a97922a94624c2d04ae1af5268f0d487c
[modutils] fix python3.3 crash on file_from_modpath. Closes #137244

diff --git a/ChangeLog b/ChangeLog
@@ -1,11 +1,16 @@
1  ChangeLog for logilab.common
2  ============================
3 
4  --
5 -    * modutils: fix typo causing name error in python3 / bad message in python2
6 -      (#136037)
7 +    * modutils:
8 +
9 +      * fix typo causing name error in python3 / bad message in python2
10 +        (#136037)
11 +
12 +      * fix python3.3 crash in file_from_modpath due to implementation
13 +        change of imp.find_module wrt builtin modules (#137244)
14 
15 
16  2013-04-16  --  0.59.1
17      * graph: added pruning of the recursive search tree for detecting cycles in
18        graphs (closes #2469)
diff --git a/modutils.py b/modutils.py
@@ -604,18 +604,27 @@
19          checkeggs = True
20      except AttributeError:
21          checkeggs = False
22      imported = []
23      while modpath:
24 +        # take care to changes in find_module implementation wrt builtin modules
25 +        #
26 +        # Python 2.6.6 (r266:84292, Sep 11 2012, 08:34:23)
27 +        # >>> imp.find_module('posix')
28 +        # (None, 'posix', ('', '', 6))
29 +        #
30 +        # Python 3.3.1 (default, Apr 26 2013, 12:08:46)
31 +        # >>> imp.find_module('posix')
32 +        # (None, None, ('', '', 6))
33          try:
34              _, mp_filename, mp_desc = find_module(modpath[0], path)
35          except ImportError:
36              if checkeggs:
37                  return _search_zip(modpath, pic)[:2]
38              raise
39          else:
40 -            if checkeggs:
41 +            if checkeggs and mp_filename:
42                  fullabspath = [abspath(x) for x in _path]
43                  try:
44                      pathindex = fullabspath.index(dirname(abspath(mp_filename)))
45                      emtype, emp_filename, zippath = _search_zip(modpath, pic)
46                      if pathindex > _path.index(zippath):