1 """Macintosh-specific module for conversion between pathnames and URLs.
3 Do not import directly; use urllib instead."""
8 __all__ = [
"url2pathname",
"pathname2url"]
11 "Convert /-delimited pathname to mac pathname"
16 if tp
and tp !=
'file':
17 raise RuntimeError,
'Cannot convert non-local URL to pathname'
19 if pathname[:3] ==
'///':
20 pathname = pathname[2:]
21 elif pathname[:2] ==
'//':
22 raise RuntimeError,
'Cannot convert non-local URL to pathname'
23 components = pathname.split(
'/')
26 while i < len(components):
27 if components[i] ==
'.':
29 elif components[i] ==
'..' and i > 0
and \
30 components[i-1]
not in (
'',
'..'):
31 del components[i-1:i+1]
33 elif components[i] ==
'' and i > 0
and components[i-1] !=
'':
39 rv =
':'.
join(components[1:])
44 while i < len(components)
and components[i] ==
'..':
47 rv =
':' +
':'.
join(components)
52 "convert mac pathname to /-delimited pathname"
54 raise RuntimeError,
"Cannot convert pathname containing slashes"
55 components = pathname.split(
':')
57 if components[0] ==
'':
59 if components[-1] ==
'':
62 for i
in range(len(components)):
63 if components[i] ==
'':
66 components = map(_pncomp2url, components)
68 if os.path.isabs(pathname):
69 return '/' +
'/'.
join(components)
71 return '/'.
join(components)
73 def _pncomp2url(component):
78 for url
in [
"index.html",
80 "/foo/bar/index.html",
84 for path
in [
"drive:",
94 if __name__ ==
'__main__':