summaryrefslogtreecommitdiff
path: root/Lib/urllib.py
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1995-12-15 13:22:13 +0000
committerJack Jansen <jack.jansen@cwi.nl>1995-12-15 13:22:13 +0000
commitdc3e3f69db6a6aa5aed1d604d53c0b4cf156add8 (patch)
tree7d04c853307e27f2e1c2073394f02661b455c24d /Lib/urllib.py
parent4f508ad4955d66a77abd92655fda7d89c7339fd4 (diff)
downloadcpython-git-dc3e3f69db6a6aa5aed1d604d53c0b4cf156add8.tar.gz
Fixed local file access for macintosh
Diffstat (limited to 'Lib/urllib.py')
-rw-r--r--Lib/urllib.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py
index 7168a5121c..b06f6bfc5d 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -17,10 +17,25 @@
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