[pypy-svn] r15176 - pypy/dist/pypy/module/posix

arigo at codespeak.net arigo at codespeak.net
Wed Jul 27 14:02:46 CEST 2005


Author: arigo
Date: Wed Jul 27 14:02:42 2005
New Revision: 15176

Modified:
   pypy/dist/pypy/module/posix/__init__.py
   pypy/dist/pypy/module/posix/app_posix.py
   pypy/dist/pypy/module/posix/interp_posix.py
Log:
A few fixes to our posix modules, and support for stat_result classes.


Modified: pypy/dist/pypy/module/posix/__init__.py
==============================================================================
--- pypy/dist/pypy/module/posix/__init__.py	(original)
+++ pypy/dist/pypy/module/posix/__init__.py	Wed Jul 27 14:02:42 2005
@@ -4,8 +4,14 @@
 import os
 
 class Module(MixedModule):
+    """This module provides access to operating system functionality that is
+standardized by the C Standard and the POSIX standard (a thinly
+disguised Unix interface).  Refer to the library manual and
+corresponding Unix manual entries for more information on calls."""
+
     appleveldefs = {
-    'error'     : 'app_posix.error',
+    'error'      : 'app_posix.error',
+    'stat_result': 'app_posix.stat_result',
     }
     
     interpleveldefs = {
@@ -19,8 +25,6 @@
     'fstat'     : 'interp_posix.fstat',
     'stat'      : 'interp_posix.stat',
     'dup'       : 'interp_posix.dup',
-    '__doc__'   : "space.wrap('Posix module')",
-    '__name__'  : "space.wrap('The builtin posix module')",
     }
 
 for constant in ['EX_CANTCREAT', 'EX_CONFIG', 'EX_DATAERR', 'EX_IOERR',
@@ -36,4 +40,4 @@
         Module.interpleveldefs[constant] = ("space.wrap(%s)" %
                                             (getattr(os, constant), ))
     except AttributeError:
-        pass
\ No newline at end of file
+        pass

Modified: pypy/dist/pypy/module/posix/app_posix.py
==============================================================================
--- pypy/dist/pypy/module/posix/app_posix.py	(original)
+++ pypy/dist/pypy/module/posix/app_posix.py	Wed Jul 27 14:02:42 2005
@@ -1,5 +1,24 @@
+# NOT_RPYTHON
 
-class OSError(Exception):
-    pass
+error = OSError
 
-error = OSError
\ No newline at end of file
+
+def tuple_item_getter(n):   # helper to make properties
+    def getter(self):
+        return self[n]
+    return property(getter)
+
+
+class stat_result(tuple):
+    __slots__ = []
+
+    st_mode  = tuple_item_getter(0)
+    st_ino   = tuple_item_getter(1)
+    st_dev   = tuple_item_getter(2)
+    st_nlink = tuple_item_getter(3)
+    st_uid   = tuple_item_getter(4)
+    st_gid   = tuple_item_getter(5)
+    st_size  = tuple_item_getter(6)
+    st_atime = tuple_item_getter(7)
+    st_mtime = tuple_item_getter(8)
+    st_ctime = tuple_item_getter(9)

Modified: pypy/dist/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/dist/pypy/module/posix/interp_posix.py	(original)
+++ pypy/dist/pypy/module/posix/interp_posix.py	Wed Jul 27 14:02:42 2005
@@ -1,19 +1,16 @@
 from pypy.interpreter.baseobjspace import ObjSpace
+from pypy.rpython.rarithmetic import intmask
 
 import os
 from os import *
 
-def open(space, w_fname, w_flag, w_mode=0777):
-    fname = space.str_w(w_fname)
-    flag = space.int_w(w_flag)
-    mode = space.int_w(w_mode)
-    # notice that an unwrap_spec attached to open could be used to the same effect
+def open(space, fname, flag, mode=0777):
     fd = os.open(fname, flag, mode)
     return space.wrap(fd)
-
+open.unwrap_spec = [ObjSpace, str, int, int]
 
 def lseek(space, fd, pos, how):
-    os.lseek(fd,pos,how)
+    return space.wrap(os.lseek(fd, pos, how))
 lseek.unwrap_spec = [ObjSpace, int, int, int]
 
 def isatty(space, fd):
@@ -21,7 +18,7 @@
 isatty.unwrap_spec = [ObjSpace, int]
 
 def read(space, fd, buffersize):
-    return space.wrap(os.read(fd,buffersize))
+    return space.wrap(os.read(fd, buffersize))
 read.unwrap_spec = [ObjSpace, int, int]
 
 def write(space, fd, data):
@@ -36,12 +33,21 @@
     os.ftruncate(fd, length)
 ftruncate.unwrap_spec = [ObjSpace, int, int]
 
+def build_stat_result(space, st):
+    # cannot index tuples with a variable...
+    lst = [st[0], st[1], st[2], st[3], st[4],
+           st[5], st[6], st[7], st[8], st[9]]
+    w_tuple = space.newtuple([space.wrap(intmask(x)) for x in lst])
+    w_stat_result = space.getattr(space.getbuiltinmodule('posix'),
+                                  space.wrap('stat_result'))
+    return space.call_function(w_stat_result, w_tuple)
+
 def fstat(space, fd):
-    return space.wrap(os.fstat(fd))
+    return build_stat_result(space, os.fstat(fd))
 fstat.unwrap_spec = [ObjSpace, int]
 
 def stat(space, path):
-    return space.wrap(os.stat(path))
+    return build_stat_result(space, os.stat(path))
 stat.unwrap_spec = [ObjSpace, str]
 
 def getcwd(space):



More information about the Pypy-commit mailing list