91
91
norm_file('uni/%25C2%25B5', u'uni/%C2%B5')
92
92
norm_file('uni/%20b', u'uni/ b')
93
93
# All the crazy characters get escaped in local paths => file:/// urls
94
norm_file('%27%3B/%3F%3A%40%26%3D%2B%24%2C%23%20', "';/?:@&=+$,# ")
94
# The ' ' character must not be at the end, because on win32
95
# it gets stripped off by ntpath.abspath
96
norm_file('%27%20%3B/%3F%3A%40%26%3D%2B%24%2C%23', "' ;/?:@&=+$,#")
96
98
def test_normalize_url_hybrid(self):
97
99
# Anything with a scheme:// should be treated as a hybrid url
255
257
def test_win32_local_path_to_url(self):
256
258
to_url = urlutils._win32_local_path_to_url
257
self.assertEqual('file:///C:/path/to/foo',
259
self.assertEqual('file:///c:/path/to/foo',
258
260
to_url('C:/path/to/foo'))
261
# BOGUS: on win32, ntpath.abspath will strip trailing
262
# whitespace, so this will always fail
263
# Though under linux, it fakes abspath support
264
# and thus will succeed
265
# self.assertEqual('file:///C:/path/to/foo%20',
266
# to_url('C:/path/to/foo '))
267
self.assertEqual('file:///c:/path/to/f%20oo',
268
to_url('C:/path/to/f oo'))
261
271
result = to_url(u'd:/path/to/r\xe4ksm\xf6rg\xe5s')
262
272
except UnicodeError:
263
273
raise TestSkipped("local encoding cannot handle unicode")
265
self.assertEqual('file:///D:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
275
self.assertEqual('file:///d:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
267
277
def test_win32_local_path_from_url(self):
268
278
from_url = urlutils._win32_local_path_from_url
269
self.assertEqual('C:/path/to/foo',
279
self.assertEqual('c:/path/to/foo',
270
280
from_url('file:///C|/path/to/foo'))
271
self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
281
self.assertEqual(u'd:/path/to/r\xe4ksm\xf6rg\xe5s',
272
282
from_url('file:///d|/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
273
self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
283
self.assertEqual(u'd:/path/to/r\xe4ksm\xf6rg\xe5s',
274
284
from_url('file:///d:/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
276
286
self.assertRaises(InvalidURL, from_url, '/path/to/foo')
371
381
test('http://foo', 'http://foo')
372
382
if sys.platform == 'win32':
373
test('C:/foo/path', 'file:///C|/foo/path')
374
test('C:/foo/path', 'file:///C:/foo/path')
383
test('c:/foo/path', 'file:///C|/foo/path')
384
test('c:/foo/path', 'file:///C:/foo/path')
376
386
test('/foo/path', 'file:///foo/path')