Skip to content

Commit

Permalink
Datastore: replace httplib2 with Requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott committed Jul 26, 2017
1 parent 27bb81e commit 496af68
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 141 deletions.
21 changes: 10 additions & 11 deletions datastore/google/cloud/datastore/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
def _request(http, project, method, data, base_url):
"""Make a request over the Http transport to the Cloud Datastore API.
:type http: :class:`~httplib2.Http`
:type http: :class:`requests.Session`
:param http: HTTP object to make requests.
:type project: str
Expand All @@ -63,27 +63,26 @@ def _request(http, project, method, data, base_url):
"""
headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': str(len(data)),
'User-Agent': connection_module.DEFAULT_USER_AGENT,
connection_module.CLIENT_INFO_HEADER: _CLIENT_INFO,
}
api_url = build_api_url(project, method, base_url)
headers, content = http.request(
uri=api_url, method='POST', headers=headers, body=data)

status = headers['status']
if status != '200':
error_status = status_pb2.Status.FromString(content)
raise exceptions.make_exception(
headers, error_status.message, use_json=False)
response = http.request(
url=api_url, method='POST', headers=headers, data=data)

return content
if response.status_code != 200:
error_status = status_pb2.Status.FromString(response.content)
raise exceptions.from_http_status(
response.status_code, error_status.message, errors=[error_status])

return response.content


def _rpc(http, project, method, base_url, request_pb, response_pb_cls):
"""Make a protobuf RPC request.
:type http: :class:`~httplib2.Http`
:type http: :class:`requests.Session`
:param http: HTTP object to make requests.
:type project: str
Expand Down
4 changes: 2 additions & 2 deletions datastore/google/cloud/datastore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ class Client(ClientWithProject):
passed), falls back to the default inferred from the
environment.
:type _http: :class:`~httplib2.Http`
:type _http: :class:`~requests.Session`
:param _http: (Optional) HTTP object to make requests. Can be any object
that defines ``request()`` with the same interface as
:meth:`~httplib2.Http.request`. If not passed, an
:meth:`requests.Session.request`. If not passed, an
``_http`` object is created that is bound to the
``credentials`` for the current object.
This parameter should be considered private, and could
Expand Down
Loading

0 comments on commit 496af68

Please sign in to comment.