summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitbake/lib/bb/fetch2/__init__.py54
1 files changed, 51 insertions, 3 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index 93fe012ec3..5aa67accc3 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -357,6 +357,54 @@ def decodeurl(url):
357 path = uri.path if uri.path else "/" 357 path = uri.path if uri.path else "/"
358 return uri.scheme, uri.hostport, path, uri.username, uri.password, uri.params 358 return uri.scheme, uri.hostport, path, uri.username, uri.password, uri.params
359 359
360def decodemirrorurl(url):
361 """Decodes a mirror URL into the tokens (scheme, network location, path,
362 user, password, parameters).
363 """
364 m = re.compile('(?P<type>[^:]*)://((?P<user>[^/;]+)@)?(?P<location>[^;]+)(;(?P<parm>.*))?').match(url)
365 if not m:
366 raise MalformedUrl(url)
367
368 type = m.group('type')
369 location = m.group('location')
370 if not location:
371 raise MalformedUrl(url)
372 user = m.group('user')
373 parm = m.group('parm')
374
375 locidx = location.find('/')
376 if locidx != -1 and type.lower() != 'file':
377 host = location[:locidx]
378 path = location[locidx:]
379 elif type.lower() == 'file':
380 host = ""
381 path = location
382 if user:
383 path = user + '@' + path
384 user = ""
385 else:
386 host = location
387 path = "/"
388 if user:
389 m = re.compile('(?P<user>[^:]+)(:?(?P<pswd>.*))').match(user)
390 if m:
391 user = m.group('user')
392 pswd = m.group('pswd')
393 else:
394 user = ''
395 pswd = ''
396
397 p = collections.OrderedDict()
398 if parm:
399 for s in parm.split(';'):
400 if s:
401 if not '=' in s:
402 raise MalformedUrl(url, "The URL: '%s' is invalid: parameter %s does not specify a value (missing '=')" % (url, s))
403 s1, s2 = s.split('=', 1)
404 p[s1] = s2
405
406 return type, host, urllib.parse.unquote(path), user, pswd, p
407
360def encodeurl(decoded): 408def encodeurl(decoded):
361 """Encodes a URL from tokens (scheme, network location, path, 409 """Encodes a URL from tokens (scheme, network location, path,
362 user, password, parameters). 410 user, password, parameters).
@@ -391,9 +439,9 @@ def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None):
391 if not ud.url or not uri_find or not uri_replace: 439 if not ud.url or not uri_find or not uri_replace:
392 logger.error("uri_replace: passed an undefined value, not replacing") 440 logger.error("uri_replace: passed an undefined value, not replacing")
393 return None 441 return None
394 uri_decoded = list(decodeurl(ud.url)) 442 uri_decoded = list(decodemirrorurl(ud.url))
395 uri_find_decoded = list(decodeurl(uri_find)) 443 uri_find_decoded = list(decodemirrorurl(uri_find))
396 uri_replace_decoded = list(decodeurl(uri_replace)) 444 uri_replace_decoded = list(decodemirrorurl(uri_replace))
397 logger.debug2("For url %s comparing %s to %s" % (uri_decoded, uri_find_decoded, uri_replace_decoded)) 445 logger.debug2("For url %s comparing %s to %s" % (uri_decoded, uri_find_decoded, uri_replace_decoded))
398 result_decoded = ['', '', '', '', '', {}] 446 result_decoded = ['', '', '', '', '', {}]
399 # 0 - type, 1 - host, 2 - path, 3 - user, 4- pswd, 5 - params 447 # 0 - type, 1 - host, 2 - path, 3 - user, 4- pswd, 5 - params