Re: [Python-Dev] cpython (2.7): Fix posixpath.realpath() for multiple pardirs (fixes issue #6975).

2013-02-18 Thread Antoine Pitrou
On Mon, 18 Feb 2013 11:24:40 +0100 (CET)
serhiy.storchaka python-check...@python.org wrote:
  
 +def test_realpath_curdir(self):
 +self.assertEqual(realpath('.'), os.getcwd())
 +self.assertEqual(realpath('./.'), os.getcwd())
 +self.assertEqual(realpath('/'.join(['.'] * 100)), os.getcwd())
 +
 +def test_realpath_pardir(self):
 +self.assertEqual(realpath('..'), dirname(os.getcwd()))
 +self.assertEqual(realpath('../..'), dirname(dirname(os.getcwd(
 +self.assertEqual(realpath('/'.join(['..'] * 100)), '/')

What if there's a symlink along os.getcwd()?

Regards

Antoine.


___
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] cpython (2.7): Fix posixpath.realpath() for multiple pardirs (fixes issue #6975).

2013-02-18 Thread Serhiy Storchaka

On 18.02.13 19:26, Antoine Pitrou wrote:

On Mon, 18 Feb 2013 11:24:40 +0100 (CET)
serhiy.storchaka python-check...@python.org wrote:


+def test_realpath_curdir(self):
+self.assertEqual(realpath('.'), os.getcwd())
+self.assertEqual(realpath('./.'), os.getcwd())
+self.assertEqual(realpath('/'.join(['.'] * 100)), os.getcwd())
+
+def test_realpath_pardir(self):
+self.assertEqual(realpath('..'), dirname(os.getcwd()))
+self.assertEqual(realpath('../..'), dirname(dirname(os.getcwd(
+self.assertEqual(realpath('/'.join(['..'] * 100)), '/')


What if there's a symlink along os.getcwd()?


1. AFAIK, os.getcwd() returns the path with resolved symlinks.
2. realpath() first resolve relative path and then prepends cwd to the 
result.



___
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] cpython (2.7): Fix posixpath.realpath() for multiple pardirs (fixes issue #6975).

2013-02-18 Thread Antoine Pitrou
On Mon, 18 Feb 2013 19:56:07 +0200
Serhiy Storchaka storch...@gmail.com wrote:
 On 18.02.13 19:26, Antoine Pitrou wrote:
  On Mon, 18 Feb 2013 11:24:40 +0100 (CET)
  serhiy.storchaka python-check...@python.org wrote:
 
  +def test_realpath_curdir(self):
  +self.assertEqual(realpath('.'), os.getcwd())
  +self.assertEqual(realpath('./.'), os.getcwd())
  +self.assertEqual(realpath('/'.join(['.'] * 100)), os.getcwd())
  +
  +def test_realpath_pardir(self):
  +self.assertEqual(realpath('..'), dirname(os.getcwd()))
  +self.assertEqual(realpath('../..'), dirname(dirname(os.getcwd(
  +self.assertEqual(realpath('/'.join(['..'] * 100)), '/')
 
  What if there's a symlink along os.getcwd()?
 
 1. AFAIK, os.getcwd() returns the path with resolved symlinks.

Indeed, it seems you are right (under POSIX at least):

“The getcwd() function shall place an absolute pathname of the current
working directory in the array pointed to by buf, and return buf. The
pathname shall contain no components that are dot or dot-dot, or are
symbolic links.”

http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html

Regards

Antoine.


___
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