Author: Antonio Cuni <[email protected]>
Branch: app_main-refactor
Changeset: r55507:4ac1f0f2666b
Date: 2012-06-08 14:33 +0200
http://bitbucket.org/pypy/pypy/changeset/4ac1f0f2666b/
Log: add rlib.rpath, which contains RPython (and more limited) versions
of some os.path functions
diff --git a/pypy/rlib/rpath.py b/pypy/rlib/rpath.py
new file mode 100644
--- /dev/null
+++ b/pypy/rlib/rpath.py
@@ -0,0 +1,22 @@
+"""
+Minimal (and limited) RPython version of some functions contained in os.path.
+"""
+
+import os.path
+from os import sep, pathsep
+from pypy.rlib import rposix
+
+if os.name == 'posix':
+ # the posix version is already RPython, just use it
+ rabspath = os.path.abspath
+elif os.name == 'nt':
+ def rabspath(path):
+ if path == '':
+ path = os.getcwd()
+ try:
+ return rposix._getfullpathname(path)
+ except OSError:
+ return path
+else:
+ raise ImportError('Unsupported os: %s' % os.name)
+
diff --git a/pypy/rlib/test/test_rpath.py b/pypy/rlib/test/test_rpath.py
new file mode 100644
--- /dev/null
+++ b/pypy/rlib/test/test_rpath.py
@@ -0,0 +1,18 @@
+import py
+import os
+from pypy.rlib import rpath
+
+IS_WINDOWS = os.name == 'nt'
+
+def test_rabspath_relative(tmpdir):
+ tmpdir.chdir()
+ assert rpath.rabspath('foo') == tmpdir.join('foo')
+
[email protected]("IS_WINDOWS")
+def test_rabspath_absolute_posix():
+ assert rpath.rabspath('/foo') == '/foo'
+
[email protected]("not IS_WINDOWS")
+def test_rabspath_absolute_nt():
+ curdrive, _ = os.path.splitdrive(os.getcwd())
+ assert rpath.rabspath('\\foo') == '%s\\foo' % curdrive
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit