Mercurial > cpython-lru_cache-weakref
annotate Lib/macpath.py @ 8831:00a6bb65ff29 legacy-trunk
Getting rid of this ancient stuff.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 05 Aug 1998 21:10:09 +0000 |
| parents | ca1b906149e6 |
| children | d7979f4ed2b6 |
| 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 | 2 |
|
579
6884346c04a0
Added 'normcase' function.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
3 import string |
|
7525
88992696b9e8
Instead of 'import mac', use 'import os' -- this way, the path syntax
Guido van Rossum <guido@python.org>
parents:
5576
diff
changeset
|
4 import os |
|
579
6884346c04a0
Added 'normcase' function.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
5 from stat import * |
| 103 | 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 | 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 | 18 |
| 19 def isabs(s): | |
| 20 return ':' in s and s[0] <> ':' | |
| 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 | 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 | 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 | 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 | 54 # Split a path in root and extension. |
| 55 # The extension is everything starting at the last dot in the last | |
| 56 # pathname component; the root is everything before that. | |
| 57 # It is always true that root + ext == p. | |
| 58 | |
| 59 def splitext(p): | |
| 60 root, ext = '', '' | |
| 61 for c in p: | |
| 62 if c == ':': | |
| 63 root, ext = root + ext + c, '' | |
| 64 elif c == '.': | |
| 65 if ext: | |
| 66 root, ext = root + ext, c | |
| 67 else: | |
| 68 ext = c | |
| 69 elif ext: | |
| 70 ext = ext + c | |
| 71 else: | |
| 72 root = root + c | |
| 73 return root, ext | |
| 74 | |
| 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 | 94 def isdir(s): |
| 95 try: | |
|
7525
88992696b9e8
Instead of 'import mac', use 'import os' -- this way, the path syntax
Guido van Rossum <guido@python.org>
parents:
5576
diff
changeset
|
96 st = os.stat(s) |
|
88992696b9e8
Instead of 'import mac', use 'import os' -- this way, the path syntax
Guido van Rossum <guido@python.org>
parents:
5576
diff
changeset
|
97 except os.error: |
| 103 | 98 return 0 |
| 99 return S_ISDIR(st[ST_MODE]) | |
| 100 | |
|
105
b4d5fdcbf83c
Added explanatory comments.
Guido van Rossum <guido@python.org>
parents:
103
diff
changeset
|
101 |
|
8746
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
102 # Get size, mtime, atime of files. |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
103 |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
104 def getsize(filename): |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
105 """Return the size of a file, reported by os.stat().""" |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
106 st = os.stat(filename) |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
107 return st[stat.ST_SIZE] |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
108 |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
109 def getmtime(filename): |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
110 """Return the last modification time of a file, reported by os.stat().""" |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
111 st = os.stat(filename) |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
112 return st[stat.ST_MTIME] |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
113 |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
114 def getatime(filename): |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
115 """Return the last access time of a file, reported by os.stat().""" |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
116 st = os.stat(filename) |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
117 return st[stat.ST_MTIME] |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
118 |
|
ca1b906149e6
Added getsize(), getmtime(), getatime()
Guido van Rossum <guido@python.org>
parents:
7525
diff
changeset
|
119 |
| 2260 | 120 # Return true if the pathname refers to a symbolic link. |
| 121 # (Always false on the Mac, until we understand Aliases.) | |
| 122 | |
| 123 def islink(s): | |
| 124 return 0 | |
| 125 | |
| 126 | |
|
105
b4d5fdcbf83c
Added explanatory comments.
Guido van Rossum <guido@python.org>
parents:
103
diff
changeset
|
127 # 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
|
128 |
| 103 | 129 def isfile(s): |
| 130 try: | |
|
7525
88992696b9e8
Instead of 'import mac', use 'import os' -- this way, the path syntax
Guido van Rossum <guido@python.org>
parents:
5576
diff
changeset
|
131 st = os.stat(s) |
|
88992696b9e8
Instead of 'import mac', use 'import os' -- this way, the path syntax
Guido van Rossum <guido@python.org>
parents:
5576
diff
changeset
|
132 except os.error: |
| 103 | 133 return 0 |
| 134 return S_ISREG(st[ST_MODE]) | |
| 135 | |
|
105
b4d5fdcbf83c
Added explanatory comments.
Guido van Rossum <guido@python.org>
parents:
103
diff
changeset
|
136 |
|
b4d5fdcbf83c
Added explanatory comments.
Guido van Rossum <guido@python.org>
parents:
103
diff
changeset
|
137 # 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
|
138 |
| 103 | 139 def exists(s): |
| 140 try: | |
|
7525
88992696b9e8
Instead of 'import mac', use 'import os' -- this way, the path syntax
Guido van Rossum <guido@python.org>
parents:
5576
diff
changeset
|
141 st = os.stat(s) |
|
88992696b9e8
Instead of 'import mac', use 'import os' -- this way, the path syntax
Guido van Rossum <guido@python.org>
parents:
5576
diff
changeset
|
142 except os.error: |
| 103 | 143 return 0 |
| 144 return 1 | |
|
1086
db817f3a1c65
* change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents:
770
diff
changeset
|
145 |
|
3299
47763ac44c48
Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents:
2947
diff
changeset
|
146 # |
|
47763ac44c48
Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents:
2947
diff
changeset
|
147 # 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
|
148 # operating systems. |
|
47763ac44c48
Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents:
2947
diff
changeset
|
149 def expandvars(path): |
|
47763ac44c48
Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents:
2947
diff
changeset
|
150 return path |
|
47763ac44c48
Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents:
2947
diff
changeset
|
151 |
|
47763ac44c48
Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents:
2947
diff
changeset
|
152 # |
|
47763ac44c48
Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents:
2947
diff
changeset
|
153 # 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
|
154 # operating systems. |
|
47763ac44c48
Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents:
2947
diff
changeset
|
155 def expanduser(path): |
|
47763ac44c48
Added (dummy) expanduser and expandvar methods
Jack Jansen <jack.jansen@cwi.nl>
parents:
2947
diff
changeset
|
156 return path |
|
1086
db817f3a1c65
* change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents:
770
diff
changeset
|
157 |
|
2947
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
158 # 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
|
159 # e.g., 'foo:bar::bletch' becomes 'foo:bletch'. |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
160 # 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
|
161 # e.g., for '::foo'. |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
162 # 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
|
163 # returns an unnormalized path. Should do so here too. |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
164 |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
165 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
|
166 |
|
db817f3a1c65
* change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents:
770
diff
changeset
|
167 def normpath(s): |
|
2947
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
168 import string |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
169 if ':' not in s: |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
170 return ':' + s |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
171 f = string.splitfields(s, ':') |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
172 pre = [] |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
173 post = [] |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
174 if not f[0]: |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
175 pre = f[:1] |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
176 f = f[1:] |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
177 if not f[len(f)-1]: |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
178 post = f[-1:] |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
179 f = f[:-1] |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
180 res = [] |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
181 for seg in f: |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
182 if seg: |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
183 res.append(seg) |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
184 else: |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
185 if not res: raise norm_error, 'path starts with ::' |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
186 del res[len(res)-1] |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
187 if not (pre or res): |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
188 raise norm_error, 'path starts with volume::' |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
189 if pre: res = pre + res |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
190 if post: res = res + post |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
191 s = res[0] |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
192 for seg in res[1:]: |
|
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
193 s = s + ':' + seg |
|
1086
db817f3a1c65
* change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents:
770
diff
changeset
|
194 return s |
|
2910
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
195 |
|
2947
a980d076052d
added normpath() and splitdrive()
Guido van Rossum <guido@python.org>
parents:
2910
diff
changeset
|
196 |
|
2910
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
197 # Directory tree walk. |
|
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
198 # For each directory under top (including top itself), |
|
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
199 # func(arg, dirname, filenames) is called, where |
|
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
200 # 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
|
201 # of files (and subdirectories etc.) in the directory. |
|
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
202 # 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
|
203 # or to impose a different order of visiting. |
|
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
204 |
|
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
205 def walk(top, func, arg): |
|
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
206 try: |
|
7525
88992696b9e8
Instead of 'import mac', use 'import os' -- this way, the path syntax
Guido van Rossum <guido@python.org>
parents:
5576
diff
changeset
|
207 names = os.listdir(top) |
|
88992696b9e8
Instead of 'import mac', use 'import os' -- this way, the path syntax
Guido van Rossum <guido@python.org>
parents:
5576
diff
changeset
|
208 except os.error: |
|
2910
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
209 return |
|
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
210 func(arg, top, names) |
|
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
211 for name in names: |
|
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
212 name = join(top, name) |
|
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
213 if isdir(name): |
|
5a2612fb6c0e
Added missing walk() function
Jack Jansen <jack.jansen@cwi.nl>
parents:
2260
diff
changeset
|
214 walk(name, func, arg) |
