test_urllib2.py 720 Bytes
Newer Older
1
from test.test_support import verify
2
import urllib2
3
import os
4 5 6 7 8 9 10 11 12 13

# A couple trivial tests

try:
    urllib2.urlopen('bogus url')
except ValueError:
    pass
else:
    verify(0)

14 15 16 17
# XXX Name hacking to get this to work on Windows.
fname = os.path.abspath(urllib2.__file__).replace('\\', '/')
if fname[1:2] == ":":
    fname = fname[2:]
18 19 20
# And more hacking to get it to work on MacOS. This assumes
# urllib.pathname2url works, unfortunately...
if os.name == 'mac':
Tim Peters's avatar
Tim Peters committed
21
    fname = '/' + fname.replace(':', '/')
22 23 24 25 26
elif os.name == 'riscos':
    import string
    fname = os.expand(fname)
    fname = fname.translate(string.maketrans("/.", "./"))

27
file_url = "file://%s" % fname
28
f = urllib2.urlopen(file_url)
29

30 31
buf = f.read()
f.close()