[pypy-commit] pypy py3.5-xattr: Implement posix.listxattr(), fix test

rlamy pypy.commits at gmail.com
Tue Dec 19 12:04:15 EST 2017


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5-xattr
Changeset: r93496:eeeb03d063f0
Date: 2017-12-19 17:02 +0000
http://bitbucket.org/pypy/pypy/changeset/eeeb03d063f0/

Log:	Implement posix.listxattr(), fix test

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
@@ -255,6 +255,7 @@
         interpleveldefs['getxattr'] = 'interp_posix.getxattr'
         interpleveldefs['setxattr'] = 'interp_posix.setxattr'
         interpleveldefs['removexattr'] = 'interp_posix.removexattr'
+        interpleveldefs['listxattr'] = 'interp_posix.listxattr'
         for _name in ['XATTR_SIZE_MAX', 'XATTR_CREATE', 'XATTR_REPLACE']:
             if getattr(rposix, _name) is not None:
                 interpleveldefs[_name] = 'space.wrap(%d)' % getattr(rposix, _name)
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
@@ -2304,10 +2304,8 @@
             raise wrap_oserror(space, e, eintr_retry=False)
     else:
         try:
-            if follow_symlinks:
-                result = rposix.getxattr(path.as_bytes, attribute.as_bytes)
-            else:
-                result = rposix.lgetxattr(path.as_bytes, attribute.as_bytes)
+            result = rposix.getxattr(path.as_bytes, attribute.as_bytes,
+                follow_symlinks=follow_symlinks)
         except OSError as e:
             raise wrap_oserror(space, e, eintr_retry=False)
     return space.newbytes(result)
@@ -2335,10 +2333,8 @@
             raise wrap_oserror(space, e, eintr_retry=False)
     else:
         try:
-            if follow_symlinks:
-                rposix.setxattr(path.as_bytes, attribute.as_bytes, value)
-            else:
-                rposix.lsetxattr(path.as_bytes, attribute.as_bytes, value)
+            rposix.setxattr(path.as_bytes, attribute.as_bytes, value,
+                follow_symlinks=follow_symlinks)
         except OSError as e:
             raise wrap_oserror(space, e, eintr_retry=False)
 
@@ -2363,16 +2359,13 @@
             raise wrap_oserror(space, e, eintr_retry=False)
     else:
         try:
-            if follow_symlinks:
-                rposix.removexattr(path.as_bytes, attribute.as_bytes)
-            else:
-                rposix.lremovexattr(path.as_bytes, attribute.as_bytes)
+            rposix.removexattr(path.as_bytes, attribute.as_bytes,
+                follow_symlinks=follow_symlinks)
         except OSError as e:
             raise wrap_oserror(space, e, eintr_retry=False)
 
 
- at unwrap_spec(path=path_or_fd(), attribute=path_or_fd(allow_fd=False),
-             follow_symlinks=bool)
+ at unwrap_spec(path=path_or_fd(), follow_symlinks=bool)
 def listxattr(space, path, __kwonly__, follow_symlinks=True):
     """listxattr(path='.', *, follow_symlinks=True)
 
@@ -2388,18 +2381,15 @@
             raise oefmt(space.w_ValueError,
                         "listxattr: cannot use fd and follow_symlinks together")
         try:
-            result = rposix.flistxattr(path.as_fd, attribute.as_bytes)
+            result = rposix.flistxattr(path.as_fd)
         except OSError as e:
             raise wrap_oserror(space, e, eintr_retry=False)
     else:
         try:
-            if follow_symlinks:
-                result = rposix.listxattr(path.as_bytes, attribute.as_bytes)
-            else:
-                result = rposix.llistxattr(path.as_bytes, attribute.as_bytes)
+            result = rposix.listxattr(path.as_bytes, follow_symlinks)
         except OSError as e:
             raise wrap_oserror(space, e, eintr_retry=False)
-    return xxx
+    return space.newlist([space.newbytes(attr) for attr in result])
 
 
 have_functions = []
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
@@ -1447,13 +1447,17 @@
             os = self.posix
             with open(self.path, 'wb'):
                 pass
+            init_names = os.listxattr(self.path)
             raises(OSError, os.getxattr, self.path, 'user.test')
-            os.setxattr(self.path, 'user.test', b'', os.XATTR_CREATE)
+            os.setxattr(self.path, 'user.test', b'', os.XATTR_CREATE, follow_symlinks=False)
             assert os.getxattr(self.path, 'user.test') == b''
             os.setxattr(self.path, 'user.test', b'foo', os.XATTR_REPLACE)
-            assert os.getxattr(self.path, 'user.test') == b'foo'
-            os.removexattr(self.path, 'user.test')
+            assert os.getxattr(self.path, 'user.test', follow_symlinks=False) == b'foo'
+            assert set(os.listxattr(self.path)) == set(
+                init_names + [b'user.test'])
+            os.removexattr(self.path, 'user.test', follow_symlinks=False)
             raises(OSError, os.getxattr, self.path, 'user.test')
+            assert os.listxattr(self.path, follow_symlinks=False) == init_names
 
 
 class AppTestEnvironment(object):


More information about the pypy-commit mailing list