]> granicus.if.org Git - python/commitdiff
Try to normalize urls referring to local files (code copied from posixpath)
authorJack Jansen <jack.jansen@cwi.nl>
Wed, 14 Feb 1996 16:05:20 +0000 (16:05 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Wed, 14 Feb 1996 16:05:20 +0000 (16:05 +0000)
Lib/urllib.py

index dc2d2cf61930c8d7eb3e3784a7444f3c43a41d75..31636966d77558e1828d860a0556f1aad27b4189 100644 (file)
@@ -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: