Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(59237)

Side by Side Diff: Lib/macpath.py

Issue 4755: Common path prefix
Patch Set: Created 10 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 """Pathname and path-related operations for the Macintosh.""" 1 """Pathname and path-related operations for the Macintosh."""
2 2
3 import os 3 import os
4 from stat import * 4 from stat import *
5 import genericpath 5 import genericpath
6 from genericpath import * 6 from genericpath import *
7 7
8 __all__ = ["normcase","isabs","join","splitdrive","split","splitext", 8 __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
9 "basename","dirname","commonprefix","getsize","getmtime", 9 "basename","dirname","commonprefix","getsize","getmtime",
10 "getatime","getctime", "islink","exists","lexists","isdir","isfile", 10 "getatime","getctime", "islink","exists","lexists","isdir","isfile",
(...skipping 15 matching lines...) Expand all
26 def _get_colon(path): 26 def _get_colon(path):
27 if isinstance(path, bytes): 27 if isinstance(path, bytes):
28 return b':' 28 return b':'
29 else: 29 else:
30 return ':' 30 return ':'
31 31
32 # Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here. 32 # Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here.
33 33
34 def normcase(path): 34 def normcase(path):
35 return path.lower() 35 return path.lower()
36
37 36
38 def isabs(s): 37 def isabs(s):
39 """Return true if a path is absolute. 38 """Return true if a path is absolute.
40 On the Mac, relative paths begin with a colon, 39 On the Mac, relative paths begin with a colon,
41 but as a special case, paths with no colons at all are also relative. 40 but as a special case, paths with no colons at all are also relative.
42 Anything else is absolute (the string up to the first colon is the 41 Anything else is absolute (the string up to the first colon is the
43 volume name).""" 42 volume name)."""
44 43
45 colon = _get_colon(s) 44 colon = _get_colon(s)
46 return colon in s and s[:1] != colon 45 return colon in s and s[:1] != colon
47 46
47 def commonpathprefix(m, separator=None):
48 """Given a list of pathnames, returns the longest common leading component.
49
50 Unlike commonprefix(), commonpathprefix() considers path elements as
51 delimited by the defined separator (default: os.sep).
52 """
53 if separator is None:
54 separator = sep
55 return genericpath.commonpathprefix(m, separator)
48 56
49 def join(s, *p): 57 def join(s, *p):
50 colon = _get_colon(s) 58 colon = _get_colon(s)
51 path = s 59 path = s
52 for t in p: 60 for t in p:
53 if (not s) or isabs(t): 61 if (not s) or isabs(t):
54 path = t 62 path = t
55 continue 63 continue
56 if t[:1] == colon: 64 if t[:1] == colon:
57 t = t[1:] 65 t = t[1:]
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 return path 194 return path
187 colon = _get_colon(path) 195 colon = _get_colon(path)
188 components = path.split(colon) 196 components = path.split(colon)
189 path = components[0] + colon 197 path = components[0] + colon
190 for c in components[1:]: 198 for c in components[1:]:
191 path = join(path, c) 199 path = join(path, c)
192 path = Carbon.File.FSResolveAliasFile(path, 1)[0].as_pathname() 200 path = Carbon.File.FSResolveAliasFile(path, 1)[0].as_pathname()
193 return path 201 return path
194 202
195 supports_unicode_filenames = False 203 supports_unicode_filenames = False
OLDNEW
« Doc/library/os.path.rst ('K') | « Lib/genericpath.py ('k') | Lib/ntpath.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+