From f7be5f9bfa61a07a8256aaae8f22d151f6b8ad81 Mon Sep 17 00:00:00 2001
From: Damien George <damien.p.george@gmail.com>
Date: Mon, 23 Apr 2018 16:11:27 +1000
Subject: [PATCH] tools/upip: Upgrade upip to 1.2.4.

Uses new pypi.org URL, and now creates a socket with the address parameters
returned by getaddrinfo().
---
 tools/bootstrap_upip.sh |  2 +-
 tools/upip.py           | 17 ++++++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/tools/bootstrap_upip.sh b/tools/bootstrap_upip.sh
index 667d0845a..2891775d7 100755
--- a/tools/bootstrap_upip.sh
+++ b/tools/bootstrap_upip.sh
@@ -17,7 +17,7 @@ fi
 
 # Remove any stale old version
 rm -rf micropython-upip-*
-wget -nd -r -l1 https://pypi.python.org/pypi/micropython-upip/ --accept-regex ".*pypi.python.org/packages/source/.*.gz" --reject=html
+wget -nd -rH -l1 -D files.pythonhosted.org https://pypi.org/project/micropython-upip/ --reject=html
 
 tar xfz micropython-upip-*.tar.gz
 tmpd="$PWD"
diff --git a/tools/upip.py b/tools/upip.py
index 411da49e8..a400c3174 100644
--- a/tools/upip.py
+++ b/tools/upip.py
@@ -1,3 +1,10 @@
+#
+# upip - Package manager for MicroPython
+#
+# Copyright (c) 2015-2018 Paul Sokolovsky
+#
+# Licensed under the MIT license.
+#
 import sys
 import gc
 import uos as os
@@ -110,16 +117,16 @@ def url_open(url):
 
     proto, _, host, urlpath = url.split('/', 3)
     try:
-        ai = usocket.getaddrinfo(host, 443)
+        ai = usocket.getaddrinfo(host, 443, 0, usocket.SOCK_STREAM)
     except OSError as e:
         fatal("Unable to resolve %s (no Internet?)" % host, e)
     #print("Address infos:", ai)
-    addr = ai[0][4]
+    ai = ai[0]
 
-    s = usocket.socket(ai[0][0])
+    s = usocket.socket(ai[0], ai[1], ai[2])
     try:
         #print("Connect address:", addr)
-        s.connect(addr)
+        s.connect(ai[-1])
 
         if proto == "https:":
             s = ussl.wrap_socket(s, server_hostname=host)
@@ -149,7 +156,7 @@ def url_open(url):
 
 
 def get_pkg_metadata(name):
-    f = url_open("https://pypi.python.org/pypi/%s/json" % name)
+    f = url_open("https://pypi.org/pypi/%s/json" % name)
     try:
         return json.load(f)
     finally:
-- 
GitLab