Skip to content

Commit 0f12813

Browse files
dhermeslukesneeringer
authored andcommitted
Renaming http argument(s) as _http. (googleapis#3235)
1 parent 2a0ba64 commit 0f12813

File tree

42 files changed

+459
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+459
-403
lines changed

bigquery/google/cloud/bigquery/client.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,27 @@ class Client(ClientWithProject):
6060
6161
:type credentials: :class:`~google.auth.credentials.Credentials`
6262
:param credentials: (Optional) The OAuth2 Credentials to use for this
63-
client. If not passed (and if no ``http`` object is
63+
client. If not passed (and if no ``_http`` object is
6464
passed), falls back to the default inferred from the
6565
environment.
6666
67-
:type http: :class:`~httplib2.Http`
68-
:param http: (Optional) HTTP object to make requests. Can be any object
69-
that defines ``request()`` with the same interface as
70-
:meth:`~httplib2.Http.request`. If not passed, an
71-
``http`` object is created that is bound to the
72-
``credentials`` for the current object.
67+
:type _http: :class:`~httplib2.Http`
68+
:param _http: (Optional) HTTP object to make requests. Can be any object
69+
that defines ``request()`` with the same interface as
70+
:meth:`~httplib2.Http.request`. If not passed, an
71+
``_http`` object is created that is bound to the
72+
``credentials`` for the current object.
73+
This parameter should be considered private, and could
74+
change in the future.
7375
"""
7476

7577
SCOPE = ('https://www.googleapis.com/auth/bigquery',
7678
'https://www.googleapis.com/auth/cloud-platform')
7779
"""The scopes required for authenticating as a BigQuery consumer."""
7880

79-
def __init__(self, project=None, credentials=None, http=None):
81+
def __init__(self, project=None, credentials=None, _http=None):
8082
super(Client, self).__init__(
81-
project=project, credentials=credentials, http=http)
83+
project=project, credentials=credentials, _http=_http)
8284
self._connection = Connection(self)
8385

8486
def list_projects(self, max_results=None, page_token=None):

bigquery/tests/unit/test_client.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_ctor(self):
4040
PROJECT = 'PROJECT'
4141
creds = _make_credentials()
4242
http = object()
43-
client = self._make_one(project=PROJECT, credentials=creds, http=http)
43+
client = self._make_one(project=PROJECT, credentials=creds, _http=http)
4444
self.assertIsInstance(client._connection, Connection)
4545
self.assertIs(client._connection.credentials, creds)
4646
self.assertIs(client._connection.http, http)
@@ -195,7 +195,7 @@ def test_dataset(self):
195195
DATASET = 'dataset_name'
196196
creds = _make_credentials()
197197
http = object()
198-
client = self._make_one(project=PROJECT, credentials=creds, http=http)
198+
client = self._make_one(project=PROJECT, credentials=creds, _http=http)
199199
dataset = client.dataset(DATASET)
200200
self.assertIsInstance(dataset, Dataset)
201201
self.assertEqual(dataset.name, DATASET)
@@ -438,7 +438,7 @@ def test_load_table_from_storage(self):
438438
SOURCE_URI = 'http://example.com/source.csv'
439439
creds = _make_credentials()
440440
http = object()
441-
client = self._make_one(project=PROJECT, credentials=creds, http=http)
441+
client = self._make_one(project=PROJECT, credentials=creds, _http=http)
442442
dataset = client.dataset(DATASET)
443443
destination = dataset.table(DESTINATION)
444444
job = client.load_table_from_storage(JOB, destination, SOURCE_URI)
@@ -458,7 +458,7 @@ def test_copy_table(self):
458458
DESTINATION = 'destination_table'
459459
creds = _make_credentials()
460460
http = object()
461-
client = self._make_one(project=PROJECT, credentials=creds, http=http)
461+
client = self._make_one(project=PROJECT, credentials=creds, _http=http)
462462
dataset = client.dataset(DATASET)
463463
source = dataset.table(SOURCE)
464464
destination = dataset.table(DESTINATION)
@@ -479,7 +479,7 @@ def test_extract_table_to_storage(self):
479479
DESTINATION = 'gs://bucket_name/object_name'
480480
creds = _make_credentials()
481481
http = object()
482-
client = self._make_one(project=PROJECT, credentials=creds, http=http)
482+
client = self._make_one(project=PROJECT, credentials=creds, _http=http)
483483
dataset = client.dataset(DATASET)
484484
source = dataset.table(SOURCE)
485485
job = client.extract_table_to_storage(JOB, source, DESTINATION)
@@ -497,7 +497,7 @@ def test_run_async_query_defaults(self):
497497
QUERY = 'select count(*) from persons'
498498
creds = _make_credentials()
499499
http = object()
500-
client = self._make_one(project=PROJECT, credentials=creds, http=http)
500+
client = self._make_one(project=PROJECT, credentials=creds, _http=http)
501501
job = client.run_async_query(JOB, QUERY)
502502
self.assertIsInstance(job, QueryJob)
503503
self.assertIs(job._client, client)
@@ -516,7 +516,7 @@ def test_run_async_w_udf_resources(self):
516516
QUERY = 'select count(*) from persons'
517517
creds = _make_credentials()
518518
http = object()
519-
client = self._make_one(project=PROJECT, credentials=creds, http=http)
519+
client = self._make_one(project=PROJECT, credentials=creds, _http=http)
520520
udf_resources = [UDFResource("resourceUri", RESOURCE_URI)]
521521
job = client.run_async_query(JOB, QUERY, udf_resources=udf_resources)
522522
self.assertIsInstance(job, QueryJob)
@@ -535,7 +535,7 @@ def test_run_async_w_query_parameters(self):
535535
QUERY = 'select count(*) from persons'
536536
creds = _make_credentials()
537537
http = object()
538-
client = self._make_one(project=PROJECT, credentials=creds, http=http)
538+
client = self._make_one(project=PROJECT, credentials=creds, _http=http)
539539
query_parameters = [ScalarQueryParameter('foo', 'INT64', 123)]
540540
job = client.run_async_query(JOB, QUERY,
541541
query_parameters=query_parameters)
@@ -553,7 +553,7 @@ def test_run_sync_query_defaults(self):
553553
QUERY = 'select count(*) from persons'
554554
creds = _make_credentials()
555555
http = object()
556-
client = self._make_one(project=PROJECT, credentials=creds, http=http)
556+
client = self._make_one(project=PROJECT, credentials=creds, _http=http)
557557
query = client.run_sync_query(QUERY)
558558
self.assertIsInstance(query, QueryResults)
559559
self.assertIs(query._client, client)
@@ -571,7 +571,7 @@ def test_run_sync_query_w_udf_resources(self):
571571
QUERY = 'select count(*) from persons'
572572
creds = _make_credentials()
573573
http = object()
574-
client = self._make_one(project=PROJECT, credentials=creds, http=http)
574+
client = self._make_one(project=PROJECT, credentials=creds, _http=http)
575575
udf_resources = [UDFResource("resourceUri", RESOURCE_URI)]
576576
query = client.run_sync_query(QUERY, udf_resources=udf_resources)
577577
self.assertIsInstance(query, QueryResults)
@@ -589,7 +589,7 @@ def test_run_sync_query_w_query_parameters(self):
589589
QUERY = 'select count(*) from persons'
590590
creds = _make_credentials()
591591
http = object()
592-
client = self._make_one(project=PROJECT, credentials=creds, http=http)
592+
client = self._make_one(project=PROJECT, credentials=creds, _http=http)
593593
query_parameters = [ScalarQueryParameter('foo', 'INT64', 123)]
594594
query = client.run_sync_query(QUERY, query_parameters=query_parameters)
595595
self.assertIsInstance(query, QueryResults)

core/google/cloud/client.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ def from_service_account_json(cls, json_credentials_path, *args, **kwargs):
7474
class Client(_ClientFactoryMixin):
7575
"""Client to bundle configuration needed for API requests.
7676
77-
Stores ``credentials`` and ``http`` object so that subclasses
77+
Stores ``credentials`` and an HTTP object so that subclasses
7878
can pass them along to a connection class.
7979
80-
If no value is passed in for ``http``, a :class:`httplib2.Http` object
80+
If no value is passed in for ``_http``, a :class:`httplib2.Http` object
8181
will be created and authorized with the ``credentials``. If not, the
82-
``credentials`` and ``http`` need not be related.
82+
``credentials`` and ``_http`` need not be related.
8383
8484
Callers and subclasses may seek to use the private key from
8585
``credentials`` to sign data.
@@ -94,21 +94,23 @@ class Client(_ClientFactoryMixin):
9494
9595
In addition, ``redirections`` and ``connection_type`` may be used.
9696
97-
A custom ``http`` object will also need to be able to add a bearer token
97+
A custom ``_http`` object will also need to be able to add a bearer token
9898
to API requests and handle token refresh on 401 errors.
9999
100100
:type credentials: :class:`~google.auth.credentials.Credentials`
101101
:param credentials: (Optional) The OAuth2 Credentials to use for this
102-
client. If not passed (and if no ``http`` object is
102+
client. If not passed (and if no ``_http`` object is
103103
passed), falls back to the default inferred from the
104104
environment.
105105
106-
:type http: :class:`~httplib2.Http`
107-
:param http: (Optional) HTTP object to make requests. Can be any object
108-
that defines ``request()`` with the same interface as
109-
:meth:`~httplib2.Http.request`. If not passed, an
110-
``http`` object is created that is bound to the
111-
``credentials`` for the current object.
106+
:type _http: :class:`~httplib2.Http`
107+
:param _http: (Optional) HTTP object to make requests. Can be any object
108+
that defines ``request()`` with the same interface as
109+
:meth:`~httplib2.Http.request`. If not passed, an
110+
``_http`` object is created that is bound to the
111+
``credentials`` for the current object.
112+
This parameter should be considered private, and could
113+
change in the future.
112114
"""
113115

114116
SCOPE = None
@@ -117,16 +119,16 @@ class Client(_ClientFactoryMixin):
117119
Needs to be set by subclasses.
118120
"""
119121

120-
def __init__(self, credentials=None, http=None):
122+
def __init__(self, credentials=None, _http=None):
121123
if (credentials is not None and
122124
not isinstance(
123125
credentials, google.auth.credentials.Credentials)):
124126
raise ValueError(_GOOGLE_AUTH_CREDENTIALS_HELP)
125-
if credentials is None and http is None:
127+
if credentials is None and _http is None:
126128
credentials = get_credentials()
127129
self._credentials = google.auth.credentials.with_scopes_if_required(
128130
credentials, self.SCOPE)
129-
self._http_internal = http
131+
self._http_internal = _http
130132

131133
def __getstate__(self):
132134
"""Explicitly state that clients are not pickleable."""
@@ -188,21 +190,23 @@ class ClientWithProject(Client, _ClientProjectMixin):
188190
189191
:type credentials: :class:`~google.auth.credentials.Credentials`
190192
:param credentials: (Optional) The OAuth2 Credentials to use for this
191-
client. If not passed (and if no ``http`` object is
193+
client. If not passed (and if no ``_http`` object is
192194
passed), falls back to the default inferred from the
193195
environment.
194196
195-
:type http: :class:`~httplib2.Http`
196-
:param http: (Optional) HTTP object to make requests. Can be any object
197-
that defines ``request()`` with the same interface as
198-
:meth:`~httplib2.Http.request`. If not passed, an
199-
``http`` object is created that is bound to the
200-
``credentials`` for the current object.
197+
:type _http: :class:`~httplib2.Http`
198+
:param _http: (Optional) HTTP object to make requests. Can be any object
199+
that defines ``request()`` with the same interface as
200+
:meth:`~httplib2.Http.request`. If not passed, an
201+
``_http`` object is created that is bound to the
202+
``credentials`` for the current object.
203+
This parameter should be considered private, and could
204+
change in the future.
201205
202206
:raises: :class:`ValueError` if the project is neither passed in nor
203207
set in the environment.
204208
"""
205209

206-
def __init__(self, project=None, credentials=None, http=None):
210+
def __init__(self, project=None, credentials=None, _http=None):
207211
_ClientProjectMixin.__init__(self, project=project)
208-
Client.__init__(self, credentials=credentials, http=http)
212+
Client.__init__(self, credentials=credentials, _http=_http)

core/tests/unit/test_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def mock_get_credentials():
7878
def test_ctor_explicit(self):
7979
CREDENTIALS = _make_credentials()
8080
HTTP = object()
81-
client_obj = self._make_one(credentials=CREDENTIALS, http=HTTP)
81+
client_obj = self._make_one(credentials=CREDENTIALS, _http=HTTP)
8282

8383
self.assertIs(client_obj._credentials, CREDENTIALS)
8484
self.assertIs(client_obj._http_internal, HTTP)
@@ -116,7 +116,7 @@ def test_from_service_account_json_bad_args(self):
116116
def test__http_property_existing(self):
117117
credentials = _make_credentials()
118118
http = object()
119-
client = self._make_one(credentials=credentials, http=http)
119+
client = self._make_one(credentials=credentials, _http=http)
120120
self.assertIs(client._http_internal, http)
121121
self.assertIs(client._http, http)
122122

@@ -196,7 +196,7 @@ def test_ctor_w_invalid_project(self):
196196
HTTP = object()
197197
with self.assertRaises(ValueError):
198198
self._make_one(project=object(), credentials=CREDENTIALS,
199-
http=HTTP)
199+
_http=HTTP)
200200

201201
def _explicit_ctor_helper(self, project):
202202
import six
@@ -205,7 +205,7 @@ def _explicit_ctor_helper(self, project):
205205
HTTP = object()
206206

207207
client_obj = self._make_one(project=project, credentials=CREDENTIALS,
208-
http=HTTP)
208+
_http=HTTP)
209209

210210
if isinstance(project, six.binary_type):
211211
self.assertEqual(client_obj.project, project.decode('utf-8'))

datastore/google/cloud/datastore/client.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
_DATASTORE_BASE_URL = 'https://datastore.googleapis.com'
4646
"""Datastore API request URL base."""
4747

48-
_USE_GAX = _HAVE_GRPC and not os.getenv(DISABLE_GRPC, False)
48+
_USE_GRPC = _HAVE_GRPC and not os.getenv(DISABLE_GRPC, False)
4949

5050

5151
def _get_gcd_project():
@@ -173,38 +173,42 @@ class Client(ClientWithProject):
173173
174174
:type credentials: :class:`~google.auth.credentials.Credentials`
175175
:param credentials: (Optional) The OAuth2 Credentials to use for this
176-
client. If not passed (and if no ``http`` object is
176+
client. If not passed (and if no ``_http`` object is
177177
passed), falls back to the default inferred from the
178178
environment.
179179
180-
:type http: :class:`~httplib2.Http`
181-
:param http: (Optional) HTTP object to make requests. Can be any object
182-
that defines ``request()`` with the same interface as
183-
:meth:`~httplib2.Http.request`. If not passed, an
184-
``http`` object is created that is bound to the
185-
``credentials`` for the current object.
186-
187-
:type use_gax: bool
188-
:param use_gax: (Optional) Explicitly specifies whether
189-
to use the gRPC transport (via GAX) or HTTP. If unset,
190-
falls back to the ``GOOGLE_CLOUD_DISABLE_GRPC`` environment
191-
variable.
180+
:type _http: :class:`~httplib2.Http`
181+
:param _http: (Optional) HTTP object to make requests. Can be any object
182+
that defines ``request()`` with the same interface as
183+
:meth:`~httplib2.Http.request`. If not passed, an
184+
``_http`` object is created that is bound to the
185+
``credentials`` for the current object.
186+
This parameter should be considered private, and could
187+
change in the future.
188+
189+
:type _use_grpc: bool
190+
:param _use_grpc: (Optional) Explicitly specifies whether
191+
to use the gRPC transport (via GAX) or HTTP. If unset,
192+
falls back to the ``GOOGLE_CLOUD_DISABLE_GRPC``
193+
environment variable.
194+
This parameter should be considered private, and could
195+
change in the future.
192196
"""
193197

194198
SCOPE = ('https://www.googleapis.com/auth/datastore',)
195199
"""The scopes required for authenticating as a Cloud Datastore consumer."""
196200

197201
def __init__(self, project=None, namespace=None,
198-
credentials=None, http=None, use_gax=None):
202+
credentials=None, _http=None, _use_grpc=None):
199203
super(Client, self).__init__(
200-
project=project, credentials=credentials, http=http)
204+
project=project, credentials=credentials, _http=_http)
201205
self.namespace = namespace
202206
self._batch_stack = _LocalStack()
203207
self._datastore_api_internal = None
204-
if use_gax is None:
205-
self._use_gax = _USE_GAX
208+
if _use_grpc is None:
209+
self._use_grpc = _USE_GRPC
206210
else:
207-
self._use_gax = use_gax
211+
self._use_grpc = _use_grpc
208212
try:
209213
host = os.environ[GCD_HOST]
210214
self._base_url = 'http://' + host
@@ -220,7 +224,7 @@ def _determine_default(project):
220224
def _datastore_api(self):
221225
"""Getter for a wrapped API object."""
222226
if self._datastore_api_internal is None:
223-
if self._use_gax:
227+
if self._use_grpc:
224228
self._datastore_api_internal = make_datastore_api(self)
225229
else:
226230
self._datastore_api_internal = HTTPDatastoreAPI(self)

datastore/tests/system/test_system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def clone_client(client):
4646
return datastore.Client(project=client.project,
4747
namespace=client.namespace,
4848
credentials=client._credentials,
49-
http=client._http)
49+
_http=client._http)
5050

5151

5252
def setUpModule():
@@ -61,7 +61,7 @@ def setUpModule():
6161
Config.CLIENT = datastore.Client(project=emulator_dataset,
6262
namespace=test_namespace,
6363
credentials=credentials,
64-
http=http)
64+
_http=http)
6565

6666

6767
def tearDownModule():

0 commit comments

Comments
 (0)