[pypy-svn] r64628 - in pypy/branch/unicode_filename/pypy: module/posix rpython/module
afa at codespeak.net
afa at codespeak.net
Fri Apr 24 10:20:57 CEST 2009
Author: afa
Date: Fri Apr 24 10:20:55 2009
New Revision: 64628
Modified:
pypy/branch/unicode_filename/pypy/module/posix/__init__.py
pypy/branch/unicode_filename/pypy/module/posix/interp_posix.py
pypy/branch/unicode_filename/pypy/rpython/module/ll_os.py
Log:
os.rmdir and os.getcwdu
Modified: pypy/branch/unicode_filename/pypy/module/posix/__init__.py
==============================================================================
--- pypy/branch/unicode_filename/pypy/module/posix/__init__.py (original)
+++ pypy/branch/unicode_filename/pypy/module/posix/__init__.py Fri Apr 24 10:20:55 2009
@@ -47,6 +47,7 @@
'unlink' : 'interp_posix.unlink',
'remove' : 'interp_posix.remove',
'getcwd' : 'interp_posix.getcwd',
+ 'getcwdu' : 'interp_posix.getcwdu',
'chdir' : 'interp_posix.chdir',
'mkdir' : 'interp_posix.mkdir',
'rmdir' : 'interp_posix.rmdir',
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 10:20:55 2009
@@ -344,6 +344,16 @@
return space.wrap(cur)
getcwd.unwrap_spec = [ObjSpace]
+def getcwdu(space):
+ """Return a unicode string representing the current working directory."""
+ try:
+ cur = os.getcwdu()
+ except OSError, e:
+ raise wrap_oserror(space, e)
+ else:
+ return space.wrap(cur)
+getcwd.unwrap_spec = [ObjSpace]
+
def chdir(space, w_path):
"""Change the current working directory to the specified path."""
try:
@@ -360,13 +370,13 @@
raise wrap_oserror(space, e)
mkdir.unwrap_spec = [ObjSpace, W_Root, int]
-def rmdir(space, path):
+def rmdir(space, w_path):
"""Remove a directory."""
try:
- os.rmdir(path)
+ wrapper(os.rmdir)(space, w_path, ())
except OSError, e:
raise wrap_oserror(space, e)
-rmdir.unwrap_spec = [ObjSpace, str]
+rmdir.unwrap_spec = [ObjSpace, W_Root]
def strerror(space, errno):
"""Translate an error code to a message string."""
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 10:20:55 2009
@@ -942,15 +942,21 @@
llimpl=_getfullpathname_llimpl)
@registering(os.getcwd)
- def register_os_getcwd(self):
+ def register_os_getcwd(self, unicodepath=False):
+ if unicodepath:
+ tp = unicode
+ TP = rffi.CWCHARP
+ else:
+ tp = str
+ TP = rffi.CCHARP
os_getcwd = self.llexternal(underscore_on_windows + 'getcwd',
- [rffi.CCHARP, rffi.SIZE_T],
- rffi.CCHARP)
+ [TP, rffi.SIZE_T],
+ TP)
def os_getcwd_llimpl():
bufsize = 256
while True:
- buf = lltype.malloc(rffi.CCHARP.TO, bufsize, flavor='raw')
+ buf = lltype.malloc(TP.TO, bufsize, flavor='raw')
res = os_getcwd(buf, rffi.cast(rffi.SIZE_T, bufsize))
if res:
break # ok
@@ -962,17 +968,24 @@
bufsize *= 4
if bufsize > 1024*1024: # xxx hard-coded upper limit
raise OSError(error, "getcwd result too large")
- result = rffi.charp2str(res)
+ if tp is str:
+ result = rffi.charp2str(res)
+ else:
+ result = rffi.wcharp2unicode(res)
lltype.free(buf, flavor='raw')
return result
def os_getcwd_oofakeimpl():
return OOSupport.to_rstr(os.getcwd())
- return extdef([], str,
+ return extdef([], tp,
"ll_os.ll_os_getcwd", llimpl=os_getcwd_llimpl,
oofakeimpl=os_getcwd_oofakeimpl)
+ @registering(os.getcwdu)
+ def register_os_getcwdu(self):
+ return self.register_os_getcwd(unicodepath=True)
+
@registering(os.listdir)
def register_os_listdir(self):
# we need a different approach on Windows and on Posix
@@ -1326,11 +1339,16 @@
@registering(os.rmdir)
def register_os_rmdir(self):
os_rmdir = self.llexternal(underscore_on_windows+'rmdir', [rffi.CCHARP], rffi.INT)
+ os_wrmdir = self.llexternal(underscore_on_windows+'wrmdir', [rffi.CWCHARP], rffi.INT)
def rmdir_llimpl(pathname):
- res = rffi.cast(lltype.Signed, os_rmdir(pathname))
+ if isinstance(pathname, str):
+ res = rffi.cast(lltype.Signed, os_rmdir(pathname))
+ else:
+ res = rffi.cast(lltype.Signed, os_wrmdir(pathname))
if res < 0:
raise OSError(rposix.get_errno(), "os_rmdir failed")
+ rmdir_llimpl._annspecialcase_ = 'specialize:argtype(0)'
return extdef([str], s_None, llimpl=rmdir_llimpl,
export_name="ll_os.ll_os_rmdir")
More information about the Pypy-commit
mailing list