115
115
eq('http://host/ab/%C2%B5/%C2%B5',
116
116
normalize_url(u'http://host/ab/%C2%B5/\xb5'))
118
# Unescape characters that don't need to be escaped
119
eq('http://host/~bob%2525-._',
120
normalize_url('http://host/%7Ebob%2525%2D%2E%5F'))
121
eq('http://host/~bob%2525-._',
122
normalize_url(u'http://host/%7Ebob%2525%2D%2E%5F'))
118
124
# Normalize verifies URLs when they are not unicode
119
125
# (indicating they did not come from the user)
120
126
self.assertRaises(InvalidURL, normalize_url, 'http://host/\xb5')
197
203
joined = urlutils.join(*args)
198
204
self.assertEqual(expected, joined)
200
# Test a single element
203
206
# Test relative path joining
207
test('foo', 'foo') # relative fragment with nothing is preserved.
204
208
test('foo/bar', 'foo', 'bar')
205
209
test('http://foo/bar', 'http://foo', 'bar')
206
210
test('http://foo/bar', 'http://foo', '.', 'bar')
207
211
test('http://foo/baz', 'http://foo', 'bar', '../baz')
208
212
test('http://foo/bar/baz', 'http://foo', 'bar/baz')
209
213
test('http://foo/baz', 'http://foo', 'bar/../baz')
214
test('http://foo/baz', 'http://foo/bar/', '../baz')
217
test('http://foo', 'http://foo') # abs url with nothing is preserved.
212
218
test('http://bar', 'http://foo', 'http://bar')
213
219
test('sftp://bzr/foo', 'http://foo', 'bar', 'sftp://bzr/foo')
214
220
test('file:///bar', 'foo', 'file:///bar')
221
test('http://bar/', 'http://foo', 'http://bar/')
222
test('http://bar/a', 'http://foo', 'http://bar/a')
223
test('http://bar/a/', 'http://foo', 'http://bar/a/')
216
225
# From a base path
217
226
test('file:///foo', 'file:///', 'foo')
222
231
# Invalid joinings
223
232
# Cannot go above root
233
# Implicitly at root:
224
234
self.assertRaises(InvalidURLJoin, urlutils.join,
225
235
'http://foo', '../baz')
236
self.assertRaises(InvalidURLJoin, urlutils.join,
238
# Joining from a path explicitly under the root.
239
self.assertRaises(InvalidURLJoin, urlutils.join,
240
'http://foo/a', '../../b')
242
def test_joinpath(self):
243
def test(expected, *args):
244
joined = urlutils.joinpath(*args)
245
self.assertEqual(expected, joined)
247
# Test a single element
250
# Test relative path joining
251
test('foo/bar', 'foo', 'bar')
252
test('foo/bar', 'foo', '.', 'bar')
253
test('foo/baz', 'foo', 'bar', '../baz')
254
test('foo/bar/baz', 'foo', 'bar/baz')
255
test('foo/baz', 'foo', 'bar/../baz')
257
# Test joining to an absolute path
259
test('/foo', '/foo', '.')
260
test('/foo/bar', '/foo', 'bar')
261
test('/', '/foo', '..')
263
# Test joining with an absolute path
264
test('/bar', 'foo', '/bar')
266
# Test joining to a path with a trailing slash
267
test('foo/bar', 'foo/', 'bar')
270
# Cannot go above root
271
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '../baz')
272
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '..')
273
self.assertRaises(InvalidURLJoin, urlutils.joinpath, '/', '/..')
227
275
def test_function_type(self):
228
276
if sys.platform == 'win32':