[pypy-svn] r76182 - in pypy/branch/unicode_filename-2/pypy: module/posix rlib rlib/test rpython/module
afa at codespeak.net
afa at codespeak.net
Tue Jul 13 15:36:41 CEST 2010
Author: afa
Date: Tue Jul 13 15:36:40 2010
New Revision: 76182
Modified:
pypy/branch/unicode_filename-2/pypy/module/posix/interp_posix.py
pypy/branch/unicode_filename-2/pypy/rlib/rposix.py
pypy/branch/unicode_filename-2/pypy/rlib/test/test_rposix.py
pypy/branch/unicode_filename-2/pypy/rpython/module/ll_os.py
Log:
Unicode version of os.unlink()
This should help the unit tests to remove their temp files...
Modified: pypy/branch/unicode_filename-2/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/branch/unicode_filename-2/pypy/module/posix/interp_posix.py (original)
+++ pypy/branch/unicode_filename-2/pypy/module/posix/interp_posix.py Tue Jul 13 15:36:40 2010
@@ -302,21 +302,21 @@
return space.wrap(rc)
system.unwrap_spec = [ObjSpace, str]
-def unlink(space, path):
+def unlink(space, w_path):
"""Remove a file (same as remove(path))."""
try:
- os.unlink(path)
- except OSError, e:
- raise wrap_oserror(space, e, path)
-unlink.unwrap_spec = [ObjSpace, 'path']
+ dispatch_filename(rposix.unlink)(space, w_path)
+ except OSError, e:
+ raise wrap_oserror2(space, e, w_path)
+unlink.unwrap_spec = [ObjSpace, W_Root]
-def remove(space, path):
+def remove(space, w_path):
"""Remove a file (same as unlink(path))."""
try:
- os.unlink(path)
- except OSError, e:
- raise wrap_oserror(space, e, path)
-remove.unwrap_spec = [ObjSpace, 'path']
+ dispatch_filename(rposix.unlink)(space, w_path)
+ except OSError, e:
+ raise wrap_oserror2(space, e, w_path)
+remove.unwrap_spec = [ObjSpace, W_Root]
def _getfullpathname(space, path):
"""helper for ntpath.abspath """
Modified: pypy/branch/unicode_filename-2/pypy/rlib/rposix.py
==============================================================================
--- pypy/branch/unicode_filename-2/pypy/rlib/rposix.py (original)
+++ pypy/branch/unicode_filename-2/pypy/rlib/rposix.py Tue Jul 13 15:36:40 2010
@@ -67,3 +67,10 @@
return os.lstat(path)
else:
return os.lstat(path.encode())
+
+ at specialize.argtype(0)
+def unlink(path):
+ if isinstance(path, str):
+ return os.unlink(path)
+ else:
+ return os.unlink(path.encode())
Modified: pypy/branch/unicode_filename-2/pypy/rlib/test/test_rposix.py
==============================================================================
--- pypy/branch/unicode_filename-2/pypy/rlib/test/test_rposix.py (original)
+++ pypy/branch/unicode_filename-2/pypy/rlib/test/test_rposix.py Tue Jul 13 15:36:40 2010
@@ -7,10 +7,10 @@
return ''.join(s.chars)
class TestPosixUnicode:
- def setup_class(cls):
- cls.ufilename = (unicode(udir.join('test_open')) +
- u'\u65e5\u672c.txt') # "Japan"
- f = file(cls.ufilename, 'w')
+ def setup_method(self, method):
+ self.ufilename = (unicode(udir.join('test_open')) +
+ u'\u65e5\u672c.txt') # "Japan"
+ f = file(self.ufilename, 'w')
f.write("test")
f.close()
@@ -26,7 +26,7 @@
def gettext(self):
return self.unistr
- cls.path = UnicodeWithEncoding(cls.ufilename)
+ self.path = UnicodeWithEncoding(self.ufilename)
def test_access(self):
def f():
@@ -47,3 +47,10 @@
return rposix.stat(self.path).st_mtime
assert interpret(f, []) == os.stat(self.ufilename).st_mtime
+
+ def test_unlink(self):
+ def f():
+ return rposix.unlink(self.path)
+
+ interpret(f, [])
+ assert not os.path.exists(self.ufilename)
Modified: pypy/branch/unicode_filename-2/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/unicode_filename-2/pypy/rpython/module/ll_os.py (original)
+++ pypy/branch/unicode_filename-2/pypy/rpython/module/ll_os.py Tue Jul 13 15:36:40 2010
@@ -1306,6 +1306,18 @@
return extdef([str], s_None, llimpl=unlink_llimpl,
export_name="ll_os.ll_os_unlink")
+ @registering_unicode_version(os.unlink, 1, [0], sys.platform=='win32')
+ def register_os_unlink_unicode(self):
+ os_wunlink = self.llexternal(underscore_on_windows+'wunlink', [rffi.CWCHARP], rffi.INT)
+
+ def wunlink_llimpl(pathname):
+ res = rffi.cast(lltype.Signed, os_wunlink(pathname))
+ if res < 0:
+ raise OSError(rposix.get_errno(), "os_unlink failed")
+
+ return extdef([unicode], s_None, llimpl=wunlink_llimpl,
+ export_name="ll_os.ll_os_wunlink")
+
@registering(os.chdir)
def register_os_chdir(self):
os_chdir = self.llexternal(underscore_on_windows+'chdir', [rffi.CCHARP], rffi.INT)
More information about the Pypy-commit
mailing list