Author: Preston Timmons <[email protected]>
Branch: py3k
Changeset: r53575:fb962fdecd9f
Date: 2012-03-13 21:30 +0000
http://bitbucket.org/pypy/pypy/changeset/fb962fdecd9f/
Log: Added getcwdb to posix module.
Also readded old getcwdu function as getcwd for posix system that
returns the directory string encoded with the file system encoding.
Otherwise, unicode is assumed.
diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -70,6 +70,7 @@
'unlink' : 'interp_posix.unlink',
'remove' : 'interp_posix.remove',
'getcwd' : 'interp_posix.getcwd',
+ 'getcwdb' : 'interp_posix.getcwdb',
'chdir' : 'interp_posix.chdir',
'mkdir' : 'interp_posix.mkdir',
'rmdir' : 'interp_posix.rmdir',
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
@@ -409,14 +409,30 @@
else:
return w_fullpath
-def getcwd(space):
+def getcwdb(space):
"""Return the current working directory."""
try:
cur = os.getcwd()
except OSError, e:
raise wrap_oserror(space, e)
else:
- return space.wrap(cur)
+ return space.wrapbytes(cur)
+
+if sys.platform == 'win32':
+ def getcwd(space):
+ """Return the current working directory as a string."""
+ try:
+ cur = os.getcwdb()
+ except OSError, e:
+ raise wrap_oserror(space, e)
+ else:
+ return space.wrap(cur)
+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))
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
@@ -266,6 +266,9 @@
def test_getcwd(self):
assert isinstance(self.posix.getcwd(), str)
+ def test_getcwdb(self):
+ assert isinstance(self.posix.getcwdb(), bytes)
+
def test_listdir(self):
pdir = self.pdir
posix = self.posix
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit