[pypy-svn] r33047 - in pypy/dist/pypy/translator/cli: src test

antocuni at codespeak.net antocuni at codespeak.net
Mon Oct 9 14:45:36 CEST 2006


Author: antocuni
Date: Mon Oct  9 14:45:35 2006
New Revision: 33047

Modified:
   pypy/dist/pypy/translator/cli/src/ll_os.cs
   pypy/dist/pypy/translator/cli/test/test_builtin.py
Log:
Added support for opendir, readdir and closedir



Modified: pypy/dist/pypy/translator/cli/src/ll_os.cs
==============================================================================
--- pypy/dist/pypy/translator/cli/src/ll_os.cs	(original)
+++ pypy/dist/pypy/translator/cli/src/ll_os.cs	Mon Oct  9 14:45:35 2006
@@ -349,11 +349,6 @@
             Helpers.raise_OSError(Errno.EPERM); // this is only a stub
         }
 
-        public static void ll_os_closedir(object o)
-        {
-            Helpers.raise_OSError(Errno.EPERM); // this is only a stub
-        }
-
         public static int ll_os_dup(int x)
         {
             Helpers.raise_OSError(Errno.EPERM); // this is only a stub
@@ -398,29 +393,48 @@
             Helpers.raise_OSError(Errno.EPERM); // this is only a stub
         }
 
-        public static object ll_os_opendir(string s)
+        public static object ll_os_opendir(string path)
         {
-            Helpers.raise_OSError(Errno.EPERM); // this is only a stub
-            return null;
+            if (path == "")
+                Helpers.raise_OSError(Errno.ENOENT);
+
+            DirectoryInfo dir = new DirectoryInfo(path);
+            if (!dir.Exists)
+                Helpers.raise_OSError(Errno.ENOENT);
+
+            System.Collections.Generic.List<string> names = new System.Collections.Generic.List<string>();
+            foreach(DirectoryInfo d in dir.GetDirectories())
+                names.Add(d.Name);
+            foreach(FileInfo f in dir.GetFiles())
+                names.Add(f.Name);
+
+            return names.GetEnumerator();
         }
 
-        public static Record_Signed_Signed ll_os_pipe()
+        public static string ll_os_readdir(object obj)
         {
-            Helpers.raise_OSError(Errno.EPERM); // this is only a stub
-            return null;
+            IEnumerator<string> names = (IEnumerator<string>)obj;
+            if (names.MoveNext())
+                return names.Current;
+            else
+                return null;
         }
 
-        public static void ll_os_putenv(string s)
+        public static void ll_os_closedir(object obj)
         {
-            Helpers.raise_OSError(Errno.EPERM); // this is only a stub
         }
 
-        public static string ll_os_readdir(object o)
+        public static Record_Signed_Signed ll_os_pipe()
         {
             Helpers.raise_OSError(Errno.EPERM); // this is only a stub
             return null;
         }
 
+        public static void ll_os_putenv(string s)
+        {
+            Helpers.raise_OSError(Errno.EPERM); // this is only a stub
+        }
+
         public static string ll_os_readlink(string s)
         {
             Helpers.raise_OSError(Errno.EPERM); // this is only a stub

Modified: pypy/dist/pypy/translator/cli/test/test_builtin.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_builtin.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_builtin.py	Mon Oct  9 14:45:35 2006
@@ -109,5 +109,22 @@
         res = self.ll_to_string(self.interpret(fn, []))
         # XXX assert something about res
 
+    def test_os_opendir(self):
+        from pypy.rpython import ros
+        def fn():
+            d = ros.opendir('.')
+            res = []
+            while True:
+                current = d.readdir()
+                if current is None:
+                    break
+                res.append(current)
+            d.closedir()
+            return res
+        res = self.ll_to_list(self.interpret(fn, []))
+        res = [self.ll_to_string(s) for s in res]
+        res.sort()
+        assert res == sorted(os.listdir('.'))
+
     # XXX: remember to test ll_os_readlink and ll_os_pipe as soon as
     # they are implemented



More information about the Pypy-commit mailing list