[pypy-svn] r36400 - in pypy/dist/pypy: module/posix module/posix/test rpython rpython/module rpython/module/test translator/c translator/c/src translator/c/test
exarkun at codespeak.net
exarkun at codespeak.net
Wed Jan 10 03:05:29 CET 2007
Author: exarkun
Date: Wed Jan 10 03:05:26 2007
New Revision: 36400
Modified:
pypy/dist/pypy/module/posix/__init__.py
pypy/dist/pypy/module/posix/interp_posix.py
pypy/dist/pypy/module/posix/test/test_posix2.py
pypy/dist/pypy/rpython/extfunctable.py
pypy/dist/pypy/rpython/module/ll_os.py
pypy/dist/pypy/rpython/module/test/test_ll_os.py
pypy/dist/pypy/translator/c/extfunc.py
pypy/dist/pypy/translator/c/src/ll_os.h
pypy/dist/pypy/translator/c/test/test_extfunc.py
Log:
Add os.access wrapper and low-level implementation for the C backend
Modified: pypy/dist/pypy/module/posix/__init__.py
==============================================================================
--- pypy/dist/pypy/module/posix/__init__.py (original)
+++ pypy/dist/pypy/module/posix/__init__.py Wed Jan 10 03:05:26 2007
@@ -33,6 +33,7 @@
'lstat' : 'interp_posix.lstat',
'dup' : 'interp_posix.dup',
'dup2' : 'interp_posix.dup2',
+ 'access' : 'interp_posix.access',
'system' : 'interp_posix.system',
'unlink' : 'interp_posix.unlink',
'remove' : 'interp_posix.remove',
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 Jan 10 03:05:26 2007
@@ -162,6 +162,19 @@
raise wrap_oserror(space, e)
dup2.unwrap_spec = [ObjSpace, int, int]
+def access(space, path, mode):
+ """
+ access(path, mode) -> 1 if granted, 0 otherwise
+
+ Use the real uid/gid to test for access to a path. Note that most
+ operations will use the effective uid/gid, therefore this routine can
+ be used in a suid/sgid environment to test if the invoking user has the
+ specified access to the path. The mode argument can be F_OK to test
+ existence, or the inclusive-OR of R_OK, W_OK, and X_OK.
+ """
+ return space.wrap(os.access(path, mode))
+access.unwrap_spec = [ObjSpace, str, int]
+
def system(space, cmd):
"""Execute the command (a string) in a subshell."""
try:
Modified: pypy/dist/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/dist/pypy/module/posix/test/test_posix2.py (original)
+++ pypy/dist/pypy/module/posix/test/test_posix2.py Wed Jan 10 03:05:26 2007
@@ -9,6 +9,7 @@
mod.path.write("this is a test")
pdir = udir.ensure('posixtestdir', dir=True)
pdir.join('file1').write("test1")
+ os.chmod(str(pdir.join('file1')), 0600)
pdir.join('file2').write("test2")
pdir.join('another_longer_file_name').write("test3")
mod.pdir = pdir
@@ -87,6 +88,16 @@
'file1',
'file2']
+
+ def test_access(self):
+ pdir = self.pdir + '/file1'
+ posix = self.posix
+
+ assert posix.access(pdir, posix.R_OK)
+ assert posix.access(pdir, posix.W_OK)
+ assert not posix.access(pdir, posix.X_OK)
+
+
def test_strerror(self):
assert isinstance(self.posix.strerror(0), str)
assert isinstance(self.posix.strerror(1), str)
Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py (original)
+++ pypy/dist/pypy/rpython/extfunctable.py Wed Jan 10 03:05:26 2007
@@ -197,6 +197,7 @@
declare(os.close , noneannotation, 'll_os/close')
declare(os.dup , int , 'll_os/dup')
declare(os.dup2 , noneannotation, 'll_os/dup2')
+declare(os.access , int , 'll_os/access')
declare(os.lseek , r_longlong , 'll_os/lseek')
declare(os.isatty , bool , 'll_os/isatty')
if hasattr(posix, 'ftruncate'):
Modified: pypy/dist/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_os.py (original)
+++ pypy/dist/pypy/rpython/module/ll_os.py Wed Jan 10 03:05:26 2007
@@ -56,6 +56,10 @@
os.dup2(old_fd, new_fd)
ll_os_dup2.suggested_primitive = True
+ def ll_os_access(cls, path, mode):
+ return os.access(cls.from_rstr(path), mode)
+ ll_os_access.suggested_primitive = True
+
def ll_os_lseek(cls, fd,pos,how):
return r_longlong(os.lseek(fd,pos,how))
ll_os_lseek.suggested_primitive = True
Modified: pypy/dist/pypy/rpython/module/test/test_ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/module/test/test_ll_os.py (original)
+++ pypy/dist/pypy/rpython/module/test/test_ll_os.py Wed Jan 10 03:05:26 2007
@@ -3,6 +3,17 @@
from pypy.rpython.lltypesystem.module.ll_os import Implementation as impl
+def test_access():
+ filename = str(udir.join('test_access.txt'))
+ rsfilename = impl.to_rstr(filename)
+
+ fd = file(filename, 'w')
+ fd.close()
+
+ for mode in os.R_OK, os.W_OK, os.X_OK, os.R_OK | os.W_OK | os.X_OK:
+ assert os.access(filename, mode) == impl.ll_os_access(rsfilename, mode)
+
+
def test_open_read_write_close():
filename = str(udir.join('test_open_read_write_close.txt'))
rsfilename = impl.to_rstr(filename)
Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py (original)
+++ pypy/dist/pypy/translator/c/extfunc.py Wed Jan 10 03:05:26 2007
@@ -31,6 +31,7 @@
impl.ll_os_close.im_func: 'LL_os_close',
impl.ll_os_dup.im_func: 'LL_os_dup',
impl.ll_os_dup2.im_func: 'LL_os_dup2',
+ impl.ll_os_access.im_func: 'LL_os_access',
impl.ll_os_stat.im_func: 'LL_os_stat',
impl.ll_os_fstat.im_func: 'LL_os_fstat',
impl.ll_os_lstat.im_func: 'LL_os_lstat',
Modified: pypy/dist/pypy/translator/c/src/ll_os.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll_os.h (original)
+++ pypy/dist/pypy/translator/c/src/ll_os.h Wed Jan 10 03:05:26 2007
@@ -57,6 +57,7 @@
void LL_os_close(int fd);
int LL_os_dup(int fd);
void LL_os_dup2(int old_fd, int new_fd);
+int LL_os_access(RPyString *filename, int mode);
RPySTAT_RESULT* _stat_construct_result_helper(STRUCT_STAT st);
RPySTAT_RESULT* LL_os_stat(RPyString * fname);
RPySTAT_RESULT* LL_os_lstat(RPyString * fname);
@@ -153,6 +154,11 @@
RPYTHON_RAISE_OSERROR(errno);
}
+int LL_os_access(RPyString *filename, int mode) {
+ int n = access(RPyString_AsString(filename), mode);
+ return (n == 0);
+}
+
#ifdef LL_NEED_OS_STAT
RPySTAT_RESULT* _stat_construct_result_helper(STRUCT_STAT st) {
Modified: pypy/dist/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_extfunc.py (original)
+++ pypy/dist/pypy/translator/c/test/test_extfunc.py Wed Jan 10 03:05:26 2007
@@ -120,6 +120,16 @@
f1()
os.unlink(filename)
+
+def test_os_access():
+ filename = str(py.magic.autopath())
+ def call_access(path, mode):
+ return os.access(path, mode)
+ f = compile(call_access, [str, int])
+ for mode in os.R_OK, os.W_OK, os.X_OK, (os.R_OK | os.W_OK | os.X_OK):
+ assert f(filename, mode) == os.access(filename, mode)
+
+
def test_os_stat():
filename = str(py.magic.autopath())
def call_stat():
More information about the Pypy-commit
mailing list