Re: [Python-Dev] os.path.diff(path1, path2)
Hi, > This function would take two paths: A and B and give > the relation between them. Here are a few of examples. > > os.path.diff("/A/C/D/", "/A/D/F/") > ==> "../../D/F" > > os.path.diff("/A/", "/A/B/C/") > ==> "B/C" > > os.path.diff("/A/B/C/", "/A/") > ==> "../.." I'm not sure whether something like this is generally non-trivial. Suppose you have the following directory structure: /home -> usr/home /usr /usr/home What does os.path.diff("/home/", "/usr/") yield? "../usr/", I would presume? But that's obviously wrong: >>> import os >>> os.stat("/home/../usr") Traceback (most recent call last): File "", line 1, in ? OSError: [Errno 2] No such file or directory: '/home/../usr' I've not thought about this long enough to say if there's a trivial solution to this, though :) Bye, Matthias A. Benkard Matthias Andreas Benkard, Anarchokommunist und Pythonprogrammierer Persönliche Website: http://www.mulk.de.vu/ Persönlicher Weblog: http://www.kompottkin.de.vu/ Flames bitte nach /dev/null schicken. signature.asc Description: This is a digitally signed message part ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] os.path.diff(path1, path2)
Hi, > /home -> usr/home Sorry, I forgot to mention what I meant by this: /home is a symlink pointing to usr/home (that is, /usr/home). Bye, Matthias ____ Matthias Andreas Benkard, Anarchokommunist und Pythonprogrammierer Persönliche Website: http://www.mulk.de.vu/ Persönlicher Weblog: http://www.kompottkin.de.vu/ Flames bitte nach /dev/null schicken. signature.asc Description: This is a digitally signed message part ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] os.path.diff(path1, path2)
Hi, > IMO, the relpath method should just work textually on > the pathnames. It's up to the user to ensure it makes > sense to do so, e.g. by resolving symlinks beforehand > if necessary. I guess so. Don't forget to mention this quirk in the docs, though :) > The alternative would be for relpath to do this itself, > but that would make it very unusual compared to the > other path-munging functions, none of which touch the file > system. Yes, and this behaviour would make it unusable for virtual file systems within the application, too. Path names needn't refer to the local file system, right? Then again, the `os' module _is_ platform-specific, as is `os.path', so one shouldn't use it for those things either way. In fact, relpath _cannot_ dereference symlinks on its own, as it has no way of knowing the absolute pathname if only relative pathnames are given as arguments (for example, relpath("a/b/c", "../d")). But this begs the question: What is relpath good for, anyway? And what are the hidden costs? One-time scripts might benefit from it, but having this function in the standard library could make application developers use it without considering the consequences, resulting in strange bugs that occur on one machine, but not on another. The more I think about it, the more I'm afraid that this might lead to severe security vulnerabilities if misused in tools run by the system administrator. Better place a big, fat warning in the docs, then. Bye, Matthias ________ Matthias Andreas Benkard, Anarchokommunist und Pythonprogrammierer Persönliche Website: http://www.mulk.de.vu/ Persönlicher Weblog: http://www.kompottkin.de.vu/ Flames bitte nach /dev/null schicken. signature.asc Description: This is a digitally signed message part ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com