[pypy-svn] r76215 - in pypy/branch/unicode_filename-2/pypy: module/posix rlib rlib/test rpython/module

afa at codespeak.net afa at codespeak.net
Wed Jul 14 21:43:55 CEST 2010


Author: afa
Date: Wed Jul 14 21:43:52 2010
New Revision: 76215

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.chdir()


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	Wed Jul 14 21:43:52 2010
@@ -345,13 +345,13 @@
     return space.call_method(getcwd(space), 'decode')
 getcwdu.unwrap_spec = [ObjSpace]
 
-def chdir(space, path):
+def chdir(space, w_path):
     """Change the current working directory to the specified path."""
     try:
-        os.chdir(path)
-    except OSError, e: 
-        raise wrap_oserror(space, e, path)
-chdir.unwrap_spec = [ObjSpace, str]
+        dispatch_filename(rposix.chdir)(space, wpath)
+    except OSError, e:
+        raise wrap_oserror2(space, e, w_path)
+chdir.unwrap_spec = [ObjSpace, W_Root]
 
 def mkdir(space, path, mode=0777):
     """Create a directory."""

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	Wed Jul 14 21:43:52 2010
@@ -88,3 +88,10 @@
         return os.access(path, mode)
     else:
         return os.access(path.encode(), mode)
+
+ at specialize.argtype(0)
+def chdir(path):
+    if isinstance(path, str):
+        return os.access(path)
+    else:
+        return os.access(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	Wed Jul 14 21:43:52 2010
@@ -68,3 +68,17 @@
 
         result = interpret(f, [])
         assert os.path.basename(self.ufilename) in ll_to_string(result)
+
+    def test_chdir(self):
+        os.unlink(self.ufilename)
+        os.mkdir(self.ufilename)
+
+        def f():
+            rposix.chdir(self.path)
+
+        curdir = os.getcwd()
+        try:
+            interpret(f, [])
+            assert os.getcwdu() == self.ufilename
+        finally:
+            os.chdir(curdir)

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	Wed Jul 14 21:43:52 2010
@@ -1412,6 +1412,18 @@
         return extdef([str], s_None, llimpl=chdir_llimpl,
                       export_name="ll_os.ll_os_chdir")
 
+    @registering_unicode_version(os.chdir, 1, [0], sys.platform=='win32')
+    def register_os_chdir(self):
+        os_wchdir = self.llexternal(underscore_on_windows+'wchdir', [rffi.CWCHARP], rffi.INT)
+
+        def chdir_llimpl(path):
+            res = rffi.cast(lltype.Signed, os_wchdir(path))
+            if res < 0:
+                raise OSError(rposix.get_errno(), "os_chdir failed")
+
+        return extdef([unicode], s_None, llimpl=chdir_llimpl,
+                      export_name="ll_os.ll_os_wchdir")
+
     @registering(os.mkdir)
     def register_os_mkdir(self):
         if os.name == 'nt':



More information about the Pypy-commit mailing list