summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1996-02-14 16:05:20 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1996-02-14 16:05:20 (GMT)
commit0d12ead05cf43d3a8f6e79a1b20fc56c7fb5bc86 (patch)
tree6499342221191cb471070997a6362d87e89b250c /Lib
parente708f4005d777a2930171d0b96d75e7f8abb8027 (diff)
downloadcpython-0d12ead05cf43d3a8f6e79a1b20fc56c7fb5bc86.zip
cpython-0d12ead05cf43d3a8f6e79a1b20fc56c7fb5bc86.tar.gz
cpython-0d12ead05cf43d3a8f6e79a1b20fc56c7fb5bc86.tar.bz2
Try to normalize urls referring to local files (code copied from posixpath)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/urllib.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py
index dc2d2cf..3163696 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -33,8 +33,20 @@ if os.name == 'mac':
if tp and tp <> 'file':
raise RuntimeError, 'Cannot convert non-local URL to pathname'
components = string.split(pathname, '/')
- if '..' in components or '.' in components or '' in components[1:-1]:
- raise RuntimeError, 'Cannot convert URL containing ., .. or // to pathname'
+ i = 0
+ while i < len(components):
+ if components[i] == '.':
+ del components[i]
+ elif components[i] == '..' and i > 0 and \
+ components[i-1] not in ('', '..'):
+ del components[i-1:i+1]
+ i = i-1
+ elif components[i] == '' and i > 0 and components[i-1] <> '':
+ del components[i]
+ else:
+ i = i+1
+ if not components or '..' in components or '.' in components or '' in components[1:-1]:
+ raise RuntimeError, 'Cannot normalize URL containing ., .. or // to pathname'
if not components[0]:
# Absolute unix path, don't start with colon
return string.join(components[1:], ':')
@@ -475,7 +487,7 @@ class ftpwrapper:
if file: cmd = 'LIST ' + file
else: cmd = 'LIST'
conn = self.ftp.transfercmd(cmd)
- return addclosehook(conn.makefile('r'), self.ftp.voidresp)
+ return addclosehook(conn.makefile('rb'), self.ftp.voidresp)
# Base class for addinfo and addclosehook
class addbase: