60
60
self.assertEqual('foo', basename('path/../foo'))
61
61
self.assertEqual('foo', basename('../path/foo'))
63
def test_normalize_url(self):
63
def test_normalize_url_files(self):
64
# Test that local paths are properly normalized
65
normalize_url = urlutils.normalize_url
67
def norm_file(expected, path):
68
url = normalize_url(path)
69
self.assertStartsWith(url, 'file:///')
70
if sys.platform == 'win32':
71
url = url[len('file:///C:'):]
73
url = url[len('file://'):]
75
self.assertEndsWith(path, expected)
77
norm_file('path/to/foo', 'path/to/foo')
78
norm_file('/path/to/foo', '/path/to/foo')
79
norm_file('path/to/foo', '../path/to/foo')
81
# Local paths are assumed to *not* be escaped at all
82
norm_file('uni/%C2%B5', u'uni/\xb5')
83
norm_file('uni/%25C2%25B5', u'uni/%C2%B5')
84
norm_file('uni/%20b', u'uni/ b')
85
# All the crazy characters get escaped in local paths => file:/// urls
86
norm_file('%27%3B/%3F%3A%40%26%3D%2B%24%2C%23%20', "';/?:@&=+$,#")
88
def test_normalize_url_hybrid(self):
89
# Anything with a scheme:// should be treated as a hybrid url
90
# which changes what characters get escaped.
91
normalize_url = urlutils.normalize_url
94
eq('file:///foo/', normalize_url(u'file:///foo/'))
95
eq('file:///foo/%20', normalize_url(u'file:///foo/ '))
96
eq('file:///foo/%20', normalize_url(u'file:///foo/%20'))
97
# Don't escape reserved characters
98
eq('file:///ab_c.d-e/%f:?g&h=i+j;k,L#M$',
99
normalize_url('file:///ab_c.d-e/%f:?g&h=i+j;k,L#M$'))
100
eq('http://ab_c.d-e/%f:?g&h=i+j;k,L#M$',
101
normalize_url('http://ab_c.d-e/%f:?g&h=i+j;k,L#M$'))
103
# Escape unicode characters, but not already escaped chars
104
eq('http://host/ab/%C2%B5/%C2%B5',
105
normalize_url(u'http://host/ab/%C2%B5/\xb5'))
107
# Normalize verifies URLs when they are not unicode
108
# (indicating they did not come from the user)
109
self.assertRaises(InvalidURL, normalize_url, 'http://host/\xb5')
110
self.assertRaises(InvalidURL, normalize_url, 'http://host/ ')
66
112
def test_url_scheme_re(self):
67
113
# Test paths that may be URLs