Revision ccd6b542 lib/rapi/client.py

b/lib/rapi/client.py
356 356
      "User-Agent": self.USER_AGENT,
357 357
      }
358 358

  
359
  def _MakeUrl(self, path, query=None):
360
    """Constructs the URL to pass to the HTTP client.
361

  
362
    @type path: str
363
    @param path: HTTP URL path
364
    @type query: list of two-tuples
365
    @param query: query arguments to pass to urllib.urlencode
366

  
367
    @rtype:  str
368
    @return: URL path
369

  
370
    """
371
    return "https://%(host)s:%(port)d%(path)s?%(query)s" % {
372
        "host": self._host,
373
        "port": self._port,
374
        "path": path,
375
        "query": urllib.urlencode(query or [])}
376

  
377 359
  def _SendRequest(self, method, path, query=None, content=None):
378 360
    """Sends an HTTP request.
379 361

  
......
396 378
    @raises GanetiApiError: If an invalid response is returned
397 379

  
398 380
    """
381
    assert path.startswith("/")
382

  
399 383
    if content:
400 384
      encoded_content = self._json_encoder.encode(content)
401 385
    else:
402 386
      encoded_content = None
403 387

  
404
    url = self._MakeUrl(path, query)
388
    # Build URL
389
    url = [self._base_url, path]
390
    if query:
391
      url.append("?")
392
      url.append(urllib.urlencode(query))
405 393

  
406
    req = _RapiRequest(method, url, self._headers, encoded_content)
394
    req = _RapiRequest(method, "".join(url), self._headers, encoded_content)
407 395

  
408 396
    try:
409 397
      resp = self._http.open(req)

Also available in: Unified diff