Merge pull request #2 from tsufiev/master

Change client to return both response code and response body.
This commit is contained in:
EkaterinaFedorova 2013-10-21 07:15:42 -07:00
commit 49f93b1834
3 changed files with 18 additions and 15 deletions

View File

@ -62,10 +62,6 @@ class HTTPMultipleChoices(HTTPException):
self.details) self.details)
class HTTPNotModified(HTTPException):
code = 304
class BadRequest(HTTPException): class BadRequest(HTTPException):
"""DEPRECATED!""" """DEPRECATED!"""
code = 400 code = 400

View File

@ -235,7 +235,7 @@ class HTTPClient(object):
elif resp.status in (301, 302, 305): elif resp.status in (301, 302, 305):
# Redirected. Reissue the request to the new location. # Redirected. Reissue the request to the new location.
return self._http_request(resp['location'], method, **kwargs) return self._http_request(resp['location'], method, **kwargs)
elif resp.status in (300, 304): elif resp.status == 300:
raise exc.from_response(resp) raise exc.from_response(resp)
return resp, body_iter return resp, body_iter

View File

@ -33,20 +33,27 @@ class Controller(object):
def __init__(self, http_client): def __init__(self, http_client):
self.http_client = http_client self.http_client = http_client
def get_ui_data(self): def _get_data(self, endpoint_type, hash_sum=None):
if hash_sum:
url = '/v1/client/{0}?hash={1}'.format(endpoint_type, hash_sum)
else:
url = '/v1/client/{0}'.format(endpoint_type)
return self.http_client.raw_request('GET', url)
def get_ui_data(self, hash_sum=None):
""" """
Download tar.gz with Download tar.gz with ui metadata. Returns a tuple
(status, body_iterator) where status can be either 200 or 304. In the
304 case there is no sense in iterating with body_iterator.
""" """
url = '/v1/client/ui' return self._get_data('ui', hash_sum=hash_sum)
resp, body = self.http_client.raw_request('GET', url)
return body
def get_conductor_data(self): def get_conductor_data(self, hash_sum=None):
""" """
Download tar.gz with Download tar.gz with conductor metadata. Returns a tuple
(status, body_iterator) where status can be either 200 or 304. In the
304 case there is no sense in iterating with body_iterator.
""" """
url = '/v1/client/conductor' return self._get_data('conductor', hash_sum=hash_sum)
resp, body = self.http_client.raw_request('GET', url)
return body