[pypy-svn] pypy default: implement os.fpathconf()

amauryfa commits-noreply at bitbucket.org
Mon Jan 17 23:42:57 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r40822:a613826ccbb6
Date: 2011-01-17 23:41 +0100
http://bitbucket.org/pypy/pypy/changeset/a613826ccbb6/

Log:	implement os.fpathconf()

diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -517,7 +517,14 @@
         def test_os_sysconf_error(self):
             os = self.posix
             raises(ValueError, os.sysconf, "!@#$%!#$!@#")
-    
+
+    if hasattr(os, 'fpathconf'):
+        def test_os_fpathconf(self):
+            os = self.posix
+            assert os.fpathconf(1, "PC_PIPE_BUF") >= 128
+            raises(OSError, os.fpathconf, -1, "PC_PIPE_BUF")
+            raises(ValueError, os.fpathconf, 1, "##")
+
     if hasattr(os, 'wait'):
         def test_os_wait(self):
             os = self.posix

diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -1047,19 +1047,31 @@
         raise wrap_oserror(space, e)
 ttyname.unwrap_spec = [ObjSpace, "c_int"]
 
-def sysconf(space, w_num_or_name):
+def confname_w(space, w_name, namespace):
     # XXX slightly non-nice, reuses the sysconf of the underlying os module
-    if space.is_true(space.isinstance(w_num_or_name, space.w_basestring)):
+    if space.is_true(space.isinstance(w_name, space.w_basestring)):
         try:
-            num = os.sysconf_names[space.str_w(w_num_or_name)]
+            num = namespace[space.str_w(w_name)]
         except KeyError:
             raise OperationError(space.w_ValueError,
                                  space.wrap("unrecognized configuration name"))
     else:
-        num = space.int_w(w_num_or_name)
+        num = space.int_w(w_name)
+    return num
+
+def sysconf(space, w_name):
+    num = confname_w(space, w_name, os.sysconf_names)
     return space.wrap(os.sysconf(num))
 sysconf.unwrap_spec = [ObjSpace, W_Root]
 
+def fpathconf(space, fd, w_name):
+    num = confname_w(space, w_name, os.pathconf_names)
+    try:
+        return space.wrap(os.fpathconf(fd, num))
+    except OSError, e:
+        raise wrap_oserror(space, e)
+fpathconf.unwrap_spec = [ObjSpace, int, W_Root]
+
 def chown(space, path, uid, gid):
     try:
         os.chown(path, uid, gid)

diff --git a/pypy/rpython/module/ll_os.py b/pypy/rpython/module/ll_os.py
--- a/pypy/rpython/module/ll_os.py
+++ b/pypy/rpython/module/ll_os.py
@@ -614,6 +614,16 @@
             return c_sysconf(i)
         return extdef([int], int, "ll_os.ll_sysconf", llimpl=sysconf_llimpl)
 
+    @registering_if(os, 'fpathconf')
+    def register_os_fpathconf(self):
+        c_fpathconf = self.llexternal('fpathconf',
+                                      [rffi.INT, rffi.INT], rffi.LONG)
+
+        def fpathconf_llimpl(fd, i):
+            return c_fpathconf(fd, i)
+        return extdef([int, int], int, "ll_os.ll_fpathconf",
+                      llimpl=fpathconf_llimpl)
+
     @registering_if(os, 'getuid')
     def register_os_getuid(self):
         return self.extdef_for_os_function_returning_int('getuid')

diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -116,7 +116,9 @@
         interpleveldefs['uname'] = 'interp_posix.uname'
     if hasattr(os, 'sysconf'):
         interpleveldefs['sysconf'] = 'interp_posix.sysconf'
+        interpleveldefs['fpathconf'] = 'interp_posix.fpathconf'
         interpleveldefs['sysconf_names'] = 'space.wrap(os.sysconf_names)'
+        interpleveldefs['pathconf_names'] = 'space.wrap(os.pathconf_names)'
     if hasattr(os, 'ttyname'):
         interpleveldefs['ttyname'] = 'interp_posix.ttyname'
     if hasattr(os, 'getloadavg'):


More information about the Pypy-commit mailing list