[pypy-svn] r64362 - in pypy/trunk/pypy/module/__builtin__: . test

arigo at codespeak.net arigo at codespeak.net
Sun Apr 19 14:43:51 CEST 2009


Author: arigo
Date: Sun Apr 19 14:43:49 2009
New Revision: 64362

Modified:
   pypy/trunk/pypy/module/__builtin__/importing.py
   pypy/trunk/pypy/module/__builtin__/test/test_import.py
Log:
Check for the case of the imported files.


Modified: pypy/trunk/pypy/module/__builtin__/importing.py
==============================================================================
--- pypy/trunk/pypy/module/__builtin__/importing.py	(original)
+++ pypy/trunk/pypy/module/__builtin__/importing.py	Sun Apr 19 14:43:49 2009
@@ -25,7 +25,7 @@
     """
     # check the .py file
     pyfile = filepart + ".py"
-    if os.path.exists(pyfile):
+    if os.path.exists(pyfile) and case_ok(pyfile):
         pyfile_ts = os.stat(pyfile)[stat.ST_MTIME]
         pyfile_exists = True
     else:
@@ -40,8 +40,9 @@
     # check the .pyc file
     if space.config.objspace.usepycfiles:
         pycfile = filepart + ".pyc"    
-        if check_compiled_module(space, pycfile, pyfile_ts):
-            return PYCFILE     # existing and up-to-date .pyc file
+        if case_ok(pycfile):
+            if check_compiled_module(space, pycfile, pyfile_ts):
+                return PYCFILE     # existing and up-to-date .pyc file
 
     # no .pyc file, use the .py file if it exists
     if pyfile_exists:
@@ -49,6 +50,23 @@
     else:
         return NOFILE
 
+if sys.platform in ['linux2', 'freebsd']:
+    def case_ok(filename):
+        return True
+else:
+    # XXX that's slow
+    def case_ok(filename):
+        index = filename.rfind(os.sep)
+        if index < 0:
+            directory = os.curdir
+        else:
+            directory = filename[:index+1]
+            filename = filename[index+1:]
+        try:
+            return filename in os.listdir(directory)
+        except OSError:
+            return False
+
 def _prepare_module(space, w_mod, filename, pkgdir):
     w = space.wrap
     space.sys.setmodule(w_mod)
@@ -276,8 +294,9 @@
 
         if w_path is not None:
             for path in space.unpackiterable(w_path):
-                dir = os.path.join(space.str_w(path), partname)
-                if os.path.isdir(dir):
+                path = space.str_w(path)
+                dir = os.path.join(path, partname)
+                if os.path.isdir(dir) and case_ok(dir):
                     fn = os.path.join(dir, '__init__')
                     w_mod = try_import_mod(space, w_modulename, fn,
                                            w_parent, w(partname),
@@ -288,7 +307,7 @@
                         msg = "Not importing directory " +\
                                 "'%s' missing __init__.py" % dir
                         space.warn(msg, space.w_ImportWarning)
-                fn = os.path.join(space.str_w(path), partname)
+                fn = dir
                 w_mod = try_import_mod(space, w_modulename, fn, w_parent,
                                        w(partname))
                 if w_mod is not None:

Modified: pypy/trunk/pypy/module/__builtin__/test/test_import.py
==============================================================================
--- pypy/trunk/pypy/module/__builtin__/test/test_import.py	(original)
+++ pypy/trunk/pypy/module/__builtin__/test/test_import.py	Sun Apr 19 14:43:49 2009
@@ -169,6 +169,22 @@
         assert pkg == sys.modules.get('pkg')
         assert pkg.a == sys.modules.get('pkg.a')
 
+    def test_import_badcase(self):
+        def missing(name):
+            try:
+                __import__(name)
+            except ImportError:
+                pass
+            else:
+                raise Exception("import should not have succeeded: %r" %
+                                (name,))
+        missing("Sys")
+        missing("SYS")
+        missing("fuNCTionAl")
+        missing("pKg")
+        missing("pKg.a")
+        missing("pkg.A")
+
     def test_import_dotted_cache(self):
         import sys
         import pkg.a



More information about the Pypy-commit mailing list