Skip to content
Open
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
12 changes: 9 additions & 3 deletions flask_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def get_etree():


def parse_response(resp, content, strict=False):
ct, options = parse_options_header(resp['content-type'])
content_type = resp.get('content-type', 'text/html')
ct, options = parse_options_header(content_type)
if ct in ('application/json', 'text/javascript'):
return json.loads(content)
elif ct in ('application/xml', 'text/xml'):
Expand Down Expand Up @@ -222,13 +223,15 @@ def put(self, *args, **kwargs):
:meth:`request`.
"""
kwargs['method'] = 'PUT'
kwargs['format'] = 'urlencoded'
return self.request(*args, **kwargs)

def delete(self, *args, **kwargs):
"""Sends a ``DELETE`` request. Accepts the same parameters as
:meth:`request`.
"""
kwargs['method'] = 'DELETE'
kwargs['format'] = 'urlencoded'
return self.request(*args, **kwargs)

def make_client(self, token=None):
Expand Down Expand Up @@ -271,16 +274,19 @@ def request(self, url, data="", headers=None, format='urlencoded',
headers = dict(headers or {})
client = self.make_client(token)
url = self.expand_url(url)
if method == 'GET':
if method in ['GET', 'PUT', 'DELETE']:
assert format == 'urlencoded'
if data:
url = add_query(url, data)
url = add_query(url, data).replace('%2C', ',')
data = ""
else:
if content_type is None:
data, content_type = encode_request_data(data, format)
if content_type is not None:
headers['Content-Type'] = content_type

data = data.replace('%2C', ',')

return OAuthResponse(*client.request(url, method=method,
body=data or '',
headers=headers))
Expand Down