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
# 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', "' ;/?:@&=+$,#")
94
norm_file('%27%3B/%3F%3A%40%26%3D%2B%24%2C%23%20', "';/?:@&=+$,# ")
98
96
def test_normalize_url_hybrid(self):
99
97
# Anything with a scheme:// should be treated as a hybrid url
257
255
def test_win32_local_path_to_url(self):
258
256
to_url = urlutils._win32_local_path_to_url
259
self.assertEqual('file:///c:/path/to/foo',
257
self.assertEqual('file:///C:/path/to/foo',
260
258
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'))
271
261
result = to_url(u'd:/path/to/r\xe4ksm\xf6rg\xe5s')
272
262
except UnicodeError:
273
263
raise TestSkipped("local encoding cannot handle unicode")
275
self.assertEqual('file:///d:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
265
self.assertEqual('file:///D:/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
277
267
def test_win32_local_path_from_url(self):
278
268
from_url = urlutils._win32_local_path_from_url
279
self.assertEqual('c:/path/to/foo',
269
self.assertEqual('C:/path/to/foo',
280
270
from_url('file:///C|/path/to/foo'))
281
self.assertEqual(u'd:/path/to/r\xe4ksm\xf6rg\xe5s',
271
self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
282
272
from_url('file:///d|/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
283
self.assertEqual(u'd:/path/to/r\xe4ksm\xf6rg\xe5s',
273
self.assertEqual(u'D:/path/to/r\xe4ksm\xf6rg\xe5s',
284
274
from_url('file:///d:/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
286
276
self.assertRaises(InvalidURL, from_url, '/path/to/foo')
381
371
test('http://foo', 'http://foo')
382
372
if sys.platform == 'win32':
383
test('c:/foo/path', 'file:///C|/foo/path')
384
test('c:/foo/path', 'file:///C:/foo/path')
373
test('C:/foo/path', 'file:///C|/foo/path')
374
test('C:/foo/path', 'file:///C:/foo/path')
386
376
test('/foo/path', 'file:///foo/path')