annotate Lib/macpath.py @ 6719:faebc1940432 legacy-trunk

Understand -Xlinker option.
author Guido van Rossum <guido@python.org>
date Tue, 02 Dec 1997 20:38:11 +0000
parents c7d812e4af0d
children 88992696b9e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
105
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
1 # module 'macpath' -- pathname (or -related) operations for the Macintosh
103
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
579
6884346c04a0 Added 'normcase' function.
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
3 import string
103
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 import mac
579
6884346c04a0 Added 'normcase' function.
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
5 from stat import *
103
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
579
6884346c04a0 Added 'normcase' function.
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
7
6884346c04a0 Added 'normcase' function.
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
8 # Normalize the case of a pathname. Dummy in Posix, but string.lower here.
6884346c04a0 Added 'normcase' function.
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
9
6884346c04a0 Added 'normcase' function.
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
10 normcase = string.lower
105
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
11
103
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
105
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
13 # Return true if a path is absolute.
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
14 # On the Mac, relative paths begin with a colon,
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
15 # but as a special case, paths with no colons at all are also relative.
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
16 # Anything else is absolute (the string up to the first colon is the
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
17 # volume name).
103
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 def isabs(s):
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 return ':' in s and s[0] <> ':'
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
21
105
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
22
5133
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
23 def join(s, *p):
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
24 path = s
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
25 for t in p:
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
26 if (not s) or isabs(t):
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
27 path = t
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
28 continue
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
29 if t[:1] == ':':
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
30 t = t[1:]
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
31 if ':' not in path:
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
32 path = ':' + path
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
33 if path[-1:] <> ':':
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
34 path = path + ':'
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
35 path = path + t
666152b77027 join(): join one or more path components
Barry Warsaw <barry@python.org>
parents: 3793
diff changeset
36 return path
103
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
105
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
38
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
39 # Split a pathname in two parts: the directory leading up to the final bit,
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
40 # and the basename (the filename, without colons, in that directory).
360
3b33ac44e36e macpath.cat --> join
Guido van Rossum <guido@python.org>
parents: 105
diff changeset
41 # The result (s, t) is such that join(s, t) yields the original argument.
105
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
42
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
43 def split(s):
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
44 if ':' not in s: return '', s
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
45 colon = 0
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
46 for i in range(len(s)):
559
683edb0c4463 New == syntax
Guido van Rossum <guido@python.org>
parents: 360
diff changeset
47 if s[i] == ':': colon = i+1
5576
c7d812e4af0d Fix for boundary case (Jack)
Guido van Rossum <guido@python.org>
parents: 5136
diff changeset
48 path, file = s[:colon-1], s[colon:]
c7d812e4af0d Fix for boundary case (Jack)
Guido van Rossum <guido@python.org>
parents: 5136
diff changeset
49 if path and not ':' in path:
c7d812e4af0d Fix for boundary case (Jack)
Guido van Rossum <guido@python.org>
parents: 5136
diff changeset
50 path = path + ':'
c7d812e4af0d Fix for boundary case (Jack)
Guido van Rossum <guido@python.org>
parents: 5136
diff changeset
51 return path, file
105
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
52
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
53
3793
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
54 # Split a path in root and extension.
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
55 # The extension is everything starting at the last dot in the last
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
56 # pathname component; the root is everything before that.
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
57 # It is always true that root + ext == p.
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
58
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
59 def splitext(p):
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
60 root, ext = '', ''
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
61 for c in p:
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
62 if c == ':':
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
63 root, ext = root + ext + c, ''
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
64 elif c == '.':
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
65 if ext:
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
66 root, ext = root + ext, c
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
67 else:
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
68 ext = c
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
69 elif ext:
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
70 ext = ext + c
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
71 else:
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
72 root = root + c
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
73 return root, ext
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
74
ca02d9278180 Added splitext()
Guido van Rossum <guido@python.org>
parents: 3299
diff changeset
75
2947
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
76 # Split a pathname into a drive specification and the rest of the
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
77 # path. Useful on DOS/Windows/NT; on the Mac, the drive is always
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
78 # empty (don't use the volume name -- it doesn't have the same
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
79 # syntactic and semantic oddities as DOS drive letters, such as there
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
80 # being a separate current directory per drive).
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
81
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
82 def splitdrive(p):
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
83 return '', p
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
84
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
85
1086
db817f3a1c65 * change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents: 770
diff changeset
86 # Short interfaces to split()
db817f3a1c65 * change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents: 770
diff changeset
87
db817f3a1c65 * change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents: 770
diff changeset
88 def dirname(s): return split(s)[0]
db817f3a1c65 * change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents: 770
diff changeset
89 def basename(s): return split(s)[1]
db817f3a1c65 * change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents: 770
diff changeset
90
db817f3a1c65 * change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents: 770
diff changeset
91
105
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
92 # Return true if the pathname refers to an existing directory.
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
93
103
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 def isdir(s):
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 try:
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 st = mac.stat(s)
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 except mac.error:
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 return 0
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 return S_ISDIR(st[ST_MODE])
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
100
105
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
101
2260
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents: 1810
diff changeset
102 # Return true if the pathname refers to a symbolic link.
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents: 1810
diff changeset
103 # (Always false on the Mac, until we understand Aliases.)
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents: 1810
diff changeset
104
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents: 1810
diff changeset
105 def islink(s):
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents: 1810
diff changeset
106 return 0
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents: 1810
diff changeset
107
a81b6db6d33c changes for the Mac
Guido van Rossum <guido@python.org>
parents: 1810
diff changeset
108
105
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
109 # Return true if the pathname refers to an existing regular file.
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
110
103
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 def isfile(s):
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 try:
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 st = mac.stat(s)
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 except mac.error:
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 return 0
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 return S_ISREG(st[ST_MODE])
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
117
105
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
118
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
119 # Return true if the pathname refers to an existing file or directory.
b4d5fdcbf83c Added explanatory comments.
Guido van Rossum <guido@python.org>
parents: 103
diff changeset
120
103
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 def exists(s):
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 try:
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 st = mac.stat(s)
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 except mac.error:
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 return 0
1229ba124e0b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 return 1
1086
db817f3a1c65 * change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents: 770
diff changeset
127
3299
47763ac44c48 Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents: 2947
diff changeset
128 #
47763ac44c48 Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents: 2947
diff changeset
129 # dummy expandvars to retain interface-compatability with other
47763ac44c48 Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents: 2947
diff changeset
130 # operating systems.
47763ac44c48 Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents: 2947
diff changeset
131 def expandvars(path):
47763ac44c48 Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents: 2947
diff changeset
132 return path
47763ac44c48 Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents: 2947
diff changeset
133
47763ac44c48 Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents: 2947
diff changeset
134 #
47763ac44c48 Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents: 2947
diff changeset
135 # dummy expanduser to retain interface-compatability with other
47763ac44c48 Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents: 2947
diff changeset
136 # operating systems.
47763ac44c48 Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents: 2947
diff changeset
137 def expanduser(path):
47763ac44c48 Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents: 2947
diff changeset
138 return path
1086
db817f3a1c65 * change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents: 770
diff changeset
139
2947
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
140 # Normalize a pathname: get rid of '::' sequences by backing up,
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
141 # e.g., 'foo:bar::bletch' becomes 'foo:bletch'.
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
142 # Raise the exception norm_error below if backing up is impossible,
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
143 # e.g., for '::foo'.
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
144 # XXX The Unix version doesn't raise an exception but simply
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
145 # returns an unnormalized path. Should do so here too.
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
146
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
147 norm_error = 'macpath.norm_error: path cannot be normalized'
1086
db817f3a1c65 * change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents: 770
diff changeset
148
db817f3a1c65 * change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents: 770
diff changeset
149 def normpath(s):
2947
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
150 import string
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
151 if ':' not in s:
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
152 return ':' + s
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
153 f = string.splitfields(s, ':')
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
154 pre = []
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
155 post = []
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
156 if not f[0]:
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
157 pre = f[:1]
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
158 f = f[1:]
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
159 if not f[len(f)-1]:
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
160 post = f[-1:]
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
161 f = f[:-1]
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
162 res = []
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
163 for seg in f:
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
164 if seg:
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
165 res.append(seg)
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
166 else:
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
167 if not res: raise norm_error, 'path starts with ::'
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
168 del res[len(res)-1]
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
169 if not (pre or res):
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
170 raise norm_error, 'path starts with volume::'
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
171 if pre: res = pre + res
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
172 if post: res = res + post
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
173 s = res[0]
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
174 for seg in res[1:]:
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
175 s = s + ':' + seg
1086
db817f3a1c65 * change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents: 770
diff changeset
176 return s
2910
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
177
2947
a980d076052d added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents: 2910
diff changeset
178
2910
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
179 # Directory tree walk.
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
180 # For each directory under top (including top itself),
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
181 # func(arg, dirname, filenames) is called, where
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
182 # dirname is the name of the directory and filenames is the list
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
183 # of files (and subdirectories etc.) in the directory.
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
184 # The func may modify the filenames list, to implement a filter,
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
185 # or to impose a different order of visiting.
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
186
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
187 def walk(top, func, arg):
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
188 try:
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
189 names = mac.listdir(top)
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
190 except mac.error:
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
191 return
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
192 func(arg, top, names)
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
193 for name in names:
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
194 name = join(top, name)
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
195 if isdir(name):
5a2612fb6c0e Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents: 2260
diff changeset
196 walk(name, func, arg)