[pypy-svn] r64296 - in pypy/trunk/pypy/translator: jvm/src/pypy oosupport/test_template

niko at codespeak.net niko at codespeak.net
Fri Apr 17 18:57:50 CEST 2009


Author: niko
Date: Fri Apr 17 18:57:49 2009
New Revision: 64296

Modified:
   pypy/trunk/pypy/translator/jvm/src/pypy/ll_os.java
   pypy/trunk/pypy/translator/oosupport/test_template/builtin.py
Log:
add support for os.access



Modified: pypy/trunk/pypy/translator/jvm/src/pypy/ll_os.java
==============================================================================
--- pypy/trunk/pypy/translator/jvm/src/pypy/ll_os.java	(original)
+++ pypy/trunk/pypy/translator/jvm/src/pypy/ll_os.java	Fri Apr 17 18:57:49 2009
@@ -275,6 +275,30 @@
 
         return file;
     }
+    
+    public boolean ll_os_access(String path, int mode) {
+        final int F_OK = 0;
+        final int X_OK = 1;
+        final int W_OK = 2;
+        final int R_OK = 4; // XXX can we load these from RPython somehow?
+        
+        File file = new File(path);
+
+        if (!file.exists())
+            return false;
+        
+        // These methods only exist in Java 1.6:    
+        //if ((mode & R_OK) != 0 && !file.canRead())
+        //    return false;
+        //
+        //if ((mode & W_OK) != 0 && !file.canWrite())
+        //    return false;
+        //
+        //if ((mode & X_OK) != 0 && !file.canExecute())
+        //    return false;
+        
+        return true;
+    }
 
     public int ll_os_open(String name, int flags, int mode)
     {

Modified: pypy/trunk/pypy/translator/oosupport/test_template/builtin.py
==============================================================================
--- pypy/trunk/pypy/translator/oosupport/test_template/builtin.py	(original)
+++ pypy/trunk/pypy/translator/oosupport/test_template/builtin.py	Fri Apr 17 18:57:49 2009
@@ -123,6 +123,26 @@
         assert stat.S_ISDIR(mode)
         mode = self.interpret(fn, [1])
         assert stat.S_ISDIR(mode)
+        
+    ACCESS_FLAGS = [os.F_OK, os.R_OK, os.W_OK, os.X_OK]
+    
+    def test_os_access_nonexisting(self):
+        def nonexisting(flag):
+            return os.access('some_file_that_does_not_exist', flag)
+        for flag in self.ACCESS_FLAGS:
+            assert self.interpret(nonexisting, [flag]) == nonexisting(flag)
+
+    def test_os_access_allowed(self):
+        def dot(flag):
+            return os.access('.', flag)
+        for flag in self.ACCESS_FLAGS:
+            assert self.interpret(dot, [flag]) == dot(flag)
+
+    def test_os_access_denied(self):
+        def slash(flag):
+            return os.access('/', flag)
+        for flag in self.ACCESS_FLAGS:
+            assert self.interpret(slash, [flag]) == slash(flag)
 
     def test_os_stat_oserror(self):
         def fn():



More information about the Pypy-commit mailing list