[bitbake-devel] [RFC PATCH] bitbake: Rewrite fetch2.decodeurl() to use urlparse.urlsplit()
Phil Blundell
pb at pbcl.net
Fri Jan 10 16:28:43 UTC 2014
This means that it now understands "standard" URI syntax as well as
the slightly odd legacy bitbake variant.
There are other places in bitbake (e.g. Local.urldata_init) that also
need fixing, but this is a start.
Signed-off-by: Phil Blundell <pb at pbcl.net>
---
lib/bb/fetch2/__init__.py | 60 ++++++++++++++++++++++++++---------------------
1 file changed, 33 insertions(+), 27 deletions(-)
diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py
index 260fb37..4886dae 100644
--- a/lib/bb/fetch2/__init__.py
+++ b/lib/bb/fetch2/__init__.py
@@ -329,40 +329,46 @@ def decodeurl(url):
user, password, parameters).
"""
- m = re.compile('(?P<type>[^:]*)://((?P<user>.+)@)?(?P<location>[^;]+)(;(?P<parm>.*))?').match(url)
- if not m:
+ if url.startswith("file://"):
+ # This is an old-style bitbake URL. Fix it up.
+ url = "file:" + url[7:]
+
+ import urlparse
+ d = urlparse.urlsplit(url)
+ if not d.scheme:
raise MalformedUrl(url)
- type = m.group('type')
- location = m.group('location')
- if not location:
+ netloc = d.netloc
+ path = d.path
+
+ if not path:
raise MalformedUrl(url)
- user = m.group('user')
- parm = m.group('parm')
- locidx = location.find('/')
- if locidx != -1 and type.lower() != 'file':
- host = location[:locidx]
- path = location[locidx:]
- else:
- host = ""
- path = location
- if user:
- m = re.compile('(?P<user>[^:]+)(:?(?P<pswd>.*))').match(user)
- if m:
- user = m.group('user')
- pswd = m.group('pswd')
- else:
- user = ''
- pswd = ''
+ user = ''
+ pswd = ''
+ host = ''
+
+ if netloc:
+ m = re.compile('((?P<user>[^:@]+)(:(?P<pswd>[^@]+))?@)?(?P<host>.+)').match(netloc)
+ if not m:
+ raise MalformedUrl(url)
+
+ user = m.group('user')
+ pswd = m.group('pswd')
+ host = m.group('host')
p = {}
- if parm:
- for s in parm.split(';'):
- s1, s2 = s.split('=')
- p[s1] = s2
+ sep = path.find(";")
+ if sep != -1:
+ for s in path[sep+1:].split(';'):
+ try:
+ s1, s2 = s.split('=')
+ p[s1] = s2
+ except ValueError:
+ raise MalformedUrl(url)
+ path = path[:sep]
- return type, host, urllib.unquote(path), user, pswd, p
+ return d.scheme, host, urllib.unquote(path), user, pswd, p
def encodeurl(decoded):
"""Encodes a URL from tokens (scheme, network location, path,
--
1.8.5
More information about the bitbake-devel
mailing list