[Python-checkins] python/dist/src/Lib macpath.py,1.35,1.36

jackjansen@sourceforge.net jackjansen@sourceforge.net
Mon, 22 Apr 2002 06:55:48 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv29352

Modified Files:
	macpath.py 
Log Message:
Fixes based on ideas from Christopher Smith:
- islink() now returns true for alias files
- walk() no longer follows aliases while traversing
- realpath() implemented, returning an alias-free pathname.

As this could conceivably break existing code I think it isn't a bugfix candidate.

Index: macpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/macpath.py,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** macpath.py	7 Apr 2002 06:36:23 -0000	1.35
--- macpath.py	22 Apr 2002 13:55:43 -0000	1.36
***************
*** 123,130 ****
  
  def islink(s):
!     """Return true if the pathname refers to a symbolic link.
!     Always false on the Mac, until we understand Aliases.)"""
  
!     return False
  
  
--- 123,133 ----
  
  def islink(s):
!     """Return true if the pathname refers to a symbolic link."""
  
!     try:
!     	import macfs
!         return macfs.ResolveAliasFile(s)[2]
!     except:
!         return False
  
  
***************
*** 224,228 ****
      for name in names:
          name = join(top, name)
!         if isdir(name):
              walk(name, func, arg)
  
--- 227,231 ----
      for name in names:
          name = join(top, name)
!         if isdir(name) and not islink(name):
              walk(name, func, arg)
  
***************
*** 235,237 ****
  
  # realpath is a no-op on systems without islink support
! realpath = abspath
--- 238,253 ----
  
  # realpath is a no-op on systems without islink support
! def realpath(path):
! 	path = abspath(path)
! 	try:
! 		import macfs
! 	except ImportError:
! 		return path
! 	if not path:
! 		return path
! 	components = path.split(':')
! 	path = components[0] + ':'
! 	for c in components[1:]:
! 		path = join(path, c)
! 		path = macfs.ResolveAliasFile(path)[0].as_pathname()
! 	return path