Skip to content

Commit 452f63d

Browse files
committed
Updating connection -> _connection attribute in some packages.
In particular: pubsub/resource_manager/runtimeconfig/speech/translate.
1 parent 5a7a2cb commit 452f63d

File tree

22 files changed

+114
-123
lines changed

22 files changed

+114
-123
lines changed

pubsub/google/cloud/pubsub/_gax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from google.cloud._helpers import _to_bytes
3232
from google.cloud._helpers import _pb_timestamp_to_rfc3339
3333
from google.cloud._helpers import make_secure_channel
34-
from google.cloud.connection import DEFAULT_USER_AGENT
34+
from google.cloud._http import DEFAULT_USER_AGENT
3535
from google.cloud.exceptions import Conflict
3636
from google.cloud.exceptions import NotFound
3737
from google.cloud.iterator import GAXIterator

pubsub/google/cloud/pubsub/_http.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import functools
1919
import os
2020

21-
from google.cloud import connection as base_connection
21+
from google.cloud import _http
2222
from google.cloud.environment_vars import PUBSUB_EMULATOR
2323
from google.cloud.iterator import HTTPIterator
2424
from google.cloud.pubsub._helpers import subscription_name_from_path
@@ -30,7 +30,7 @@
3030
"""Pub / Sub API request host."""
3131

3232

33-
class Connection(base_connection.JSONConnection):
33+
class Connection(_http.JSONConnection):
3434
"""A connection to Google Cloud Pub/Sub via the JSON REST API.
3535
3636
:type credentials: :class:`oauth2client.client.OAuth2Credentials`
@@ -108,7 +108,7 @@ class _PublisherAPI(object):
108108

109109
def __init__(self, client):
110110
self._client = client
111-
self._connection = client.connection
111+
self._connection = client._connection
112112

113113
def list_topics(self, project, page_size=None, page_token=None):
114114
"""API call: list topics for a given project
@@ -255,7 +255,7 @@ class _SubscriberAPI(object):
255255

256256
def __init__(self, client):
257257
self._client = client
258-
self._connection = client.connection
258+
self._connection = client._connection
259259

