[Python-checkins] CVS: python/dist/src/Lib ntpath.py,1.39,1.40

Tim Peters tim_one@users.sourceforge.net
Fri, 27 Jul 2001 01:09:56 -0700


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

Modified Files:
	ntpath.py 
Log Message:
One more crack at join():  stop trying to pretend this isn't a mass of
special cases.  test_pkg works again on Windows.


Index: ntpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ntpath.py,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** ntpath.py	2001/07/26 21:54:37	1.39
--- ntpath.py	2001/07/27 08:09:54	1.40
***************
*** 43,62 ****
      path = a
      for b in p:
!         # If path starts with a raw drive letter (e.g. "C:"), and b doesn't
!         # start with a drive letter, path+b is correct, and regardless of\
!         # whether b is absolute on its own.
!         if len(path) >= 2 and path[1] == ":" and splitdrive(b)[0] == "":
!             if path[-1] in "/\\" and b[:1] in "/\\":
!                 b = b[1:]
  
!         # In any other case, if b is absolute it wipes out the path so far.
!         elif isabs(b) or path == "":
!             path = ""
  
!         # Else make sure a separator appears between the pieces.
!         elif path[-1:] not in "/\\":
!             b = "\\" + b
  
!         path += b
  
      return path
--- 43,86 ----
      path = a
      for b in p:
!         b_wins = 0  # set to 1 iff b makes path irrelevant
!         if path == "":
!             b_wins = 1
  
!         elif isabs(b):
!             # This probably wipes out path so far.  However, it's more
!             # complicated if path begins with a drive letter:
!             #     1. join('c:', '/a') == 'c:/a'
!             #     2. join('c:/', '/a') == 'c:/a'
!             # But
!             #     3. join('c:/a', '/b') == '/b'
!             #     4. join('c:', 'd:/') = 'd:/'
!             #     5. join('c:/', 'd:/') = 'd:/'
!             if path[1:2] != ":" or b[1:2] == ":":
!                 # Path doesn't start with a drive letter, or cases 4 and 5.
!                 b_wins = 1
  
!             # Else path has a drive letter, and b doesn't but is absolute.
!             elif len(path) > 3 or (len(path) == 3 and
!                                    path[-1] not in "/\\"):
!                 # case 3
!                 b_wins = 1
  
!         if b_wins:
!             path = b
!         else:
!             # Join, and ensure there's a separator.
!             assert len(path) > 0
!             if path[-1] in "/\\":
!                 if b and b[0] in "/\\":
!                     path += b[1:]
!                 else:
!                     path += b
!             elif path[-1] == ":":
!                 path += b
!             elif b:
!                 if b[0] in "/\\":
!                     path += b
!                 else:
!                     path += "\\" + b
  
      return path