Skip to content

Commit ec039d0

Browse files
authored
Merge pull request #2703 from dhermes/connection-non-public
Making base connection module non-public and making connection attribute non-public
2 parents 32184d3 + 6918e7c commit ec039d0

File tree

13 files changed

+97
-97
lines changed

13 files changed

+97
-97
lines changed

packages/google-cloud-storage/google/cloud/storage/_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def reload(self, client=None):
7474
# Pass only '?projection=noAcl' here because 'acl' and related
7575
# are handled via custom endpoints.
7676
query_params = {'projection': 'noAcl'}
77-
api_response = client.connection.api_request(
77+
api_response = client._connection.api_request(
7878
method='GET', path=self.path, query_params=query_params,
7979
_target_object=self)
8080
self._set_properties(api_response)
@@ -122,7 +122,7 @@ def patch(self, client=None):
122122
# to work properly w/ 'noAcl'.
123123
update_properties = {key: self._properties[key]
124124
for key in self._changes}
125-
api_response = client.connection.api_request(
125+
api_response = client._connection.api_request(
126126
method='PATCH', path=self.path, data=update_properties,
127127
query_params={'projection': 'full'}, _target_object=self)
128128
self._set_properties(api_response)

packages/google-cloud-storage/google/cloud/storage/_http.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
"""Create / interact with Google Cloud Storage connections."""
1616

17-
from google.cloud import connection as base_connection
17+
from google.cloud import _http
1818

1919

20-
class Connection(base_connection.JSONConnection):
20+
class Connection(_http.JSONConnection):
2121
"""A connection to Google Cloud Storage via the JSON REST API.
2222
2323
:type credentials: :class:`oauth2client.client.OAuth2Credentials`
@@ -28,7 +28,7 @@ class Connection(base_connection.JSONConnection):
2828
:param http: (Optional) HTTP object to make requests.
2929
"""
3030

31-
API_BASE_URL = base_connection.API_BASE_URL
31+
API_BASE_URL = _http.API_BASE_URL
3232
"""The base of the API call URL."""
3333

3434
API_VERSION = 'v1'

packages/google-cloud-storage/google/cloud/storage/acl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def reload(self, client=None):
407407

408408
self.entities.clear()
409409

410-
found = client.connection.api_request(method='GET', path=path)
410+
found = client._connection.api_request(method='GET', path=path)
411411
self.loaded = True
412412
for entry in found.get('items', ()):
413413
self.add_entity(self.entity_from_dict(entry))
@@ -436,7 +436,7 @@ def _save(self, acl, predefined, client):
436436

437437
path = self.save_path
438438
client = self._require_client(client)
439-
result = client.connection.api_request(
439+
result = client._connection.api_request(
440440
method='PATCH',
441441
path=path,
442442
data={self._URL_PATH_ELEM: list(acl)},

packages/google-cloud-storage/google/cloud/storage/batch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ def finish(self):
241241

242242
url = '%s/batch' % self.API_BASE_URL
243243

244-
# Use the private ``_connection`` rather than the public
245-
# ``.connection``, since the public connection may be this
244+
# Use the private ``_base_connection`` rather than the property
245+
# ``_connection``, since the property may be this
246246
# current batch.
247-
response, content = self._client._connection._make_request(
247+
response, content = self._client._base_connection._make_request(
248248
'POST', url, data=body, headers=headers)
249249
responses = list(_unpack_batch_response(response, content))
250250
self._finish_futures(responses)

packages/google-cloud-storage/google/cloud/storage/blob.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def generate_signed_url(self, expiration, method='GET',
235235

236236
if credentials is None:
237237
client = self._require_client(client)
238-
credentials = client._connection.credentials
238+
credentials = client._base_connection.credentials
239239

240240
return generate_signed_url(
241241
credentials, resource=resource,
@@ -264,9 +264,9 @@ def exists(self, client=None):
264264
query_params = {'fields': 'name'}
265265
# We intentionally pass `_target_object=None` since fields=name
266266
# would limit the local properties.
267-
client.connection.api_request(method='GET', path=self.path,
268-
query_params=query_params,
269-
_target_object=None)
267+
client._connection.api_request(
268+
method='GET', path=self.path,
269+
query_params=query_params, _target_object=None)
270270
# NOTE: This will not fail immediately in a batch. However, when
271271
# Batch.finish() is called, the resulting `NotFound` will be
272272
# raised.
@@ -344,13 +344,13 @@ def download_to_file(self, file_obj, client=None):
344344

345345
request = Request(download_url, 'GET', headers)
346346

347-
# Use the private ``_connection`` rather than the public
348-
# ``.connection``, since the public connection may be a batch. A
349-
# batch wraps a client's connection, but does not store the `http`
350-
# object. The rest (API_BASE_URL and build_api_url) are also defined
351-
# on the Batch class, but we just use the wrapped connection since
352-
# it has all three (http, API_BASE_URL and build_api_url).
353-
download.initialize_download(request, client._connection.http)
347+
# Use ``_base_connection`` rather ``_connection`` since the current
348+
# connection may be a batch. A batch wraps a client's connection,
349+
# but does not store the ``http`` object. The rest (API_BASE_URL and
350+
# build_api_url) are also defined on the Batch class, but we just
351+
# use the wrapped connection since it has all three (http,
352+
# API_BASE_URL and build_api_url).
353+
download.initialize_download(request, client._base_connection.http)
354354

355355
def download_to_filename(self, filename, client=None):
356356
"""Download the contents of this blob into a named file.
@@ -466,13 +466,13 @@ def upload_from_file(self, file_obj, rewind=False, size=None,
466466
if the upload response returns an error status.
467467
"""
468468
client = self._require_client(client)
469-
# Use the private ``_connection`` rather than the public
470-
# ``.connection``, since the public connection may be a batch. A
471-
# batch wraps a client's connection, but does not store the `http`
472-
# object. The rest (API_BASE_URL and build_api_url) are also defined
473-
# on the Batch class, but we just use the wrapped connection since
474-
# it has all three (http, API_BASE_URL and build_api_url).
475-
connection = client._connection
469+
# Use ``_base_connection`` rather ``_connection`` since the current
470+
# connection may be a batch. A batch wraps a client's connection,
471+
# but does not store the ``http`` object. The rest (API_BASE_URL and
472+
# build_api_url) are also defined on the Batch class, but we just
473+
# use the wrapped connection since it has all three (http,
474+
# API_BASE_URL and build_api_url).
475+
connection = client._base_connection
476476
content_type = (content_type or self._properties.get('contentType') or
477477
'application/octet-stream')
478478

@@ -650,7 +650,7 @@ def compose(self, sources, client=None):
650650
'sourceObjects': [{'name': source.name} for source in sources],
651651
'destination': self._properties.copy(),
652652
}
653-
api_response = client.connection.api_request(
653+
api_response = client._connection.api_request(
654654
method='POST', path=self.path + '/compose', data=request,
655655
_target_object=self)
656656
self._set_properties(api_response)
@@ -688,7 +688,7 @@ def rewrite(self, source, token=None, client=None):
688688
else:
689689
query_params = {}
690690

691-
api_response = client.connection.api_request(
691+
api_response = client._connection.api_request(
692692
method='POST', path=source.path + '/rewriteTo' + self.path,
693693
query_params=query_params, data=self._properties, headers=headers,
694694
_target_object=self)

packages/google-cloud-storage/google/cloud/storage/bucket.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ def exists(self, client=None):
144144
query_params = {'fields': 'name'}
145145
# We intentionally pass `_target_object=None` since fields=name
146146
# would limit the local properties.
147-
client.connection.api_request(method='GET', path=self.path,
148-
query_params=query_params,
149-
_target_object=None)
147+
client._connection.api_request(
148+
method='GET', path=self.path,
149+
query_params=query_params, _target_object=None)
150150
# NOTE: This will not fail immediately in a batch. However, when
151151
# Batch.finish() is called, the resulting `NotFound` will be
152152
# raised.
@@ -171,7 +171,7 @@ def create(self, client=None):
171171
query_params = {'project': client.project}
172172
properties = {key: self._properties[key] for key in self._changes}
173173
properties['name'] = self.name
174-
api_response = client.connection.api_request(
174+
api_response = client._connection.api_request(
175175
method='POST', path='/b', query_params=query_params,
176176
data=properties, _target_object=self)
177177
self._set_properties(api_response)
@@ -233,7 +233,7 @@ def get_blob(self, blob_name, client=None):
233233
client = self._require_client(client)
234234
blob = Blob(bucket=self, name=blob_name)
235235
try:
236-
response = client.connection.api_request(
236+
response = client._connection.api_request(
237237
method='GET', path=blob.path, _target_object=blob)
238238
# NOTE: We assume response.get('name') matches `blob_name`.
239239
blob._set_properties(response)
@@ -363,8 +363,8 @@ def delete(self, force=False, client=None):
363363
# We intentionally pass `_target_object=None` since a DELETE
364364
# request has no response value (whether in a standard request or
365365
# in a batch request).
366-
client.connection.api_request(method='DELETE', path=self.path,
367-
_target_object=None)
366+
client._connection.api_request(
367+
method='DELETE', path=self.path, _target_object=None)
368368

369369
def delete_blob(self, blob_name, client=None):
370370
"""Deletes a blob from the current bucket.
@@ -405,8 +405,8 @@ def delete_blob(self, blob_name, client=None):
405405
# We intentionally pass `_target_object=None` since a DELETE
406406
# request has no response value (whether in a standard request or
407407
# in a batch request).
408-
client.connection.api_request(method='DELETE', path=blob_path,
409-
_target_object=None)
408+
client._connection.api_request(
409+
method='DELETE', path=blob_path, _target_object=None)
410410

411411
def delete_blobs(self, blobs, on_error=None, client=None):
412412
"""Deletes a list of blobs from the current bucket.
@@ -472,7 +472,7 @@ def copy_blob(self, blob, destination_bucket, new_name=None,
472472
new_name = blob.name
473473
new_blob = Blob(bucket=destination_bucket, name=new_name)
474474
api_path = blob.path + '/copyTo' + new_blob.path
475-
copy_result = client.connection.api_request(
475+
copy_result = client._connection.api_request(
476476
method='POST', path=api_path, _target_object=new_blob)
477477
if not preserve_acl:
478478
new_blob.acl.save(acl={}, client=client)

packages/google-cloud-storage/google/cloud/storage/client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ class Client(JSONClient):
4848
_connection_class = Connection
4949

5050
def __init__(self, project=None, credentials=None, http=None):
51-
self._connection = None
51+
self._base_connection = None
5252
super(Client, self).__init__(project=project, credentials=credentials,
5353
http=http)
5454
self._batch_stack = _LocalStack()
5555

5656
@property
57-
def connection(self):
57+
def _connection(self):
5858
"""Get connection or batch on the client.
5959
6060
:rtype: :class:`google.cloud.storage._http.Connection`
@@ -64,24 +64,24 @@ def connection(self):
6464
if self.current_batch is not None:
6565
return self.current_batch
6666
else:
67-
return self._connection
67+
return self._base_connection
6868

69-
@connection.setter
70-
def connection(self, value):
69+
@_connection.setter
70+
def _connection(self, value):
7171
"""Set connection on the client.
7272
7373
Intended to be used by constructor (since the base class calls)
74-
self.connection = connection
74+
self._connection = connection
7575
Will raise if the connection is set more than once.
7676
7777
:type value: :class:`google.cloud.storage._http.Connection`
7878
:param value: The connection set on the client.
7979
8080
:raises: :class:`ValueError` if connection has already been set.
8181
"""
82-
if self._connection is not None:
82+
if self._base_connection is not None:
8383
raise ValueError('Connection already set on client')
84-
self._connection = value
84+
self._base_connection = value
8585

8686
def _push_batch(self, batch):
8787
"""Push a batch onto our stack.

packages/google-cloud-storage/unit_tests/test__helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,4 @@ def b64encode(self, value):
223223
class _Client(object):
224224

225225
def __init__(self, connection):
226-
self.connection = connection
226+
self._connection = connection

packages/google-cloud-storage/unit_tests/test_acl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,4 +813,4 @@ def api_request(self, **kw):
813813
class _Client(object):
814814

815815
def __init__(self, connection):
816-
self.connection = connection
816+
self._connection = connection

packages/google-cloud-storage/unit_tests/test_batch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def test_as_context_mgr_wo_error(self):
380380
project = 'PROJECT'
381381
credentials = _Credentials()
382382
client = Client(project=project, credentials=credentials)
383-
client._connection._http = http
383+
client._base_connection._http = http
384384

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

@@ -416,7 +416,7 @@ def test_as_context_mgr_w_error(self):
416416
project = 'PROJECT'
417417
credentials = _Credentials()
418418
client = Client(project=project, credentials=credentials)
419-
client._connection = connection
419+
client._base_connection = connection
420420

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

@@ -598,7 +598,7 @@ class _MockObject(object):
598598
class _Client(object):
599599

600600
def __init__(self, connection):
601-
self._connection = connection
601+
self._base_connection = connection
602602

603603

604604
class _Credentials(object):

0 commit comments

Comments
 (0)