[Python-checkins] cpython: make sure the crawler can browse file-based indexes under win32

tarek.ziade python-checkins at python.org
Sat May 21 22:48:09 CEST 2011


http://hg.python.org/cpython/rev/8c9498db0e07
changeset: 70262:8c9498db0e07
user: Tarek Ziade <tarek at ziade.org>
date: Sat May 21 22:47:40 2011 +0200
summary:
 make sure the crawler can browse file-based indexes under win32
files:
 Lib/packaging/pypi/simple.py | 18 ++++++++++--
 Lib/packaging/tests/test_pypi_simple.py | 14 +++++++--
 2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/Lib/packaging/pypi/simple.py b/Lib/packaging/pypi/simple.py
--- a/Lib/packaging/pypi/simple.py
+++ b/Lib/packaging/pypi/simple.py
@@ -123,8 +123,14 @@
 self.follow_externals = follow_externals
 
 # mirroring attributes.
- if not index_url.endswith("/"):
- index_url += "/"
+ parsed = urllib.parse.urlparse(index_url)
+ self.scheme = parsed[0]
+ if self.scheme == 'file':
+ ender = os.path.sep
+ else:
+ ender = '/'
+ if not index_url.endswith(ender):
+ index_url += ender
 # if no mirrors are defined, use the method described in PEP 381.
 if mirrors is None:
 mirrors = get_mirrors(mirrors_url)
@@ -376,7 +382,11 @@
 :param name: the name of the project to find the page
 """
 # Browse and index the content of the given PyPI page.
- url = self.index_url + name + "/"
+ if self.scheme == 'file':
+ ender = os.path.sep
+ else:
+ ender = '/'
+ url = self.index_url + name + ender
 self._process_url(url, name)
 
 @socket_timeout()
@@ -395,7 +405,7 @@
 
 # add index.html automatically for filesystem paths
 if scheme == 'file':
- if url.endswith('/'):
+ if url.endswith(os.path.sep):
 url += "index.html"
 
 # add authorization headers if auth is provided
diff --git a/Lib/packaging/tests/test_pypi_simple.py b/Lib/packaging/tests/test_pypi_simple.py
--- a/Lib/packaging/tests/test_pypi_simple.py
+++ b/Lib/packaging/tests/test_pypi_simple.py
@@ -1,5 +1,5 @@
 """Tests for the packaging.pypi.simple module."""
-
+import re
 import os
 import sys
 import http.client
@@ -277,8 +277,16 @@
 
 def test_browse_local_files(self):
 # Test that we can browse local files"""
- index_path = os.sep.join(["file://" + PYPI_DEFAULT_STATIC_PATH,
- "test_found_links", "simple"])
+ index_url = "file://" + PYPI_DEFAULT_STATIC_PATH
+ if sys.platform == 'win32':
+ # under windows the correct syntax is:
+ # file:///C|\the\path\here
+ # instead of
+ # file://C:\the\path\here
+ fix = re.compile(r'^(file://)([A-Za-z])(:)')
+ index_url = fix.sub('\1円/\2円|', index_url)
+
+ index_path = os.sep.join([index_url, "test_found_links", "simple"])
 crawler = Crawler(index_path)
 dists = crawler.get_releases("foobar")
 self.assertEqual(4, len(dists))
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /