[Python-checkins] python/dist/src/Lib/plat-riscos riscospath.py, 1.8.6.2, 1.8.6.3

jhylton@users.sourceforge.net jhylton at users.sourceforge.net
Sun Oct 16 07:24:33 CEST 2005


Update of /cvsroot/python/python/dist/src/Lib/plat-riscos
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27718/Lib/plat-riscos

Modified Files:
      Tag: ast-branch
	riscospath.py 
Log Message:
Merge head to branch (for the last time)


Index: riscospath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-riscos/riscospath.py,v
retrieving revision 1.8.6.2
retrieving revision 1.8.6.3
diff -u -d -r1.8.6.2 -r1.8.6.3
--- riscospath.py	7 Jan 2005 06:58:45 -0000	1.8.6.2
+++ riscospath.py	16 Oct 2005 05:24:00 -0000	1.8.6.3
@@ -168,23 +168,16 @@
     return split(p)[0]
 
 
-def commonprefix(ps):
-    """
-  Return the longest prefix of all list elements. Purely string-based; does not
-  separate any path parts. Why am I in os.path?
-  """
-    if len(ps)==0:
-        return ''
-    prefix= ps[0]
-    for p in ps[1:]:
-        prefix= prefix[:len(p)]
-        for i in range(len(prefix)):
-            if prefix[i] <> p[i]:
-                prefix= prefix[:i]
-                if i==0:
-                    return ''
-                break
-    return prefix
+def commonprefix(m):
+    "Given a list of pathnames, returns the longest common leading component"
+    if not m: return ''
+    s1 = min(m)
+    s2 = max(m)
+    n = min(len(s1), len(s2))
+    for i in xrange(n):
+        if s1[i] != s2[i]:
+            return s1[:i]
+    return s1[:n]
 
 
 ## File access functions. Why are we in os.path?



More information about the Python-checkins mailing list