From: <pj...@us...> - 2009-05-28 05:32:19
|
Revision: 6413 http://jython.svn.sourceforge.net/jython/?rev=6413&view=rev Author: pjenvey Date: 2009-05-28 05:32:12 +0000 (Thu, 28 May 2009) Log Message: ----------- combine getPath/getPathLazy and special case paths with a single leading '\' (e.g. r'\Jython25') as an absolute path on Windows Modified Paths: -------------- trunk/jython/src/org/python/core/PySystemState.java Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2009-05-28 05:31:51 UTC (rev 6412) +++ trunk/jython/src/org/python/core/PySystemState.java 2009-05-28 05:32:12 UTC (rev 6413) @@ -19,6 +19,7 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; +import org.jruby.ext.posix.util.Platform; import org.python.Version; import org.python.core.adapter.ClassicPyObjectAdapter; import org.python.core.adapter.ExtensiblePyObjectAdapter; @@ -482,16 +483,40 @@ * @return a resolved path String */ public String getPath(String path) { + return getPath(this, path); + } + + /** + * Resolve a path. Returns the full path taking the current + * working directory into account. + * + * Like getPath but called statically. The current PySystemState + * is only consulted for the current working directory when it's + * necessary (when the path is relative). + * + * @param path a path String + * @return a resolved path String + */ + public static String getPathLazy(String path) { + // XXX: This method likely an unnecessary optimization + return getPath(null, path); + } + + private static String getPath(PySystemState sys, String path) { if (path == null) { return path; - } else { - File file = new File(path); - if (!file.isAbsolute()) { - file = new File(getCurrentWorkingDir(), path); + } + + File file = new File(path); + // Python considers r'\Jython25' an abspath on Windows, unlike java.io.File + if (!file.isAbsolute() && (!Platform.IS_WINDOWS || !path.startsWith("\\"))) { + if (sys == null) { + sys = Py.getSystemState(); } - // This needs to be performed always to trim trailing backslashes on Windows - return file.getPath(); + file = new File(sys.getCurrentWorkingDir(), path); } + // This needs to be performed always to trim trailing backslashes on Windows + return file.getPath(); } public void callExitFunc() throws PyIgnoreMethodTag { @@ -1146,24 +1171,6 @@ packageManager.addJarDir(directoryPath, cache); } - /** - * Resolve a path. Returns the full path taking the current - * working directory into account. - * - * Like getPath but called statically. The current PySystemState - * is only consulted for the current working directory when it's - * necessary (when the path is relative). - * - * @param path a path String - * @return a resolved path String - */ - public static String getPathLazy(String path) { - if (path == null || new File(path).isAbsolute()) { - return path; - } - return new File(Py.getSystemState().getCurrentWorkingDir(), path).getPath(); - } - // Not public by design. We can't rebind the displayhook if // a reflected function is inserted in the class dict. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |