[Python-3000] Mini Path object
Nick Coghlan
ncoghlan at gmail.com
Wed Nov 8 11:07:10 CET 2006
Mike Orr wrote:
>> And again, it strays outside the domain of path algebra
>> operations.
>
> This is also the same issue. Where do we put the .expand*() methods
> if not on Path?
For the moment, I'd say that if an operation can raise any flavour of
EnvironmentError, don't make it a method of the path algebra.
I realise this means normalisation and symbol expansion will be defined only
on FSPath's. I'd say that's OK because at least the syntax for environment
variable substitution is OS dependent anyway (note that these methods should
return the appropriate FSPath objects, rather than the abstract versions).
> Is there an actual case where calling normpath() would change which
> file the path referred to? Any case that's not handled by
> (posix|nt|mac)path.normpath itself?
>
To quote the docs for os.normpath itself:
"It should be understood that this may change the meaning of the path if it
contains symbolic links!"
Specifically, using path algebra to normalise a path that backtracks after
following a symlink will actually give a different answer than asking the
filesystem to do it.
To steal an explanation from the effbot [1]:
"""
if BAR is a symbolic link, FOO/BAR/../DIR isn't necessarily the same
thing as FOO/DIR.
a simple example:
$ ln -s /etc etc
$ ls -ld etc
lrwxrwxrwx 1 fredrik fredrik 4 Dec 2 23:22 etc -> /etc
$ etc/../usr/local/bin/python2.4
Python 2.4.1 (#1, Sep 12 2005, 19:35:02)
...
>>> import os
>>> os.path.normpath("etc/../usr/local/bin/python2.4")
'usr/local/bin/python2.4'
>>> <control-D>
$ usr/local/bin/python2.4
-bash: usr/local/bin/python2.4: No such file or directory
"""
Cheers,
Nick.
[1]
http://mail.python.org/pipermail/python-dev/2005-December/058453.html
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list