[Python-checkins] distutils2: add support of mirrors for PyPI simple client (as described in PEP 381)

tarek.ziade python-checkins at python.org
Sun Jul 4 11:48:40 CEST 2010


tarek.ziade pushed c880d980acaa to distutils2:

http://hg.python.org/distutils2/rev/c880d980acaa
changeset:   332:c880d980acaa
user:        Alexis Metaireau <ametaireau at gmail.com>
date:        Tue Jun 29 18:14:40 2010 +0200
summary:     add support of mirrors for PyPI simple client (as described in PEP 381)
files:       src/distutils2/pypi/simple.py

diff --git a/src/distutils2/pypi/simple.py b/src/distutils2/pypi/simple.py
--- a/src/distutils2/pypi/simple.py
+++ b/src/distutils2/pypi/simple.py
@@ -21,6 +21,7 @@
 
 # -- Constants -----------------------------------------------
 PYPI_DEFAULT_INDEX_URL = "http://pypi.python.org/simple/"
+PYPI_DEFAULT_MIRROR_URL = "mirrors.pypi.python.org"
 DEFAULT_HOSTS = ("*",)  
 SOCKET_TIMEOUT = 15
 USER_AGENT = "Python-urllib/%s distutils2/%s" % (
@@ -62,22 +63,28 @@
     """
 
     def __init__(self, index_url=PYPI_DEFAULT_INDEX_URL, hosts=DEFAULT_HOSTS,
-                 mirrors=[], follow_externals=False, timeout=SOCKET_TIMEOUT):
+                 follow_externals=False, mirrors_url=PYPI_DEFAULT_MIRROR_URL, 
+                 mirrors=None, timeout=SOCKET_TIMEOUT):
         """Class constructor.
 
         :param index_url: the url of the simple index to search on.
-        :param follow_externals: tell if following external links is needed or 
-                                 not. Default is False.
         :param hosts: a list of hosts allowed to be processed while using
                       follow_externals=True. Default behavior is to follow all 
                       hosts.
-        :param mirrors: a list of mirrors to check out if problems occurs while
-                        working with the one given in "url"
+        :param follow_externals: tell if following external links is needed or 
+                                 not. Default is False.
+        :param mirrors_url: the url to look on for DNS records giving mirror
+                            adresses.
+        :param mirrors: a list of mirrors to check out if problems 
+                             occurs while working with the one given in "url"
         :param timeout: time in seconds to consider a url has timeouted.
         """
         if not index_url.endswith("/"):
             index_url += "/"
         self._index_urls = [index_url]
+        # if no mirrors are defined, use the method described in PEP 381.
+        if mirrors is None:
+            mirrors = socket.gethostbyname_ex(mirrors_url)[-1]
         self._index_urls.extend(mirrors)
         self._current_index_url = 0
         self._timeout = timeout

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list