260260
def list_subscriptions(self, project, page_size=None, page_token=None):
261261
"""API call: list subscriptions for a given project

pubsub/google/cloud/pubsub/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def publisher_api(self):
8585
"""Helper for publisher-related API calls."""
8686
if self._publisher_api is None:
8787
if self._use_gax:
88-
generated = make_gax_publisher_api(self.connection)
88+
generated = make_gax_publisher_api(self._connection)
8989
self._publisher_api = GAXPublisherAPI(generated, self)
9090
else:
9191
self._publisher_api = JSONPublisherAPI(self)
@@ -96,7 +96,7 @@ def subscriber_api(self):
9696
"""Helper for subscriber-related API calls."""
9797
if self._subscriber_api is None:
9898
if self._use_gax:
99-
generated = make_gax_subscriber_api(self.connection)
99+
generated = make_gax_subscriber_api(self._connection)
100100
self._subscriber_api = GAXSubscriberAPI(generated, self)
101101
else:
102102
self._subscriber_api = JSONSubscriberAPI(self)
@@ -106,7 +106,7 @@ def subscriber_api(self):
106106
def iam_policy_api(self):
107107
"""Helper for IAM policy-related API calls."""
108108
if self._iam_policy_api is None:
109-
self._iam_policy_api = _IAMPolicyAPI(self.connection)
109+
self._iam_policy_api = _IAMPolicyAPI(self._connection)
110110
return self._iam_policy_api
111111

112112
def list_topics(self, page_size=None, page_token=None):

pubsub/unit_tests/test__http.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def test_list_subscriptions_no_paging(self):
435435
connection = _Connection(RETURNED)
436436
creds = _Credentials()
437437
client = Client(project=self.PROJECT, credentials=creds)
438-
client.connection = connection
438+
client._connection = connection
439439
api = self._make_one(client)
440440

441441
iterator = api.list_subscriptions(self.PROJECT)
@@ -478,7 +478,7 @@ def test_list_subscriptions_with_paging(self):
478478
connection = _Connection(RETURNED)
479479
creds = _Credentials()
480480
client = Client(project=self.PROJECT, credentials=creds)
481-
client.connection = connection
481+
client._connection = connection
482482
api = self._make_one(client)
483483

484484
iterator = api.list_subscriptions(
@@ -879,7 +879,7 @@ def api_request(self, **kw):
879879
class _Client(object):
880880

881881
def __init__(self, connection, project):
882-
self.connection = connection
882+
self._connection = connection
883883
self.project = project
884884

885885

pubsub/unit_tests/test_client.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_publisher_api_wo_gax(self):
3939
with _Monkey(MUT, _USE_GAX=False):
4040
client = self._make_one(project=self.PROJECT, credentials=creds)
4141

42-
conn = client.connection = object()
42+
conn = client._connection = object()
4343
api = client.publisher_api
4444

4545
self.assertIsInstance(api, _PublisherAPI)
@@ -93,7 +93,7 @@ def __init__(self, _wrapped, client):
9393
# API instance is cached
9494
again = client.publisher_api
9595
self.assertIs(again, api)
96-
args = (client.connection,)
96+
args = (client._connection,)
9797
self.assertEqual(_called_with, [(args, {})])
9898

9999
def test_subscriber_api_wo_gax(self):
@@ -105,7 +105,7 @@ def test_subscriber_api_wo_gax(self):
105105
with _Monkey(MUT, _USE_GAX=False):
106106
client = self._make_one(project=self.PROJECT, credentials=creds)
107107

108-
conn = client.connection = object()
108+
conn = client._connection = object()
109109
api = client.subscriber_api
110110

111111
self.assertIsInstance(api, _SubscriberAPI)
@@ -145,14 +145,14 @@ def __init__(self, _wrapped, client):
145145
# API instance is cached
146146
again = client.subscriber_api
147147
self.assertIs(again, api)
148-
args = (client.connection,)
148+
args = (client._connection,)
149149
self.assertEqual(_called_with, [(args, {})])
150150

151151
def test_iam_policy_api(self):
152152
from google.cloud.pubsub._http import _IAMPolicyAPI
153153
creds = _Credentials()
154154
client = self._make_one(project=self.PROJECT, credentials=creds)
155-
conn = client.connection = object()
155+
conn = client._connection = object()
156156
api = client.iam_policy_api
157157
self.assertIsInstance(api, _IAMPolicyAPI)
158158
self.assertIs(api._connection, conn)
@@ -165,7 +165,7 @@ def test_list_topics_no_paging(self):
165165

166166
creds = _Credentials()
167167
client = self._make_one(project=self.PROJECT, credentials=creds)
168-
client.connection = object()
168+
client._connection = object()
169169
api = _FauxPublisherAPI(items=[Topic(self.TOPIC_NAME, client)])
170170
client._publisher_api = api
171171

@@ -188,7 +188,7 @@ def test_list_topics_with_paging(self):
188188
SIZE = 1
189189
creds = _Credentials()
190190
client = self._make_one(project=self.PROJECT, credentials=creds)
191-
client.connection = object()
191+
client._connection = object()
192192
api = _FauxPublisherAPI([Topic(self.TOPIC_NAME, client)], TOKEN2)
193193
client._publisher_api = api
194194

@@ -206,7 +206,7 @@ def test_list_topics_with_paging(self):
206206
def test_list_topics_missing_key(self):
207207
creds = _Credentials()
208208
client = self._make_one(project=self.PROJECT, credentials=creds)
209-
client.connection = object()
209+
client._connection = object()
210210
api = _FauxPublisherAPI()
211211
client._publisher_api = api
212212

@@ -228,7 +228,7 @@ def test_list_subscriptions_no_paging(self):
228228
client = self._make_one(project=self.PROJECT, credentials=creds,
229229
use_gax=False)
230230
returned = {'subscriptions': [SUB_INFO]}
231-
client.connection = _Connection(returned)
231+
client._connection = _Connection(returned)
232232

233233
iterator = client.list_subscriptions()
234234
subscriptions = list(iterator)
@@ -248,7 +248,7 @@ def test_list_subscriptions_no_paging(self):
248248
self.assertIsNone(subscription.ack_deadline)
249249
self.assertIsNone(subscription.push_endpoint)
250250

251-
called_with = client.connection._called_with
251+
called_with = client._connection._called_with
252252
expected_path = '/projects/%s/subscriptions' % (self.PROJECT,)
253253
self.assertEqual(called_with, {
254254
'method': 'GET',
@@ -280,7 +280,7 @@ def test_list_subscriptions_with_paging(self):
280280
'subscriptions': [SUB_INFO],
281281
'nextPageToken': TOKEN2,
282282
}
283-
client.connection = _Connection(returned)
283+
client._connection = _Connection(returned)
284284

285285
iterator = client.list_subscriptions(
286286
SIZE, TOKEN1)
@@ -302,7 +302,7 @@ def test_list_subscriptions_with_paging(self):
302302
self.assertEqual(subscription.ack_deadline, ACK_DEADLINE)
303303
self.assertEqual(subscription.push_endpoint, PUSH_ENDPOINT)
304304

305-
called_with = client.connection._called_with
305+
called_with = client._connection._called_with
306306
expected_path = '/projects/%s/subscriptions' % (self.PROJECT,)
307307
self.assertEqual(called_with, {
308308
'method': 'GET',
@@ -318,7 +318,7 @@ def test_list_subscriptions_w_missing_key(self):
318318
creds = _Credentials()
319319

320320
client = self._make_one(project=PROJECT, credentials=creds)
321-
client.connection = object()
321+
client._connection = object()
322322
api = client._subscriber_api = _FauxSubscriberAPI()
323323
api._list_subscriptions_response = (), None
324324

pubsub/unit_tests/test_topic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def test_list_subscriptions_no_paging(self):
330330
'subscriptions': SUBS_LIST,
331331
'nextPageToken': TOKEN,
332332
}
333-
client.connection = _Connection(returned)
333+
client._connection = _Connection(returned)
334334

335335
topic = self._make_one(self.TOPIC_NAME, client=client)
336336

@@ -353,7 +353,7 @@ def test_list_subscriptions_no_paging(self):
353353

354354
self.assertEqual(next_page_token, TOKEN)
355355
# Verify the mock.
356-
called_with = client.connection._called_with
356+
called_with = client._connection._called_with
357357
self.assertEqual(len(called_with), 3)
358358
self.assertEqual(called_with['method'], 'GET')
359359
path = '/%s/subscriptions' % (self.TOPIC_PATH,)
@@ -380,7 +380,7 @@ def test_list_subscriptions_with_paging(self):
380380
returned = {
381381
'subscriptions': SUBS_LIST,
382382
}
383-
client.connection = _Connection(returned)
383+
client._connection = _Connection(returned)
384384

385385
topic = self._make_one(self.TOPIC_NAME, client=client)
386386

@@ -403,7 +403,7 @@ def test_list_subscriptions_with_paging(self):
403403

404404
self.assertIsNone(next_page_token)
405405
# Verify the mock.
406-
called_with = client.connection._called_with
406+
called_with = client._connection._called_with
407407
self.assertEqual(len(called_with), 3)
408408
self.assertEqual(called_with['method'], 'GET')
409409
path = '/%s/subscriptions' % (self.TOPIC_PATH,)
@@ -416,7 +416,7 @@ def test_list_subscriptions_missing_key(self):
416416

417417
client = Client(project=self.PROJECT, credentials=object(),
418418
use_gax=False)
419-
client.connection = _Connection({})
419+
client._connection = _Connection({})
420420
topic = self._make_one(self.TOPIC_NAME, client=client)
421421

422422
iterator = topic.list_subscriptions()
@@ -426,7 +426,7 @@ def test_list_subscriptions_missing_key(self):
426426
self.assertEqual(len(subscriptions), 0)
427427
self.assertIsNone(next_page_token)
428428
# Verify the mock.
429-
called_with = client.connection._called_with
429+
called_with = client._connection._called_with
430430
self.assertEqual(len(called_with), 3)
431431
self.assertEqual(called_with['method'], 'GET')
432432
path = '/%s/subscriptions' % (self.TOPIC_PATH,)

resource_manager/google/cloud/resource_manager/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"""Create / interact with Google Cloud Resource Manager connections."""
1616

1717

18-
from google.cloud import connection as base_connection
18+
from google.cloud import _http
1919

2020

21-
class Connection(base_connection.JSONConnection):
21+
class Connection(_http.JSONConnection):
2222
"""A connection to Google Cloud Resource Manager via the JSON REST API.
2323
2424
:type credentials: :class:`oauth2client.client.OAuth2Credentials`

