Barry Warsaw | 04f357c | 2002-07-23 19:04:11 +0000 | [diff] [blame] | 1 | from test.test_support import verify |
Jeremy Hylton | e3e6104 | 2001-05-09 15:50:25 +0000 | [diff] [blame] | 2 | import urllib2 |
Tim Peters | 861adac | 2001-07-16 20:49:49 +0000 | [diff] [blame] | 3 | import os |
Jeremy Hylton | e3e6104 | 2001-05-09 15:50:25 +0000 | [diff] [blame] | 4 | |
| 5 | # A couple trivial tests |
| 6 | |
| 7 | try: |
| 8 | urllib2.urlopen('bogus url') |
| 9 | except ValueError: |
| 10 | pass |
| 11 | else: |
| 12 | verify(0) |
| 13 | |
Tim Peters | 861adac | 2001-07-16 20:49:49 +0000 | [diff] [blame] | 14 | # XXX Name hacking to get this to work on Windows. |
| 15 | fname = os.path.abspath(urllib2.__file__).replace('\\', '/') |
| 16 | if fname[1:2] == ":": |
| 17 | fname = fname[2:] |
Jack Jansen | 535c524 | 2001-08-27 22:31:58 +0000 | [diff] [blame] | 18 | # And more hacking to get it to work on MacOS. This assumes |
| 19 | # urllib.pathname2url works, unfortunately... |
| 20 | if os.name == 'mac': |
Tim Peters | 83e7ccc | 2001-09-04 06:37:28 +0000 | [diff] [blame] | 21 | fname = '/' + fname.replace(':', '/') |
Guido van Rossum | e2ae77b | 2001-10-24 20:42:55 +0000 | [diff] [blame] | 22 | elif os.name == 'riscos': |
| 23 | import string |
| 24 | fname = os.expand(fname) |
| 25 | fname = fname.translate(string.maketrans("/.", "./")) |
| 26 | |
Tim Peters | 861adac | 2001-07-16 20:49:49 +0000 | [diff] [blame] | 27 | file_url = "file://%s" % fname |
Jeremy Hylton | e3e6104 | 2001-05-09 15:50:25 +0000 | [diff] [blame] | 28 | f = urllib2.urlopen(file_url) |
Tim Peters | 861adac | 2001-07-16 20:49:49 +0000 | [diff] [blame] | 29 | |
Jeremy Hylton | e3e6104 | 2001-05-09 15:50:25 +0000 | [diff] [blame] | 30 | buf = f.read() |
| 31 | f.close() |