Skip to content

Commit 7112533

Browse files
committed
Adding comment about using _connection in storage.blob.
Doing this to address review commits. Also testing current() in the presence of an empty batch stack.
1 parent e221edb commit 7112533

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

gcloud/storage/blob.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ def download_to_file(self, file_obj, client=None):
291291
headers['Range'] = 'bytes=0-%d' % (self.chunk_size - 1,)
292292
request = http_wrapper.Request(download_url, 'GET', headers)
293293

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

296302
# Should we be passing callbacks through from caller? We can't

gcloud/storage/test_batch.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ def test_current(self):
9090
credentials = _Credentials()
9191
client = Client(project=project, credentials=credentials)
9292
batch1 = self._makeOne(client)
93+
self.assertTrue(batch1.current() is None)
94+
9395
client._push_batch(batch1)
9496
self.assertTrue(batch1.current() is batch1)
97+
9598
batch2 = self._makeOne(client)
9699
client._push_batch(batch2)
97100
self.assertTrue(batch1.current() is batch2)
@@ -372,11 +375,10 @@ def test_as_context_mgr_wo_error(self):
372375
expected = _Response()
373376
expected['content-type'] = 'multipart/mixed; boundary="DEADBEEF="'
374377
http = _HTTP((expected, _THREE_PART_MIME_RESPONSE))
375-
connection = _Connection(http=http)
376378
project = 'PROJECT'
377379
credentials = _Credentials()
378380
client = Client(project=project, credentials=credentials)
379-
client._connection = connection
381+
client._connection._http = http
380382

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

0 commit comments

Comments
 (0)