resource_manager/google/cloud/resource_manager/project.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def create(self, client=None):
131131
'name': self.name,
132132
'labels': self.labels,
133133
}
134-
resp = client.connection.api_request(method='POST', path='/projects',
135-
data=data)
134+
resp = client._connection.api_request(method='POST', path='/projects',
135+
data=data)
136136
self.set_properties_from_api_repr(resource=resp)
137137

138138
def reload(self, client=None):
@@ -161,7 +161,7 @@ def reload(self, client=None):
161161

162162
# We assume the project exists. If it doesn't it will raise a NotFound
163163
# exception.
164-
resp = client.connection.api_request(method='GET', path=self.path)
164+
resp = client._connection.api_request(method='GET', path=self.path)
165165
self.set_properties_from_api_repr(resource=resp)
166166

167167
def exists(self, client=None):
@@ -183,7 +183,7 @@ def exists(self, client=None):
183183
try:
184184
# Note that we have to request the entire resource as the API
185185
# doesn't provide a way tocheck for existence only.
186-
client.connection.api_request(method='GET', path=self.path)
186+
client._connection.api_request(method='GET', path=self.path)
187187
except NotFound:
188188
return False
189189
else:
@@ -203,8 +203,8 @@ def update(self, client=None):
203203
client = self._require_client(client)
204204

205205
data = {'name': self.name, 'labels': self.labels}
206-
resp = client.connection.api_request(method='PUT', path=self.path,
207-
data=data)
206+
resp = client._connection.api_request(
207+
method='PUT', path=self.path, data=data)
208208
self.set_properties_from_api_repr(resp)
209209

210210
def delete(self, client=None, reload_data=False):
@@ -232,7 +232,7 @@ def delete(self, client=None, reload_data=False):
232232
Default: :data:`False`.
233233
"""
234234
client = self._require_client(client)
235-
client.connection.api_request(method='DELETE', path=self.path)
235+
client._connection.api_request(method='DELETE', path=self.path)
236236

237237
# If the reload flag is set, reload the project.
238238
if reload_data:
@@ -262,8 +262,8 @@ def undelete(self, client=None, reload_data=False):
262262
Default: :data:`False`.
263263
"""
264264
client = self._require_client(client)
265-
client.connection.api_request(method='POST',
266-
path=self.path + ':undelete')
265+
client._connection.api_request(
266+
method='POST', path=self.path + ':undelete')
267267

268268
# If the reload flag is set, reload the project.
269269
if reload_data:

0 commit comments

Comments
 (0)