Skip to contentSkip to conversation

lib/oe/distro_check: don't set empty proxy keys

PATCH New Ross Burton 1 participant 1 message Nov 12, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/oe/distro_check: don't set empty proxy keys

If the proxies dictionary has a proxy set to None urllib will throw an exception instead of not using a proxy (abridged stack):

File: '/home/ross/Yocto/poky/meta/lib/oe/distro_check.py', lineno: 43, function: get_links_from_url
*** 0043: with create_socket(url,d) as sock:

     0044:        webpage = sock.read()

File: '/home/ross/Yocto/poky/meta/lib/oe/distro_check.py', lineno: 5, function: create_socket
0003:def create_socket(url, d):
0004: import urllib
*** 0005: socket = urllib.urlopen(url, proxies=get_proxies(d))
File: '/usr/lib/python2.7/urllib.py', lineno: 87, function: urlopen
0086: if data is None:
*** 0087: return opener.open(url)
File: '/usr/lib/python2.7/urllib.py', lineno: 203, function: open
0201: else:
0202: proxy = None

 *** 0203:        name = 'open_' + urltype
     0204:        self.type = urltype
     0205:        name = name.replace('-', '_')

Exception: TypeError: cannot concatenate 'str' and 'NoneType' objects

Filter out unset values so that the dictionary only has valid assignments in.

---
 meta/lib/oe/distro_check.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
meta/lib/oe/distro_check.py +6 -4
index f92cd2e..8655a6f 100644
@@ -9,10 +9,12 @@ def create_socket(url, d):
         socket.close()
 
 def get_proxies(d):
-    import os
-    proxykeys = ['http', 'https', 'ftp', 'ftps', 'no', 'all']
-    proxyvalues = map(lambda key: d.getVar(key+'_proxy', True), proxykeys)
-    return dict(zip(proxykeys, proxyvalues))
+    proxies = {}
+    for key in ['http', 'https', 'ftp', 'ftps', 'no', 'all']:
+        proxy = d.getVar(key + '_proxy', True)
+        if proxy:
+            proxies[key] = proxy
+    return proxies
 
 def get_links_from_url(url, d):
     "Return all the href links found on the web location"
Signature · 1 line
2.1.4