Skip to content

Commit

Permalink
rest: handle endpoints that don't output json
Browse files Browse the repository at this point in the history
The /changes/<id>/revisions/current/patch?zip endpoint doesn't
return json output but a binary data (the zipped contents of the
change). The usual get() function raises a ValueError when
faced with this. As a workaround provide a get_raw() function
to allow callers to handle the decoding of data.
  • Loading branch information
cpackham authored and cpackham-atlnz committed Jan 29, 2017
1 parent 89578cb commit bb3b794
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pygerrit/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ def get(self, endpoint, **kwargs):
response = requests.get(self.make_url(endpoint), **kwargs)
return _decode_response(response)

def get_raw(self, endpoint, **kwargs):
""" Send HTTP GET to the endpoint. Return raw result
:arg str endpoint: The endpoint to send to.
:returns:
Raw result.
:raises:
requests.RequestException on timeout or connection error.
"""
kwargs.update(self.kwargs.copy())
response = requests.get(self.make_url(endpoint), **kwargs)
content = response.content.strip()
response.raise_for_status()

return content

def put(self, endpoint, **kwargs):
""" Send HTTP PUT to the endpoint.
Expand Down

0 comments on commit bb3b794

Please sign in to comment.