Skip to content

Commit

Permalink
Adding comment about using _connection in storage.blob.
Browse files Browse the repository at this point in the history
Doing this to address review commits. Also testing current()
in the presence of an empty batch stack.
  • Loading branch information
dhermes committed Jul 21, 2015
1 parent e221edb commit 7112533
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions gcloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ def download_to_file(self, file_obj, client=None):
headers['Range'] = 'bytes=0-%d' % (self.chunk_size - 1,)
request = http_wrapper.Request(download_url, 'GET', headers)

# Use the private ``_connection`` rather than the public
# ``.connection``, since the public connection may be a batch. A
# batch wraps a client's connection, but does not store the `http`
# object. The rest (API_BASE_URL and build_api_url) are also defined
# on the Batch class, but we just use the wrapped connection since
# it has all three (http, API_BASE_URL and build_api_url).
download.InitializeDownload(request, client._connection.http)

# Should we be passing callbacks through from caller? We can't
Expand Down
6 changes: 4 additions & 2 deletions gcloud/storage/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ def test_current(self):
credentials = _Credentials()
client = Client(project=project, credentials=credentials)
batch1 = self._makeOne(client)
self.assertTrue(batch1.current() is None)

client._push_batch(batch1)
self.assertTrue(batch1.current() is batch1)

batch2 = self._makeOne(client)
client._push_batch(batch2)
self.assertTrue(batch1.current() is batch2)
Expand Down Expand Up @@ -372,11 +375,10 @@ def test_as_context_mgr_wo_error(self):
expected = _Response()
expected['content-type'] = 'multipart/mixed; boundary="DEADBEEF="'
http = _HTTP((expected, _THREE_PART_MIME_RESPONSE))
connection = _Connection(http=http)
project = 'PROJECT'
credentials = _Credentials()
client = Client(project=project, credentials=credentials)
client._connection = connection
client._connection._http = http

self.assertEqual(list(client._batch_stack), [])

Expand Down

0 comments on commit 7112533

Please sign in to comment.