From ccd6b542a4ee76d0208880c5ff65d1a76d335dc5 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Fri, 7 May 2010 19:28:49 +0200
Subject: [PATCH] RAPI client: Simplify URL construction

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: David Knowles <dknowles@google.com>
---
 lib/rapi/client.py | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/lib/rapi/client.py b/lib/rapi/client.py
index 57b1fb4dd..ff1249dbe 100644
--- a/lib/rapi/client.py
+++ b/lib/rapi/client.py
@@ -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)
-- 
GitLab