Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r67899:166ca52b236d
Date: 2013-11-09 16:37 +0100
http://bitbucket.org/pypy/pypy/changeset/166ca52b236d/

Log:    os.pathconf()

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
@@ -131,6 +131,8 @@
     if hasattr(os, 'fpathconf'):
         interpleveldefs['fpathconf'] = 'interp_posix.fpathconf'
         interpleveldefs['pathconf_names'] = 'space.wrap(os.pathconf_names)'
+    if hasattr(os, 'pathconf'):
+        interpleveldefs['pathconf'] = 'interp_posix.pathconf'
     if hasattr(os, 'confstr'):
         interpleveldefs['confstr'] = 'interp_posix.confstr'
         interpleveldefs['confstr_names'] = 'space.wrap(os.confstr_names)'
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
@@ -1248,6 +1248,15 @@
         raise wrap_oserror(space, e)
     return space.wrap(res)
 
+@unwrap_spec(path='str0')
+def pathconf(space, path, w_name):
+    num = confname_w(space, w_name, os.pathconf_names)
+    try:
+        res = os.pathconf(path, num)
+    except OSError, e:
+        raise wrap_oserror(space, e)
+    return space.wrap(res)
+
 def confstr(space, w_name):
     num = confname_w(space, w_name, os.confstr_names)
     try:
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
@@ -705,6 +705,14 @@
             raises(OSError, os.fpathconf, -1, "PC_PIPE_BUF")
             raises(ValueError, os.fpathconf, 1, "##")
 
+    if hasattr(os, 'pathconf'):
+        def test_os_pathconf(self):
+            os = self.posix
+            assert os.pathconf("/tmp", "PC_NAME_MAX") >= 31
+            # Linux: the following gets 'No such file or directory'
+            raises(OSError, os.pathconf, "", "PC_PIPE_BUF")
+            raises(ValueError, os.pathconf, "/tmp", "##")
+
     if hasattr(os, 'confstr'):
         def test_os_confstr(self):
             os = self.posix
diff --git a/rpython/rtyper/module/ll_os.py b/rpython/rtyper/module/ll_os.py
--- a/rpython/rtyper/module/ll_os.py
+++ b/rpython/rtyper/module/ll_os.py
@@ -651,6 +651,22 @@
         return extdef([int, int], int, "ll_os.ll_fpathconf",
                       llimpl=fpathconf_llimpl)
 
+    @registering_if(os, 'pathconf')
+    def register_os_pathconf(self):
+        c_pathconf = self.llexternal('pathconf',
+                                     [rffi.CCHARP, rffi.INT], rffi.LONG)
+
+        def pathconf_llimpl(path, i):
+            rposix.set_errno(0)
+            res = c_pathconf(path, i)
+            if res == -1:
+                errno = rposix.get_errno()
+                if errno != 0:
+                    raise OSError(errno, "pathconf failed")
+            return res
+        return extdef([str0, int], int, "ll_os.ll_pathconf",
+                      llimpl=pathconf_llimpl)
+
     @registering_if(os, 'confstr')
     def register_os_confstr(self):
         c_confstr = self.llexternal('confstr', [rffi.INT, rffi.CCHARP,
diff --git a/rpython/rtyper/module/test/test_posix.py 
b/rpython/rtyper/module/test/test_posix.py
--- a/rpython/rtyper/module/test/test_posix.py
+++ b/rpython/rtyper/module/test/test_posix.py
@@ -190,6 +190,14 @@
             res = self.interpret(f, [94781413])
             assert hlstr(res) == "oooops!!"
 
+    if hasattr(os, 'pathconf'):
+        def test_os_pathconf(self):
+            def f(i):
+                return os.pathconf("/tmp", i)
+            i = os.pathconf_names["PC_NAME_MAX"]
+            some_value = self.interpret(f, [i])
+            assert some_value >= 31
+
     if hasattr(os, 'chroot'):
         def test_os_chroot(self):
             def f():
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to