[pypy-svn] r79988 - in pypy/branch/more-posix/pypy: module/posix module/posix/test rlib
arigo at codespeak.net
arigo at codespeak.net
Sat Dec 11 17:13:46 CET 2010
Author: arigo
Date: Sat Dec 11 17:13:44 2010
New Revision: 79988
Modified:
pypy/branch/more-posix/pypy/module/posix/__init__.py
pypy/branch/more-posix/pypy/module/posix/interp_posix.py
pypy/branch/more-posix/pypy/module/posix/test/test_posix2.py
pypy/branch/more-posix/pypy/rlib/rposix.py
Log:
os.mknod().
Modified: pypy/branch/more-posix/pypy/module/posix/__init__.py
==============================================================================
--- pypy/branch/more-posix/pypy/module/posix/__init__.py (original)
+++ pypy/branch/more-posix/pypy/module/posix/__init__.py Sat Dec 11 17:13:44 2010
@@ -117,6 +117,8 @@
interpleveldefs['getloadavg'] = 'interp_posix.getloadavg'
if hasattr(os, 'mkfifo'):
interpleveldefs['mkfifo'] = 'interp_posix.mkfifo'
+ if hasattr(os, 'mknod'):
+ interpleveldefs['mknod'] = 'interp_posix.mknod'
for name in ['setsid', 'getuid', 'geteuid', 'getgid', 'getegid', 'setuid',
'seteuid', 'setgid', 'setegid', 'getpgrp', 'setpgrp',
Modified: pypy/branch/more-posix/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/branch/more-posix/pypy/module/posix/interp_posix.py (original)
+++ pypy/branch/more-posix/pypy/module/posix/interp_posix.py Sat Dec 11 17:13:44 2010
@@ -562,6 +562,19 @@
raise wrap_oserror2(space, e, w_filename)
mkfifo.unwrap_spec = [ObjSpace, W_Root, "c_int"]
+def mknod(space, w_filename, mode=0600, device=0):
+ """Create a filesystem node (file, device special file or named pipe)
+named filename. mode specifies both the permissions to use and the
+type of node to be created, being combined (bitwise OR) with one of
+S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. For S_IFCHR and S_IFBLK,
+device defines the newly created device special file (probably using
+os.makedev()), otherwise it is ignored."""
+ try:
+ dispatch_filename(rposix.mknod)(space, w_filename, mode, device)
+ except OSError, e:
+ raise wrap_oserror2(space, e, w_filename)
+mknod.unwrap_spec = [ObjSpace, W_Root, "c_int", "c_int"]
+
def umask(space, mask):
"Set the current numeric umask and return the previous umask."
prevmask = os.umask(mask)
Modified: pypy/branch/more-posix/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/branch/more-posix/pypy/module/posix/test/test_posix2.py (original)
+++ pypy/branch/more-posix/pypy/module/posix/test/test_posix2.py Sat Dec 11 17:13:44 2010
@@ -667,6 +667,35 @@
import stat
assert stat.S_ISFIFO(st.st_mode)
+ if hasattr(os, 'mknod'):
+ def test_mknod(self):
+ import stat
+ os = self.posix
+ # not very useful: os.mknod() without specifying 'mode'
+ os.mknod(self.path2 + 'test_mknod-1')
+ st = os.lstat(self.path2 + 'test_mknod-1')
+ assert stat.S_ISREG(st.st_mode)
+ # os.mknod() with S_IFIFO
+ os.mknod(self.path2 + 'test_mknod-2', 0600 | stat.S_IFIFO)
+ st = os.lstat(self.path2 + 'test_mknod-2')
+ assert stat.S_ISFIFO(st.st_mode)
+
+ def test_mknod_with_ifchr(self):
+ # os.mknod() with S_IFCHR
+ # -- usually requires root priviledges --
+ os = self.posix
+ if hasattr(os.lstat('.'), 'st_rdev'):
+ import stat
+ try:
+ os.mknod(self.path2 + 'test_mknod-3', 0600 | stat.S_IFCHR,
+ 0x105)
+ except OSError, e:
+ skip("os.mknod() with S_IFCHR: got %r" % (e,))
+ else:
+ st = os.lstat(self.path2 + 'test_mknod-3')
+ assert stat.S_ISCHR(st.st_mode)
+ assert st.st_rdev == 0x105
+
class AppTestEnvironment(object):
def setup_class(cls):
Modified: pypy/branch/more-posix/pypy/rlib/rposix.py
==============================================================================
--- pypy/branch/more-posix/pypy/rlib/rposix.py (original)
+++ pypy/branch/more-posix/pypy/rlib/rposix.py Sat Dec 11 17:13:44 2010
@@ -142,6 +142,13 @@
else:
os.mkfifo(path.as_bytes(), mode)
+ at specialize.argtype(0)
+def mknod(path, mode, device):
+ if isinstance(path, str):
+ os.mknod(path, mode, device)
+ else:
+ os.mknod(path.as_bytes(), mode, device)
+
if os.name == 'nt':
import nt
def _getfullpathname(path):
More information about the Pypy-commit
mailing list