]> granicus.if.org Git - python/commitdiff
Fixed local file access for macintosh
authorJack Jansen <jack.jansen@cwi.nl>
Fri, 15 Dec 1995 13:22:13 +0000 (13:22 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Fri, 15 Dec 1995 13:22:13 +0000 (13:22 +0000)
Lib/urllib.py

index 7168a5121c0966f6dd3c7c8fd1a4305fb39aacf0..b06f6bfc5d52acec4d06a77d3efbd14ae44cda96 100644 (file)
 import string
 import socket
 import regex
+import os
 
 
 __version__ = '1.2'
 
+# Helper for non-unix systems
+if os.name == 'mac':
+       def _fixpath(pathname):
+               components = string.split(pathname, '/')
+               if not components[0]:
+                       # Absolute unix path, don't start with colon
+                       return string.join(components[1:], ':')
+               else:
+                       # relative unix path, start with colon
+                       return ':' + string.join(components, ':')
+else:
+       def _fixpath(pathname):
+               return pathname
+
 
 # This really consists of two pieces:
 # (1) a class which handles opening of all sorts of URLs
@@ -223,12 +238,12 @@ class URLopener:
        # Use local file
        def open_local_file(self, url):
                host, file = splithost(url)
-               if not host: return addinfo(open(file, 'r'), noheaders())
+               if not host: return addinfo(open(_fixpath(file), 'r'), noheaders())
                host, port = splitport(host)
                if not port and socket.gethostbyname(host) in (
                          localhost(), thishost()):
                        file = unquote(file)
-                       return addinfo(open(file, 'r'), noheaders())
+                       return addinfo(open(_fixpath(file), 'r'), noheaders())
                raise IOError, ('local file error', 'not on local host')
 
        # Use FTP protocol