[Python-Dev] Add os.path.resolve to simplify the use of os.readlink

2012-06-21 Thread Armin Ronacher
Due to an user error on my part I was not using os.readlink correctly. Since links can be relative to their location I think it would make sense to provide an os.path.resolve helper that automatically returns the absolute path: def resolve(filename): try: target =

Re: [Python-Dev] Add os.path.resolve to simplify the use of os.readlink

2012-06-21 Thread Christian Heimes
Am 21.06.2012 12:23, schrieb Armin Ronacher: Due to an user error on my part I was not using os.readlink correctly. Since links can be relative to their location I think it would make sense to provide an os.path.resolve helper that automatically returns the absolute path: def

Re: [Python-Dev] Add os.path.resolve to simplify the use of os.readlink

2012-06-21 Thread Armin Ronacher
Hi, Am 21.06.2012 12:23, schrieb Armin Ronacher: Does the code handle a chain of absolute and relative symlinks correctly, for example a relative symlink that points to another relative symlink in a different directory that points to a file in a third directry? No, but that's a good point.

Re: [Python-Dev] Add os.path.resolve to simplify the use of os.readlink

2012-06-21 Thread Antoine Pitrou
On Thu, 21 Jun 2012 11:10:44 - Armin Ronacher armin.ronac...@active-4.com wrote: Hi, Am 21.06.2012 12:23, schrieb Armin Ronacher: Does the code handle a chain of absolute and relative symlinks correctly, for example a relative symlink that points to another relative symlink in a

Re: [Python-Dev] Add os.path.resolve to simplify the use of os.readlink

2012-06-21 Thread Christian Heimes
Am 21.06.2012 13:10, schrieb Armin Ronacher: Hello Armin, No, but that's a good point. It should attempt to resolve these in a loop until it either loops too often (would have to check the POSIX spec for a reasonable value) or until it terminates by finding an actual file or directory. The

Re: [Python-Dev] Add os.path.resolve to simplify the use of os.readlink

2012-06-21 Thread Oleg Broytman
On Thu, Jun 21, 2012 at 11:10:44AM -, Armin Ronacher armin.ronac...@active-4.com wrote: would have to check the POSIX spec for a reasonable value POSIX allows 8 links: http://infohost.nmt.edu/~eweiss/222_book/222_book/0201433079/ch02lev1sec5.html _POSIX_SYMLOOP_MAX - number of

Re: [Python-Dev] Add os.path.resolve to simplify the use of os.readlink

2012-06-21 Thread Nick Coghlan
On Thu, Jun 21, 2012 at 9:26 PM, Christian Heimes li...@cheimes.de wrote: BTW Is there a better way than raise OSError(errno.ELOOP, os.strerror(errno.ELOOP), filename) to raise a correct OSError with errno, errno message and filename? A classmethod like OSError.from_errno(errno, filename=None)

Re: [Python-Dev] Add os.path.resolve to simplify the use of os.readlink

2012-06-21 Thread Antoine Pitrou
On Thu, 21 Jun 2012 15:04:17 +0200 Christian Heimes li...@cheimes.de wrote: How about adding keyword support to OSError and derive the strerror from errno if the second argument is not given? That's not the original behaviour: Python 3.2.2+ (3.2:9ef20fbd340f, Oct 15 2011, 21:22:07) [GCC

Re: [Python-Dev] Add os.path.resolve to simplify the use of os.readlink

2012-06-21 Thread Nick Coghlan
On Thu, Jun 21, 2012 at 11:16 PM, Antoine Pitrou solip...@pitrou.net wrote: On Thu, 21 Jun 2012 15:04:17 +0200 Christian Heimes li...@cheimes.de wrote: How about adding keyword support to OSError and derive the strerror from errno if the second argument is not given? That's not the original

Re: [Python-Dev] Add os.path.resolve to simplify the use of os.readlink

2012-06-21 Thread Phil Vandry
On 2012-06-21 06:23, Armin Ronacher wrote: Due to an user error on my part I was not using os.readlink correctly. Since links can be relative to their location I think it would make sense to provide an os.path.resolve helper that automatically returns the absolute path: def

Re: [Python-Dev] Add os.path.resolve to simplify the use of os.readlink

2012-06-21 Thread Antoine Pitrou
On Thu, 21 Jun 2012 10:23:25 - Armin Ronacher armin.ronac...@active-4.com wrote: Due to an user error on my part I was not using os.readlink correctly. Since links can be relative to their location I think it would make sense to provide an os.path.resolve helper that automatically returns