Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r59347:22a93bb43298
Date: 2012-12-05 17:56 -0800
http://bitbucket.org/pypy/pypy/changeset/22a93bb43298/

Log:    fix getcwd to surrogateescape

diff --git a/pypy/module/posix/interp_posix.py 
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -443,9 +443,7 @@
 else:
     def getcwd(space):
         """Return the current working directory as a string."""
-        filesystemencoding = space.sys.filesystemencoding
-        return space.call_method(getcwdb(space), 'decode',
-                                 space.wrap(filesystemencoding))
+        return fsdecode(space, getcwdb(space))
 
 def chdir(space, w_path):
     """Change the current working directory to the specified path."""
diff --git a/pypy/module/posix/test/test_posix2.py 
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -31,6 +31,8 @@
     bytes_dir.join('somefile').write('who cares?')
     bytes_dir.join('caf\xe9').write('who knows?')
     mod.bytes_dir = bytes_dir
+    # an escaped surrogate
+    mod.esurrogate_dir = udir.ensure('foo\x80', dir=True)
 
     # in applevel tests, os.stat uses the CPython os.stat.
     # Be sure to return times with full precision
@@ -62,6 +64,7 @@
         cls.w_path2 = space.wrap(str(path2))
         cls.w_pdir = space.wrap(str(pdir))
         cls.w_bytes_dir = space.wrapbytes(str(bytes_dir))
+        cls.w_esurrogate_dir = space.wrapbytes(str(esurrogate_dir))
         if hasattr(os, 'getuid'):
             cls.w_getuid = space.wrap(os.getuid())
             cls.w_geteuid = space.wrap(os.geteuid())
@@ -265,7 +268,15 @@
         ex(self.posix.dup, UNUSEDFD)
 
     def test_getcwd(self):
-        assert isinstance(self.posix.getcwd(), str)
+        os, posix = self.os, self.posix
+        assert isinstance(posix.getcwd(), str)
+        cwdb = posix.getcwdb()
+        os.chdir(self.esurrogate_dir)
+        try:
+            cwd = posix.getcwd()
+            assert os.fsencode(cwd) == posix.getcwdb()
+        finally:
+            os.chdir(cwdb)
 
     def test_getcwdb(self):
         assert isinstance(self.posix.getcwdb(), bytes)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to