Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

version = '0.1.1'
version = '0.1.4'

setup(
name='python-wellrested',
Expand Down
17 changes: 13 additions & 4 deletions wellrested/connections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -57,6 +59,7 @@ def _deserialize(self, data):

class JsonRestClient(RestClient):
content_type = 'application/json'
accept = 'application/json'

def _serialize(self, data):
if data:
Expand Down Expand Up @@ -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):
Expand All @@ -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


Expand All @@ -135,14 +141,17 @@ 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 = {}

params = None
path = resource
headers['User-Agent'] = 'Basic Agent'

if accept is not None:
headers["Accept"] = accept

BOUNDARY = mimetools.choose_boundary()
CRLF = u'\r\n'

Expand Down