Skip to content

Commit 1e40fdb

Browse files
dhermeslukesneeringer
authored andcommitted
Renaming http argument(s) as _http. (#3235)
1 parent 2555a4c commit 1e40fdb

File tree

4 files changed

+45
-41
lines changed

4 files changed

+45
-41
lines changed

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,48 @@
2424
from google.cloud.speech.sample import Sample
2525

2626

27-
_USE_GAX = not os.getenv(DISABLE_GRPC, False)
27+
_USE_GRPC = not os.getenv(DISABLE_GRPC, False)
2828

2929

3030
class Client(BaseClient):
3131
"""Client to bundle configuration needed for API requests.
3232
3333
:type credentials: :class:`~google.auth.credentials.Credentials`
3434
:param credentials: (Optional) The OAuth2 Credentials to use for this
35-
client. If not passed (and if no ``http`` object is
35+
client. If not passed (and if no ``_http`` object is
3636
passed), falls back to the default inferred from the
3737
environment.
3838
39-
:type http: :class:`~httplib2.Http`
40-
:param http: (Optional) HTTP object to make requests. Can be any object
41-
that defines ``request()`` with the same interface as
42-
:meth:`~httplib2.Http.request`. If not passed, an
43-
``http`` object is created that is bound to the
44-
``credentials`` for the current object.
45-
46-
:type use_gax: bool
47-
:param use_gax: (Optional) Explicitly specifies whether
48-
to use the gRPC transport (via GAX) or HTTP. If unset,
49-
falls back to the ``GOOGLE_CLOUD_DISABLE_GRPC`` environment
50-
variable
39+
:type _http: :class:`~httplib2.Http`
40+
:param _http: (Optional) HTTP object to make requests. Can be any object
41+
that defines ``request()`` with the same interface as
42+
:meth:`~httplib2.Http.request`. If not passed, an
43+
``_http`` object is created that is bound to the
44+
``credentials`` for the current object.
45+
This parameter should be considered private, and could
46+
change in the future.
47+
48+
:type _use_grpc: bool
49+
:param _use_grpc: (Optional) Explicitly specifies whether
50+
to use the gRPC transport (via GAX) or HTTP. If unset,
51+
falls back to the ``GOOGLE_CLOUD_DISABLE_GRPC``
52+
environment variable.
53+
This parameter should be considered private, and could
54+
change in the future.
5155
"""
5256

5357
SCOPE = ('https://www.googleapis.com/auth/cloud-platform',)
5458
"""The scopes required for authenticating as an API consumer."""
5559

5660
_speech_api = None
5761

58-
def __init__(self, credentials=None, http=None, use_gax=None):
59-
super(Client, self).__init__(credentials=credentials, http=http)
62+
def __init__(self, credentials=None, _http=None, _use_grpc=None):
63+
super(Client, self).__init__(credentials=credentials, _http=_http)
6064
# Save on the actual client class whether we use GAX or not.
61-
if use_gax is None:
62-
self._use_gax = _USE_GAX
65+
if _use_grpc is None:
66+
self._use_grpc = _USE_GRPC
6367
else:
64-
self._use_gax = use_gax
68+
self._use_grpc = _use_grpc
6569

6670
def sample(self, content=None, source_uri=None, stream=None, encoding=None,
6771
sample_rate=None):
@@ -104,7 +108,7 @@ def sample(self, content=None, source_uri=None, stream=None, encoding=None,
104108
def speech_api(self):
105109
"""Helper for speech-related API calls."""
106110
if self._speech_api is None:
107-
if self._use_gax:
111+
if self._use_grpc:
108112
self._speech_api = GAPICSpeechAPI(self)
109113
else:
110114
self._speech_api = HTTPSpeechAPI(self)

packages/google-cloud-speech/google/cloud/speech/sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def streaming_recognize(self, language_code=None,
247247
248248
:raises: EnvironmentError if gRPC is not available.
249249
"""
250-
if not self._client._use_gax:
250+
if not self._client._use_grpc:
251251
raise EnvironmentError('gRPC is required to use this API.')
252252

253253
api = self._client.speech_api

packages/google-cloud-speech/tests/system.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ class Config(object):
5858
"""
5959
CLIENT = None
6060
TEST_BUCKET = None
61-
USE_GAX = True
61+
USE_GRPC = True
6262

6363

6464
def setUpModule():
6565
Config.CLIENT = speech.Client()
66-
Config.USE_GAX = Config.CLIENT._use_gax
66+
Config.USE_GRPC = Config.CLIENT._use_grpc
6767
# Now create a bucket for GCS stored content.
6868
storage_client = storage.Client()
6969
bucket_name = 'new' + unique_resource_id()
@@ -195,15 +195,15 @@ def test_async_recognize_gcs_file(self):
195195
self._check_results(alternatives, 2)
196196

197197
def test_stream_recognize(self):
198-
if not Config.USE_GAX:
198+
if not Config.USE_GRPC:
199199
self.skipTest('gRPC is required for Speech Streaming Recognize.')
200200

201201
with open(AUDIO_FILE, 'rb') as file_obj:
202202
for results in self._make_streaming_request(file_obj):
203203
self._check_results(results.alternatives)
204204

205205
def test_stream_recognize_interim_results(self):
206-
if not Config.USE_GAX:
206+
if not Config.USE_GRPC:
207207
self.skipTest('gRPC is required for Speech Streaming Recognize.')
208208

209209
# These extra words are interim_results that the API returns as it's
@@ -223,7 +223,7 @@ def test_stream_recognize_interim_results(self):
223223
self._check_results(responses[-1].alternatives)
224224

225225
def test_stream_recognize_single_utterance(self):
226-
if not Config.USE_GAX:
226+
if not Config.USE_GRPC:
227227
self.skipTest('gRPC is required for Speech Streaming Recognize.')
228228

229229
with open(AUDIO_FILE, 'rb') as file_obj:

packages/google-cloud-speech/tests/unit/test_client.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ def _make_one(self, *args, **kw):
8787
def test_ctor(self):
8888
creds = _make_credentials()
8989
http = object()
90-
client = self._make_one(credentials=creds, http=http)
90+
client = self._make_one(credentials=creds, _http=http)
9191
self.assertTrue(client._credentials is creds)
9292
self.assertTrue(client._http is http)
9393

94-
def test_ctor_use_gax_preset(self):
94+
def test_ctor_use_grpc_preset(self):
9595
creds = _make_credentials()
9696
http = object()
97-
client = self._make_one(credentials=creds, http=http, use_gax=True)
98-
self.assertTrue(client._use_gax)
97+
client = self._make_one(credentials=creds, _http=http, _use_grpc=True)
98+
self.assertTrue(client._use_grpc)
9999

100100
def test_create_sample_from_client(self):
101101
from google.cloud import speech
@@ -148,7 +148,7 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
148148
}
149149
}
150150
credentials = _make_credentials()
151-
client = self._make_one(credentials=credentials, use_gax=False)
151+
client = self._make_one(credentials=credentials, _use_grpc=False)
152152
speech_api = client.speech_api
153153
connection = _Connection(SYNC_RECOGNIZE_RESPONSE)
154154
speech_api._connection = connection
@@ -196,7 +196,7 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
196196
},
197197
}
198198
credentials = _make_credentials()
199-
client = self._make_one(credentials=credentials, use_gax=False)
199+
client = self._make_one(credentials=credentials, _use_grpc=False)
200200
speech_api = client.speech_api
201201
connection = _Connection(SYNC_RECOGNIZE_RESPONSE)
202202
speech_api._connection = connection
@@ -233,7 +233,7 @@ def test_sync_recognize_with_empty_results_no_gax(self):
233233
from tests.unit._fixtures import SYNC_RECOGNIZE_EMPTY_RESPONSE
234234

