From 5d4e0655d089cf0738846d219a573ae4ab1cf405 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Sun, 26 Sep 2010 16:57:42 -0300 Subject: [PATCH] Fixed test_utils_url, broken on Windows after recent Python urllib change. Closes #251 --- scrapy/tests/test_utils_url.py | 8 ++++---- scrapy/utils/url.py | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scrapy/tests/test_utils_url.py b/scrapy/tests/test_utils_url.py index 6884b81a9..1292a84f6 100644 --- a/scrapy/tests/test_utils_url.py +++ b/scrapy/tests/test_utils_url.py @@ -277,7 +277,7 @@ class UrlUtilsTest(unittest.TestCase): def test_path_to_file_uri(self): if os.name == 'nt': self.assertEqual(path_to_file_uri("C:\\windows\clock.avi"), - "file:///C|/windows/clock.avi") + "file:///C:/windows/clock.avi") else: self.assertEqual(path_to_file_uri("/some/path.txt"), "file:///some/path.txt") @@ -289,9 +289,9 @@ class UrlUtilsTest(unittest.TestCase): def test_file_uri_to_path(self): if os.name == 'nt': - self.assertEqual(file_uri_to_path("file:///C|/windows/clock.avi"), + self.assertEqual(file_uri_to_path("file:///C:/windows/clock.avi"), "C:\\windows\clock.avi") - uri = "file:///C|/windows/clock.avi" + uri = "file:///C:/windows/clock.avi" uri2 = path_to_file_uri(file_uri_to_path(uri)) self.assertEqual(uri, uri2) else: @@ -309,7 +309,7 @@ class UrlUtilsTest(unittest.TestCase): def test_any_to_uri(self): if os.name == 'nt': self.assertEqual(any_to_uri("C:\\windows\clock.avi"), - "file:///C|/windows/clock.avi") + "file:///C:/windows/clock.avi") else: self.assertEqual(any_to_uri("/some/path.txt"), "file:///some/path.txt") diff --git a/scrapy/utils/url.py b/scrapy/utils/url.py index 552f343f5..ae010cb9e 100644 --- a/scrapy/utils/url.py +++ b/scrapy/utils/url.py @@ -161,6 +161,8 @@ def path_to_file_uri(path): http://en.wikipedia.org/wiki/File_URI_scheme """ x = urllib.pathname2url(os.path.abspath(path)) + if os.name == 'nt': + x = x.replace('|', ':') # http://bugs.python.org/issue5861 return 'file:///%s' % x.lstrip('/') def file_uri_to_path(uri):