Skip to content

Commit 3414d0f

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 92aa585 + 13c917d commit 3414d0f

File tree

4 files changed

+27
-36
lines changed

4 files changed

+27
-36
lines changed

google-cloud-speech/google/cloud/speech/_gax.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from google.cloud._helpers import make_secure_channel
2929
from google.cloud._helpers import make_secure_stub
30-
from google.cloud.connection import DEFAULT_USER_AGENT
30+
from google.cloud._http import DEFAULT_USER_AGENT
3131

3232
from google.cloud.speech.alternative import Alternative
3333
from google.cloud.speech.operation import Operation
@@ -39,7 +39,7 @@ class GAPICSpeechAPI(object):
3939
"""Manage calls through GAPIC wrappers to the Speech API."""
4040
def __init__(self, client=None):
4141
self._client = client
42-
credentials = self._client.connection.credentials
42+
credentials = self._client._connection.credentials
4343
channel = make_secure_channel(
4444
credentials, DEFAULT_USER_AGENT,
4545
SpeechApi.SERVICE_ADDRESS)

google-cloud-speech/google/cloud/speech/client.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,7 @@ class _JSONSpeechAPI(object):
308308
"""
309309
def __init__(self, client):
310310
self._client = client
311-
self._connection = client.connection
312-
313-
@property
314-
def connection(self):
315-
"""Connection property.
316-
317-
:rtype: :class:`~google.cloud.core.connection.Connection`
318-
:returns: Instance of ``Connection``
319-
"""
320-
return self._connection
311+
self._connection = client._connection
321312

322313
def async_recognize(self, sample, language_code=None,
323314
max_alternatives=None, profanity_filter=None,

google-cloud-speech/google/cloud/speech/connection.py

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

1515
"""Create / interact with Google Cloud Speech 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 Speech JSON REST API."""
2222

2323
API_BASE_URL = 'https://speech.googleapis.com'

google-cloud-speech/unit_tests/test_client.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ def test_ctor(self):
8282
creds = _Credentials()
8383
http = object()
8484
client = self._make_one(credentials=creds, http=http)
85-
self.assertIsInstance(client.connection, Connection)
86-
self.assertTrue(client.connection.credentials is creds)
87-
self.assertTrue(client.connection.http is http)
85+
self.assertIsInstance(client._connection, Connection)
86+
self.assertTrue(client._connection.credentials is creds)
87+
self.assertTrue(client._connection.http is http)
8888

8989
def test_ctor_use_gax_preset(self):
9090
creds = _Credentials()
@@ -147,7 +147,7 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
147147
}
148148
credentials = _Credentials()
149149
client = self._make_one(credentials=credentials, use_gax=False)
150-
client.connection = _Connection(RETURNED)
150+
client._connection = _Connection(RETURNED)
151151

152152
encoding = speech.Encoding.FLAC
153153

@@ -160,8 +160,8 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
160160
profanity_filter=True,
161161
speech_context=self.HINTS)
162162

163-
self.assertEqual(len(client.connection._requested), 1)
164-
req = client.connection._requested[0]
163+
self.assertEqual(len(client._connection._requested), 1)
164+
req = client._connection._requested[0]
165165
self.assertEqual(len(req), 3)
166166
self.assertEqual(req['data'], REQUEST)
167167
self.assertEqual(req['method'], 'POST')
@@ -192,7 +192,7 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
192192
}
193193
credentials = _Credentials()
194194
client = self._make_one(credentials=credentials, use_gax=False)
195-
client.connection = _Connection(RETURNED)
195+
client._connection = _Connection(RETURNED)
196196

197197
encoding = speech.Encoding.FLAC
198198

@@ -201,8 +201,8 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
201201

202202
response = client.sync_recognize(sample)
203203

204-
self.assertEqual(len(client.connection._requested), 1)
205-
req = client.connection._requested[0]
204+
self.assertEqual(len(client._connection._requested), 1)
205+
req = client._connection._requested[0]
206206
self.assertEqual(len(req), 3)
207207
self.assertEqual(req['data'], REQUEST)
208208
self.assertEqual(req['method'], 'POST')
@@ -222,7 +222,7 @@ def test_sync_recognize_with_empty_results_no_gax(self):
222222

223223
credentials = _Credentials()
224224
client = self._make_one(credentials=credentials, use_gax=False)
225-
client.connection = _Connection(SYNC_RECOGNIZE_EMPTY_RESPONSE)
225+
client._connection = _Connection(SYNC_RECOGNIZE_EMPTY_RESPONSE)
226226

227227
sample = Sample(source_uri=self.AUDIO_SOURCE_URI,
228228
encoding=speech.Encoding.FLAC,
@@ -240,8 +240,8 @@ def test_sync_recognize_with_empty_results_gax(self):
240240

241241
credentials = _Credentials()
242242
client = self._make_one(credentials=credentials, use_gax=True)
243-
client.connection = _Connection()
244-
client.connection.credentials = credentials
243+
client._connection = _Connection()
244+
client._connection.credentials = credentials
245245

246246
channel_args = []
247247
channel_obj = object()
@@ -283,8 +283,8 @@ def test_sync_recognize_with_gax(self):
283283

284284
creds = _Credentials()
285285
client = self._make_one(credentials=creds, use_gax=True)
286-
client.connection = _Connection()
287-
client.connection.credentials = creds
286+
client._connection = _Connection()
287+
client._connection.credentials = creds
288288
client._speech_api = None
289289

290290
alternatives = [{
@@ -344,7 +344,7 @@ def test_async_supported_encodings(self):
344344

345345
credentials = _Credentials()
346346
client = self._make_one(credentials=credentials)
347-
client.connection = _Connection({})
347+
client._connection = _Connection({})
348348

349349
sample = Sample(source_uri=self.AUDIO_SOURCE_URI,
350350
encoding=speech.Encoding.FLAC,
@@ -362,7 +362,7 @@ def test_async_recognize_no_gax(self):
362362

363363
credentials = _Credentials()
364364
client = self._make_one(credentials=credentials, use_gax=False)
365-
client.connection = _Connection(RETURNED)
365+
client._connection = _Connection(RETURNED)
366366

367367
sample = Sample(source_uri=self.AUDIO_SOURCE_URI,
368368
encoding=speech.Encoding.LINEAR16,
@@ -385,8 +385,8 @@ def test_async_recognize_with_gax(self):
385385
credentials = _Credentials()
386386
client = self._make_one(credentials=credentials,
387387
use_gax=True)
388-
client.connection = _Connection()
389-
client.connection.credentials = credentials
388+
client._connection = _Connection()
389+
client._connection.credentials = credentials
390390

391391
channel_args = []
392392
channel_obj = object()
@@ -652,8 +652,8 @@ def test_speech_api_with_gax(self):
652652

653653
creds = _Credentials()
654654
client = self._make_one(credentials=creds, use_gax=True)
655-
client.connection = _Connection()
656-
client.connection.credentials = creds
655+
client._connection = _Connection()
656+
client._connection.credentials = creds
657657

658658
channel_args = []
659659
channel_obj = object()
@@ -680,14 +680,14 @@ def speech_api(channel=None):
680680
self.assertEqual(channel_args, [expected])
681681

682682
def test_speech_api_without_gax(self):
683-
from google.cloud.connection import Connection
683+
from google.cloud._http import Connection
684684
from google.cloud.speech.client import _JSONSpeechAPI
685685

686686
creds = _Credentials()
687687
client = self._make_one(credentials=creds, use_gax=False)
688688
self.assertIsNone(client._speech_api)
689689
self.assertIsInstance(client.speech_api, _JSONSpeechAPI)
690-
self.assertIsInstance(client.speech_api.connection, Connection)
690+
self.assertIsInstance(client.speech_api._connection, Connection)
691691

692692
def test_speech_api_preset(self):
693693
creds = _Credentials()

0 commit comments

Comments
 (0)