[pypy-svn] r64612 - in pypy/branch/unicode_filename/pypy: module/bz2 module/posix rlib rpython/module
afa at codespeak.net
afa at codespeak.net
Fri Apr 24 00:01:19 CEST 2009
Author: afa
Date: Fri Apr 24 00:01:17 2009
New Revision: 64612
Modified:
pypy/branch/unicode_filename/pypy/module/bz2/interp_bz2.py
pypy/branch/unicode_filename/pypy/module/posix/interp_posix.py
pypy/branch/unicode_filename/pypy/rlib/streamio.py
pypy/branch/unicode_filename/pypy/rpython/module/ll_os.py
Log:
More progress. This even translates.
Modified: pypy/branch/unicode_filename/pypy/module/bz2/interp_bz2.py
==============================================================================
--- pypy/branch/unicode_filename/pypy/module/bz2/interp_bz2.py (original)
+++ pypy/branch/unicode_filename/pypy/module/bz2/interp_bz2.py Fri Apr 24 00:01:17 2009
@@ -274,7 +274,7 @@
if basemode == "a":
raise OperationError(space.w_ValueError,
space.wrap("cannot append to bz2 file"))
- stream = open_path_helper(space.str_w(w_path), os_flags, False)
+ stream = open_path_helper(space.str_w(w_path), os_flags)
if reading:
bz2stream = ReadBZ2Filter(space, stream, buffering)
buffering = 0 # by construction, the ReadBZ2Filter acts like
Modified: pypy/branch/unicode_filename/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/branch/unicode_filename/pypy/module/posix/interp_posix.py (original)
+++ pypy/branch/unicode_filename/pypy/module/posix/interp_posix.py Fri Apr 24 00:01:17 2009
@@ -154,12 +154,27 @@
else:
return impl(space.str_w(w_path), *args)
return f
+ def wrapper2(fn):
+ impl = extregistry.lookup(fn).lltypeimpl
+ def f(space, w_path1, w_path2, args):
+ if (space.is_true(space.isinstance(w_path1, space.w_unicode)) and
+ space.is_true(space.isinstance(w_path2, space.w_unicode))):
+ return impl(space.unicode_w(w_path1),
+ space.unicode_w(w_path2), *args)
+ else:
+ return impl(space.str_w(w_path1), space.str_w(w_path2), *args)
+ return f
else:
def wrapper(fn):
def f(space, w_path, args):
return fn(space.str_w(w_path), *args)
return f
+ def wrapper2(fn):
+ def f(space, w_path1, w_path2, args):
+ return fn(space.str_w(w_path1), space.str_w(w_path2), *args)
+ return f
wrapper._annspecialcase_ = 'specialize:memo'
+wrapper2._annspecialcase_ = 'specialize:memo'
def stat(space, w_path):
"""Perform a stat system call on the given path. Return an object
@@ -233,7 +248,7 @@
raise wrap_oserror(space, e)
dup2.unwrap_spec = [ObjSpace, int, int]
-def access(space, path, mode):
+def access(space, w_path, mode):
"""
access(path, mode) -> 1 if granted, 0 otherwise
@@ -244,12 +259,12 @@
existence, or the inclusive-OR of R_OK, W_OK, and X_OK.
"""
try:
- ok = os.access(path, mode)
+ ok = wrapper(os.access)(space, w_path, (mode,))
except OSError, e:
raise wrap_oserror(space, e)
else:
return space.wrap(ok)
-access.unwrap_spec = [ObjSpace, str, int]
+access.unwrap_spec = [ObjSpace, W_Root, int]
def times(space):
@@ -280,21 +295,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)
+ wrapper(os.unlink)(space, w_path, ())
except OSError, e:
raise wrap_oserror(space, e)
-unlink.unwrap_spec = [ObjSpace, str]
+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)
+ wrapper(os.unlink)(space, w_path, ())
except OSError, e:
raise wrap_oserror(space, e)
-remove.unwrap_spec = [ObjSpace, str]
+remove.unwrap_spec = [ObjSpace, W_Root]
def _getfullpathname(space, path):
"""helper for ntpath.abspath """
@@ -425,21 +440,21 @@
return space.newtuple([space.wrap(fd1), space.wrap(fd2)])
pipe.unwrap_spec = [ObjSpace]
-def chmod(space, path, mode):
+def chmod(space, w_path, mode):
"Change the access permissions of a file."
try:
- os.chmod(path, mode)
+ wrapper(os.chmod)(space, w_path, (mode,))
except OSError, e:
raise wrap_oserror(space, e)
-chmod.unwrap_spec = [ObjSpace, str, int]
+chmod.unwrap_spec = [ObjSpace, W_Root, int]
-def rename(space, old, new):
+def rename(space, w_old, w_new):
"Rename a file or directory."
- try:
- os.rename(old, new)
+ try:
+ wrapper2(os.rename)(space, w_old, w_new, ())
except OSError, e:
raise wrap_oserror(space, e)
-rename.unwrap_spec = [ObjSpace, str, str]
+rename.unwrap_spec = [ObjSpace, W_Root, W_Root]
def umask(space, mask):
"Set the current numeric umask and return the previous umask."
Modified: pypy/branch/unicode_filename/pypy/rlib/streamio.py
==============================================================================
--- pypy/branch/unicode_filename/pypy/rlib/streamio.py (original)
+++ pypy/branch/unicode_filename/pypy/rlib/streamio.py Fri Apr 24 00:01:17 2009
@@ -75,7 +75,13 @@
def open_file_as_stream(path, mode="r", buffering=-1):
os_flags, universal, reading, writing, basemode, binary = decode_mode(mode)
- stream = open_path_helper(path, os_flags, basemode == "a")
+ stream = open_path_helper(path, os_flags)
+ if basemode == "a":
+ try:
+ stream.seek(0, 2)
+ except OSError:
+ # XXX does this pass make sense?
+ pass
return construct_stream_tower(stream, buffering, universal, reading,
writing, binary)
open_file_as_stream._annspecialcase_ = 'specialize:argtype(0)'
@@ -92,20 +98,20 @@
return construct_stream_tower(stream, buffering, universal, reading,
writing, binary)
-def open_path_helper(path, os_flags, append):
- # XXX for now always return DiskFile
- if _WIN32 and isinstance(path, unicode):
- fd = ll_os.os_wopen(path, os_flags, 0666)
- else:
+if _WIN32:
+ def open_path_helper(path, os_flags):
+ # XXX for now always return DiskFile
+ if isinstance(path, unicode):
+ fd = ll_os.os_wopen(path, os_flags, 0666)
+ else:
+ fd = os.open(path, os_flags, 0666)
+ return DiskFile(fd)
+ open_path_helper._annspecialcase_ = 'specialize:argtype(0)'
+else:
+ def open_path_helper(path, os_flags):
+ # XXX for now always return DiskFile
fd = os.open(path, os_flags, 0666)
- if append:
- try:
- os.lseek(fd, 0, 2)
- except OSError:
- # XXX does this pass make sense?
- pass
- return DiskFile(fd)
-open_path_helper._annspecialcase_ = 'specialize:argtype(0)'
+ return DiskFile(fd)
def decode_mode(mode):
if mode[0] == 'U':
Modified: pypy/branch/unicode_filename/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/unicode_filename/pypy/rpython/module/ll_os.py (original)
+++ pypy/branch/unicode_filename/pypy/rpython/module/ll_os.py Fri Apr 24 00:01:17 2009
@@ -724,7 +724,7 @@
def os_wopen_oofakeimpl(o_path, flags, mode):
return os.open(o_path._str, flags, mode)
- return extdef([str, int, int], int, "ll_os.ll_os_wopen",
+ return extdef([unicode, int, int], int, "ll_os.ll_os_wopen",
llimpl=os_wopen_llimpl, oofakeimpl=os_wopen_oofakeimpl)
# ------------------------------- os.read -------------------------------
@@ -862,13 +862,20 @@
os_access = self.llexternal(underscore_on_windows + 'access',
[rffi.CCHARP, rffi.INT],
rffi.INT)
+ os_waccess = self.llexternal(underscore_on_windows + 'waccess',
+ [rffi.CWCHARP, rffi.INT],
+ rffi.INT)
if sys.platform.startswith('win'):
# All files are executable on Windows
def access_llimpl(path, mode):
mode = mode & ~os.X_OK
- error = rffi.cast(lltype.Signed, os_access(path, mode))
+ if isinstance(path, str):
+ error = rffi.cast(lltype.Signed, os_access(path, mode))
+ else:
+ error = rffi.cast(lltype.Signed, os_waccess(path, mode))
return error == 0
+ access_llimpl._annspecialcase_ = 'specialize:argtype(0)'
else:
def access_llimpl(path, mode):
error = rffi.cast(lltype.Signed, os_access(path, mode))
@@ -1254,11 +1261,16 @@
@registering(os.unlink)
def register_os_unlink(self):
os_unlink = self.llexternal(underscore_on_windows+'unlink', [rffi.CCHARP], rffi.INT)
+ os_wunlink = self.llexternal(underscore_on_windows+'wunlink', [rffi.CWCHARP], rffi.INT)
def unlink_llimpl(pathname):
- res = rffi.cast(lltype.Signed, os_unlink(pathname))
+ if isinstance(pathname, str):
+ res = rffi.cast(lltype.Signed, os_unlink(pathname))
+ else:
+ res = rffi.cast(lltype.Signed, os_wunlink(pathname))
if res < 0:
raise OSError(rposix.get_errno(), "os_unlink failed")
+ unlink_llimpl._annspecialcase_ = 'specialize:argtype(0)'
return extdef([str], s_None, llimpl=unlink_llimpl,
export_name="ll_os.ll_os_unlink")
@@ -1327,11 +1339,17 @@
def register_os_chmod(self):
os_chmod = self.llexternal(underscore_on_windows+'chmod', [rffi.CCHARP, rffi.MODE_T],
rffi.INT)
+ os_wchmod = self.llexternal(underscore_on_windows+'wchmod', [rffi.CWCHARP, rffi.MODE_T],
+ rffi.INT)
def chmod_llimpl(path, mode):
- res = rffi.cast(lltype.Signed, os_chmod(path, rffi.cast(rffi.MODE_T, mode)))
+ if isinstance(path, str):
+ res = rffi.cast(lltype.Signed, os_chmod(path, rffi.cast(rffi.MODE_T, mode)))
+ else:
+ res = rffi.cast(lltype.Signed, os_wchmod(path, rffi.cast(rffi.MODE_T, mode)))
if res < 0:
raise OSError(rposix.get_errno(), "os_chmod failed")
+ chmod_llimpl._annspecialcase_ = 'specialize:argtype(0)'
return extdef([str, int], s_None, llimpl=chmod_llimpl,
export_name="ll_os.ll_os_chmod")
@@ -1340,11 +1358,17 @@
def register_os_rename(self):
os_rename = self.llexternal('rename', [rffi.CCHARP, rffi.CCHARP],
rffi.INT)
+ os_wrename = self.llexternal('wrename', [rffi.CWCHARP, rffi.CWCHARP],
+ rffi.INT)
def rename_llimpl(oldpath, newpath):
- res = rffi.cast(lltype.Signed, os_rename(oldpath, newpath))
+ if isinstance(oldpath, str):
+ res = rffi.cast(lltype.Signed, os_rename(oldpath, newpath))
+ else:
+ res = rffi.cast(lltype.Signed, os_wrename(oldpath, newpath))
if res < 0:
raise OSError(rposix.get_errno(), "os_rename failed")
+ rename_llimpl._annspecialcase_ = 'specialize:argtype(0)'
return extdef([str, str], s_None, llimpl=rename_llimpl,
export_name="ll_os.ll_os_rename")
More information about the Pypy-commit
mailing list