diff --git a/setup.py b/setup.py index 9e6fb30..52fd452 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -version = '0.1.1' +version = '0.1.4' setup( name='python-wellrested', diff --git a/wellrested/connections/__init__.py b/wellrested/connections/__init__.py index c22a9b5..b75b656 100644 --- a/wellrested/connections/__init__.py +++ b/wellrested/connections/__init__.py @@ -13,6 +13,7 @@ class RestClient(object): content_type = None + accept = None def __init__(self, base_url, username=None, password=None, connection_class=None, **kwargs): @@ -43,7 +44,8 @@ def _request(self, resource, method, args=None, data=None, headers=None): response_headers, response_content = \ self._connection.request(resource, method, args=args, body=request_body, headers=headers, - content_type=self.content_type) + content_type=self.content_type, + accept=self.accept) if response_headers.get('status') == HTTP_STATUS_OK: response_data = self._deserialize(response_content) return Response(response_headers, response_content, response_data) @@ -57,6 +59,7 @@ def _deserialize(self, data): class JsonRestClient(RestClient): content_type = 'application/json' + accept = 'application/json' def _serialize(self, data): if data: @@ -87,7 +90,7 @@ def _deserialize(self, data): class XmlRestClient(RestClient): content_type = 'text/xml' - + accept = 'text/xml' class Response(object): def __init__(self, headers, content, data): @@ -111,11 +114,14 @@ def __init__(self, base_url, username=None, password=None): self.host = netloc self.path = path + if self.path == "/": + self.path = "" + def _get_content_type(self, filename): return mimetypes.guess_type(filename)[0] or 'application/octet-stream' def request(self, resource, method="get", args=None, body=None, - headers=None, content_type=None): + headers=None, content_type=None, accept=None): raise NotImplementedError @@ -135,7 +141,7 @@ def __init__(self, *args, **kwargs): self._conn.add_credentials(self.username, self.password) def request(self, resource, method, args=None, body=None, headers=None, - content_type=None): + content_type=None, accept=None): if headers is None: headers = {} @@ -143,6 +149,9 @@ def request(self, resource, method, args=None, body=None, headers=None, path = resource headers['User-Agent'] = 'Basic Agent' + if accept is not None: + headers["Accept"] = accept + BOUNDARY = mimetools.choose_boundary() CRLF = u'\r\n'