diff options
author | Colin Watson <cjwatson@debian.org> | 2019-05-09 09:50:35 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2019-05-09 09:52:58 +0100 |
commit | 1b2acc6aebeada2cf8d53b2e2184030ac6160f7e (patch) | |
tree | 1502b10f97b49252505a3f7734912d1e3c0216b6 /macaroonbakery/httpbakery/_client.py | |
parent | bc4ad5ef594af4c89ab09c405e64c1483caa0696 (diff) | |
parent | 64f7b99b10a70e8341b4ddf5c9c726722f005ebe (diff) |
Update upstream source from tag 'upstream/1.2.3'
Update to upstream version '1.2.3'
with Debian dir 3636e342362ac7260cde53e4969a25f9f270aa8b
Diffstat (limited to 'macaroonbakery/httpbakery/_client.py')
-rw-r--r-- | macaroonbakery/httpbakery/_client.py | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/macaroonbakery/httpbakery/_client.py b/macaroonbakery/httpbakery/_client.py index 2510f73..326c33d 100644 --- a/macaroonbakery/httpbakery/_client.py +++ b/macaroonbakery/httpbakery/_client.py @@ -107,7 +107,7 @@ class Client: discharges)) + ']' all_macaroons = base64.urlsafe_b64encode(utils.to_bytes(macaroons)) - full_path = relative_url(url, error.info.macaroon_path) + full_path = urljoin(url, error.info.macaroon_path) if error.info.cookie_name_suffix is not None: name = 'macaroon-' + error.info.cookie_name_suffix else: @@ -164,7 +164,10 @@ class Client: if payload is not None: req['caveat64'] = base64.urlsafe_b64encode(payload).rstrip( b'=').decode('utf-8') - target = relative_url(cav.location, 'discharge') + loc = cav.location + if not loc.endswith('/'): + loc += '/' + target = urljoin(loc, 'discharge') headers = { BAKERY_PROTOCOL_HEADER: str(bakery.LATEST_VERSION) } @@ -200,8 +203,8 @@ class Client: raise InteractionError('no supported interaction method') def _legacy_interact(self, location, error_info): - visit_url = relative_url(location, error_info.info.visit_url) - wait_url = relative_url(location, error_info.info.wait_url) + visit_url = urljoin(location, error_info.info.visit_url) + wait_url = urljoin(location, error_info.info.wait_url) method_urls = { "interactive": visit_url } @@ -226,7 +229,7 @@ class Client: if visit_url is None: continue - visit_url = relative_url(location, visit_url) + visit_url = urljoin(location, visit_url) interactor.legacy_interact(self, location, visit_url) return _wait_for_macaroon(wait_url) @@ -295,7 +298,9 @@ def _prepare_discharge_hook(req, client): req.headers[BAKERY_PROTOCOL_HEADER] = \ str(bakery.LATEST_VERSION) with requests.Session() as s: - return s.send(req) + settings = s.merge_environment_settings( + req.url, {}, None, None, None) + return s.send(req, **settings) return hook @@ -371,16 +376,6 @@ def _wait_for_macaroon(wait_url): return bakery.Macaroon.from_dict(resp.json().get('Macaroon')) -def relative_url(base, new): - ''' Returns new path relative to an original URL. - ''' - if new == '': - return base - if not base.endswith('/'): - base += '/' - return urljoin(base, new) - - def _legacy_get_interaction_methods(u): ''' Queries a URL as found in an ErrInteractionRequired VisitURL field to find available interaction methods. @@ -397,7 +392,7 @@ def _legacy_get_interaction_methods(u): if resp.status_code == 200: json_resp = resp.json() for m in json_resp: - method_urls[m] = relative_url(u, json_resp[m]) + method_urls[m] = urljoin(u, json_resp[m]) if method_urls.get('interactive') is None: # There's no "interactive" method returned, but we know |