[Python-checkins] CVS: python/dist/src/Lib dospath.py,1.13,1.14 macpath.py,1.22,1.23 ntpath.py,1.24,1.25 posixpath.py,1.31,1.32
Skip Montanaro
python-dev@python.org
2000年7月12日 09:56:00 -0700
- Previous message: [Python-checkins] CVS: python/dist/src/Modules _sre.c,2.25,2.26 _tkinter.c,1.105,1.106 almodule.c,1.28,1.29 cPickle.c,2.44,2.45 cStringIO.c,2.21,2.22 parsermodule.c,2.45,2.46 posixmodule.c,2.150,2.151 stropmodule.c,2.67,2.68
- Next message: [Python-checkins] CVS: python/dist/src/Include mymalloc.h,2.22,2.23 mymath.h,2.10,2.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv9633/Lib
Modified Files:
dospath.py macpath.py ntpath.py posixpath.py
Log Message:
fixed semantics of commonprefix to work by path elements instead of
characters.
Index: dospath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/dospath.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** dospath.py 2000年07月01日 10:52:49 1.13
--- dospath.py 2000年07月12日 16:55:57 1.14
***************
*** 103,112 ****
! def commonprefix(m):
! """Return the longest prefix of all list elements."""
if not m: return ''
! prefix = m[0]
! for item in m:
for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]:
--- 103,120 ----
! # Return the longest prefix of all list elements.
+ def commonprefix(m):
+ "Given a list of pathnames, returns the longest common leading component"
if not m: return ''
! n = m[:]
! for i in range(len(n)):
! n[i] = n[i].split(os.sep)
! # if os.sep didn't have any effect, try os.altsep
! if os.altsep and len(n[i]) == 1:
! n[i] = n[i].split(os.altsep)
!
! prefix = n[0]
! for item in n:
for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]:
***************
*** 114,118 ****
if i == 0: return ''
break
! return prefix
--- 122,126 ----
if i == 0: return ''
break
! return os.sep.join(prefix)
Index: macpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/macpath.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** macpath.py 2000年07月01日 10:52:26 1.22
--- macpath.py 2000年07月12日 16:55:57 1.23
***************
*** 90,93 ****
--- 90,116 ----
+ # Return the longest prefix of all list elements.
+ # XXX completely untested on Mac!!!
+
+ def commonprefix(m):
+ "Given a list of pathnames, returns the longest common leading component"
+ if not m: return ''
+ n = m[:]
+ for i in range(len(n)):
+ n[i] = n[i].split(os.sep)
+ # if os.sep didn't have any effect, try os.altsep
+ if os.altsep and len(n[i]) == 1:
+ n[i] = n[i].split(os.altsep)
+
+ prefix = n[0]
+ for item in n:
+ for i in range(len(prefix)):
+ if prefix[:i+1] <> item[:i+1]:
+ prefix = prefix[:i]
+ if i == 0: return ''
+ break
+ return os.sep.join(prefix)
+
+
def isdir(s):
"""Return true if the pathname refers to an existing directory."""
Index: ntpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ntpath.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -r1.24 -r1.25
*** ntpath.py 2000年07月01日 06:36:51 1.24
--- ntpath.py 2000年07月12日 16:55:57 1.25
***************
*** 9,14 ****
import stat
import string
-
# Normalize the case of a pathname and map slashes to backslashes.
# Other normalizations (such as optimizing '../' away) are not done
--- 9,14 ----
import stat
import string
+ import copy
# Normalize the case of a pathname and map slashes to backslashes.
# Other normalizations (such as optimizing '../' away) are not done
***************
*** 159,164 ****
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
! prefix = m[0]
! for item in m:
for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]:
--- 159,167 ----
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
! n = copy.copy(m)
! for i in range(len(n)):
! n[i] = n[i].split(os.sep)
! prefix = n[0]
! for item in n:
for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]:
***************
*** 166,170 ****
if i == 0: return ''
break
! return prefix
--- 169,173 ----
if i == 0: return ''
break
! return os.sep.join(prefix)
Index: posixpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/posixpath.py,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -r1.31 -r1.32
*** posixpath.py 2000年06月28日 14:48:01 1.31
--- posixpath.py 2000年07月12日 16:55:57 1.32
***************
*** 119,124 ****
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
! prefix = m[0]
! for item in m:
for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]:
--- 119,131 ----
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
! n = m[:]
! for i in range(len(n)):
! n[i] = n[i].split(os.sep)
! # if os.sep didn't have any effect, try os.altsep
! if os.altsep and len(n[i]) == 1:
! n[i] = n[i].split(os.altsep)
!
! prefix = n[0]
! for item in n:
for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]:
***************
*** 126,130 ****
if i == 0: return ''
break
! return prefix
--- 133,137 ----
if i == 0: return ''
break
! return os.sep.join(prefix)
- Previous message: [Python-checkins] CVS: python/dist/src/Modules _sre.c,2.25,2.26 _tkinter.c,1.105,1.106 almodule.c,1.28,1.29 cPickle.c,2.44,2.45 cStringIO.c,2.21,2.22 parsermodule.c,2.45,2.46 posixmodule.c,2.150,2.151 stropmodule.c,2.67,2.68
- Next message: [Python-checkins] CVS: python/dist/src/Include mymalloc.h,2.22,2.23 mymath.h,2.10,2.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]