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

afa at codespeak.net afa at codespeak.net
Thu Jul 15 10:14:26 CEST 2010


Author: afa
Date: Thu Jul 15 10:14:24 2010
New Revision: 76229

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


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	Thu Jul 15 10:14:24 2010
@@ -481,13 +481,13 @@
     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)
-    except OSError, e: 
-        raise wrap_oserror(space, e, path)
-chmod.unwrap_spec = [ObjSpace, str, "c_int"]
+    try:
+        dispatch_filename(rposix.chmod)(space, w_path, mode)
+    except OSError, e:
+        raise wrap_oserror2(space, e, w_path)
+chmod.unwrap_spec = [ObjSpace, W_Root, "c_int"]
 
 def rename(space, old, new):
     "Rename a file or 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	Thu Jul 15 10:14:24 2010
@@ -90,6 +90,13 @@
         return os.access(path.encode(), mode)
 
 @specialize.argtype(0)
+def chmod(path, mode):
+    if isinstance(path, str):
+        return os.chmod(path, mode)
+    else:
+        return os.chmod(path.encode(), mode)
+
+ at specialize.argtype(0)
 def chdir(path):
     if isinstance(path, str):
         return os.chdir(path)

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	Thu Jul 15 10:14:24 2010
@@ -10,10 +10,16 @@
     def __init__(self, unistr):
         self.unistr = unistr
 
-    def encode(self):
-        from pypy.rlib.runicode import unicode_encode_utf_8
-        return unicode_encode_utf_8(self.unistr, len(self.unistr),
-                                    "strict")
+    if sys.platform == 'win32':
+        def encode(self):
+            from pypy.rlib.runicode import unicode_encode_mbcs
+            return unicode_encode_mbcs(self.unistr, len(self.unistr),
+                                       "strict")
+    else:
+        def encode(self):
+            from pypy.rlib.runicode import unicode_encode_utf_8
+            return unicode_encode_utf_8(self.unistr, len(self.unistr),
+                                        "strict")
 
     def gettext(self):
         return self.unistr
@@ -54,6 +60,12 @@
 
         assert interpret(f, []) == 1
 
+    def test_chmod(self):
+        def f():
+            return rposix.chmod(self.path, 0777)
+
+        interpret(f, []) # does not crash
+
     def test_unlink(self):
         def f():
             return rposix.unlink(self.path)

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	Thu Jul 15 10:14:24 2010
@@ -1567,6 +1567,19 @@
         return extdef([str, int], s_None, llimpl=chmod_llimpl,
                       export_name="ll_os.ll_os_chmod")
 
+    @registering_unicode_version(os.chmod, 2, [0], sys.platform=='win32')
+    def register_os_chmod_unicode(self):
+        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_wchmod(path, rffi.cast(rffi.MODE_T, mode)))
+            if res < 0:
+                raise OSError(rposix.get_errno(), "os_chmod failed")
+
+        return extdef([unicode, int], s_None, llimpl=chmod_llimpl,
+                      export_name="ll_os.ll_os_wchmod")
+
     @registering(os.rename)
     def register_os_rename(self):
         os_rename = self.llexternal('rename', [rffi.CCHARP, rffi.CCHARP],



More information about the Pypy-commit mailing list