From: SourceForge.net <no...@so...> - 2007-02-17 12:13:27
|
Bugs item #1423047, was opened at 2006-02-03 01:35 Message generated for change (Comment added) made by laukpe You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1423047&group_id=12867 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Library Group: Deferred Status: Closed Resolution: Fixed Priority: 4 Private: No Submitted By: Pekka Laukkanen (laukpe) Assigned to: Nobody/Anonymous (nobody) Summary: os.path.abspath does not normalize as in Python Initial Comment: C:\temp>python Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.path.abspath('..') 'C:\\' >>> ^Z C:\temp>jython Jython 2.2a1 on java1.5.0_04 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import os >>> os.path.abspath('..') 'C:\\temp\\..' >>> os.path.normpath(os.path.abspath('..')) 'C:' >>> ^Z ---------------------------------------------------------------------- >Comment By: Pekka Laukkanen (laukpe) Date: 2007-02-17 14:13 Message: Logged In: YES user_id=1379331 Originator: YES Unfortunately getCanonicalPath has two problems. 1) It raises an IOException in some cases (see e.g. bug [1]) 2) It also eliminates symlinks which abspath doesn't do in CPython (there's realpath for that). As I comment on [1] I have a patch solving both of these issues ready but need write some automated tests for it before submitting. [1] http://jython.org/bugs/1661700 ---------------------------------------------------------------------- Comment By: Charles Groves (cgroves) Date: 2007-02-01 08:09 Message: Logged In: YES user_id=1174327 Originator: NO getCanonicalPath looks right to me too. Committed in r3071. ---------------------------------------------------------------------- Comment By: Pekka Laukkanen (laukpe) Date: 2007-01-12 23:38 Message: Logged In: YES user_id=1379331 Originator: YES Based on those javadocs and little playing on Jython interpreter getCanonicalPath really seems to be the answer. On top of things mentioned in javadocs it also fixes paths like 'c:\temp\\foo' -> 'c:\temp\foo'. Thanks for looking that up. ---------------------------------------------------------------------- Comment By: leouser (leouserz) Date: 2007-01-12 23:12 Message: Logged In: YES user_id=1277399 Originator: NO the answer may be to change in javapath.py: def abspath(path): path = _tostr(path, "abspath") return File(path).getAbsolutePath() to def abspath(path): path = _tostr(path, "abspath") return File(path).getCanonicalPath() using getCanonicalFile on Windows gives me the same answer as the python example above. The javadoc for getCanonicalPath states: A canonical pathname is both absolute and unique. The precise definition of canonical form is system-dependent. This method first converts this pathname to absolute form if necessary, as if by invoking the getAbsolutePath() method, and then maps it to its unique form in a system-dependent way. This typically involves removing redundant names such as "." and ".." from the pathname, resolving symbolic links (on UNIX platforms), and converting drive letters to a standard case (on Microsoft Windows platforms). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1423047&group_id=12867 |