Commit ccd6b542 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

RAPI client: Simplify URL construction


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarDavid Knowles <dknowles@google.com>
parent d3844674
......@@ -356,24 +356,6 @@ class GanetiRapiClient(object):
"User-Agent": self.USER_AGENT,
}
def _MakeUrl(self, path, query=None):
"""Constructs the URL to pass to the HTTP client.
@type path: str
@param path: HTTP URL path
@type query: list of two-tuples
@param query: query arguments to pass to urllib.urlencode
@rtype: str
@return: URL path
"""
return "https://%(host)s:%(port)d%(path)s?%(query)s" % {
"host": self._host,
"port": self._port,
"path": path,
"query": urllib.urlencode(query or [])}
def _SendRequest(self, method, path, query=None, content=None):
"""Sends an HTTP request.
......@@ -396,14 +378,20 @@ class GanetiRapiClient(object):
@raises GanetiApiError: If an invalid response is returned
"""
assert path.startswith("/")
if content:
encoded_content = self._json_encoder.encode(content)
else:
encoded_content = None
url = self._MakeUrl(path, query)
# Build URL
url = [self._base_url, path]
if query:
url.append("?")
url.append(urllib.urlencode(query))
req = _RapiRequest(method, url, self._headers, encoded_content)
req = _RapiRequest(method, "".join(url), self._headers, encoded_content)
try:
resp = self._http.open(req)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment