From patchwork Sun Mar 10 16:22:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [bitbake-devel, 1/5] fetch2.URI: Coerce urlparse to use netloc for all schemes Date: Sun, 10 Mar 2013 16:22:18 -0000 From: Olof Johansson X-Patchwork-Id: 45841 Message-Id: <1362932543-3737-2-git-send-email-olof.johansson@axis.com> To: With this change, we don't have to think about what urlparse supports and not, and can treat all URIs the same in this regard. This should also make a previous, git specific, fix for this problem redundant (and thus removed). Signed-off-by: Olof Johansson --- lib/bb/fetch2/__init__.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py index 4cfe089..455ab6a 100644 --- a/lib/bb/fetch2/__init__.py +++ b/lib/bb/fetch2/__init__.py @@ -31,9 +31,6 @@ import os, re import logging import urllib import urlparse -if 'git' not in urlparse.uses_netloc: - urlparse.uses_netloc.append('git') -from urlparse import urlparse import operator import bb.persist_data, bb.utils import bb.checksum @@ -202,13 +199,25 @@ class URI(object): if not uri: return - urlp = urlparse(uri) + urlp = urlparse.urlparse(uri) self.scheme = urlp.scheme - # Convert URI to be relative + reparse = 0 + + # Coerce urlparse to make URI scheme use netloc + if not self.scheme in urlparse.uses_netloc: + urlparse.uses_params.append(self.scheme) + reparse = 1 + + # Make urlparse happy(/ier) by converting local resources + # to RFC compliant URL format. E.g.: + # file://foo.diff -> file:foo.diff if urlp.scheme in self._netloc_forbidden: uri = re.sub("(?<=:)//(?!/)", "", uri, 1) - urlp = urlparse(uri) + reparse = 1 + + if reparse: + urlp = urlparse.urlparse(uri) # Identify if the URI is relative or not if urlp.scheme in self._relative_schemes and \