235235
credentials = _make_credentials()
236-
client = self._make_one(credentials=credentials, use_gax=False)
236+
client = self._make_one(credentials=credentials, _use_grpc=False)
237237
speech_api = client.speech_api
238238
speech_api._connection = _Connection(SYNC_RECOGNIZE_EMPTY_RESPONSE)
239239

@@ -251,7 +251,7 @@ def test_sync_recognize_with_empty_results_gax(self):
251251
from google.cloud.speech import _gax
252252

253253
credentials = _make_credentials()
254-
client = self._make_one(credentials=credentials, use_gax=True)
254+
client = self._make_one(credentials=credentials, _use_grpc=True)
255255
client._credentials = credentials
256256

257257
channel_args = []
@@ -293,7 +293,7 @@ def test_sync_recognize_with_gax(self):
293293
from google.cloud.speech import _gax
294294

295295
creds = _make_credentials()
296-
client = self._make_one(credentials=creds, use_gax=True)
296+
client = self._make_one(credentials=creds, _use_grpc=True)
297297
client._credentials = creds
298298

299299
alternatives = [{
@@ -354,7 +354,7 @@ def test_async_supported_encodings(self):
354354
from google.cloud import speech
355355

356356
credentials = _make_credentials()
357-
client = self._make_one(credentials=credentials, use_gax=True)
357+
client = self._make_one(credentials=credentials, _use_grpc=True)
358358

359359
sample = client.sample(
360360
source_uri=self.AUDIO_SOURCE_URI, encoding=speech.Encoding.FLAC,
@@ -370,7 +370,7 @@ def test_async_recognize_no_gax(self):
370370
RETURNED = ASYNC_RECOGNIZE_RESPONSE
371371

372372
credentials = _make_credentials()
373-
client = self._make_one(credentials=credentials, use_gax=False)
373+
client = self._make_one(credentials=credentials, _use_grpc=False)
374374
speech_api = client.speech_api
375375
speech_api._connection = _Connection(RETURNED)
376376

@@ -393,7 +393,7 @@ def test_async_recognize_with_gax(self):
393393
from google.cloud.speech.operation import Operation
394394

395395
credentials = _make_credentials()
396-
client = self._make_one(credentials=credentials, use_gax=True)
396+
client = self._make_one(credentials=credentials, _use_grpc=True)
397397
client._credentials = credentials
398398

399399
channel_args = []
@@ -433,7 +433,7 @@ def test_streaming_depends_on_gax(self):
433433
from google.cloud import speech
434434

435435
credentials = _make_credentials()
436-
client = self._make_one(credentials=credentials, use_gax=False)
436+
client = self._make_one(credentials=credentials, _use_grpc=False)
437437
sample = client.sample(
438438
content=self.AUDIO_CONTENT, encoding=speech.Encoding.LINEAR16,
439439
sample_rate=self.SAMPLE_RATE)
@@ -673,7 +673,7 @@ def test_speech_api_with_gax(self):
673673
from google.cloud.speech import _gax
674674

675675
creds = _make_credentials()
676-
client = self._make_one(credentials=creds, use_gax=True)
676+
client = self._make_one(credentials=creds, _use_grpc=True)
677677
client._credentials = creds
678678

679679
channel_args = []
@@ -705,7 +705,7 @@ def test_speech_api_without_gax(self):
705705
from google.cloud.speech._http import HTTPSpeechAPI
706706

707707
creds = _make_credentials()
708-
client = self._make_one(credentials=creds, use_gax=False)
708+
client = self._make_one(credentials=creds, _use_grpc=False)
709709
self.assertIsNone(client._speech_api)
710710
self.assertIsInstance(client.speech_api, HTTPSpeechAPI)
711711
self.assertIsInstance(client.speech_api._connection, Connection)

0 commit comments

Comments
 (0)