summaryrefslogtreecommitdiffstats
path: root/Lib/macurl2path.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-08-06 13:37:21 (GMT)
committerGuido van Rossum <guido@python.org>1998-08-06 13:37:21 (GMT)
commit4ff6d27319bf07a43ba41905658241e73457c291 (patch)
treef9967a246909ab80310b8201c68f26eb3716a715 /Lib/macurl2path.py
parent9c241ba014f5b3ff9b4a6c980f1c20585199b874 (diff)
downloadcpython-4ff6d27319bf07a43ba41905658241e73457c291.zip
cpython-4ff6d27319bf07a43ba41905658241e73457c291.tar.gz
cpython-4ff6d27319bf07a43ba41905658241e73457c291.tar.bz2
Quote/unquote slashes in macintosh pathname components (Jack Jansen).
Diffstat (limited to 'Lib/macurl2path.py')
-rw-r--r--Lib/macurl2path.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/Lib/macurl2path.py b/Lib/macurl2path.py
index dced58a..7d273bc 100644
--- a/Lib/macurl2path.py
+++ b/Lib/macurl2path.py
@@ -29,7 +29,7 @@ def url2pathname(pathname):
i = i+1
if not components[0]:
# Absolute unix path, don't start with colon
- return string.join(components[1:], ':')
+ rv = string.join(components[1:], ':')
else:
# relative unix path, start with colon. First replace
# leading .. by empty strings (giving ::file)
@@ -37,7 +37,9 @@ def url2pathname(pathname):
while i < len(components) and components[i] == '..':
components[i] = ''
i = i + 1
- return ':' + string.join(components, ':')
+ rv = ':' + string.join(components, ':')
+ # and finally unquote slashes and other funny characters
+ return urllib.unquote(rv)
def pathname2url(pathname):
"convert mac pathname to /-delimited pathname"
@@ -54,13 +56,17 @@ def pathname2url(pathname):
if components[i] == '':
components[i] = '..'
# Truncate names longer than 31 bytes
- components = map(lambda x: x[:31], components)
+ components = map(_pncomp2url, components)
if os.path.isabs(pathname):
return '/' + string.join(components, '/')
else:
return string.join(components, '/')
-
+
+def _pncomp2url(component):
+ component = urllib.quote(component[:31], safe='') # We want to quote slashes
+ return component
+
def test():
for url in ["index.html",
"bar/index.html",