def _urljoin(base, url): """ Join relative URLs to base URLs like urllib.parse.urljoin but support arbitrary URIs (esp. 'http+unix://'). """ parsed = urlparse(base) scheme = parsed.scheme return urlparse(urljoin(parsed._replace(scheme="http").geturl(), url))._replace(scheme=scheme).geturl()
def _urljoin(base, url): """ Join relative URLs to base URLs like urllib.parse.urljoin but support arbitrary URIs (esp. 'http+unix://'). """ parsed = urlparse(base) scheme = parsed.scheme return urlparse(urljoin(parsed._replace(scheme='http').geturl(), url))._replace(scheme=scheme).geturl()
def _create_request(self, full_url, body=None): # when full_url contains basic auth info, extract it and set the Authorization header url = urlparse(full_url) if url.username: # base64 encoding of username:password auth = base64.b64encode(six.b('{}:{}'.format(url.username, url.password or ''))) if six.PY3: auth = auth.decode('utf-8') # update full_url and create a request object with the auth header set full_url = url._replace(netloc=url.netloc.split('@', 1)[-1]).geturl() req = Request(full_url) req.add_header('Authorization', 'Basic {}'.format(auth)) else: req = Request(full_url) # add the request body if body: req.data = urlencode(body).encode('utf-8') return req