Skip to content

Commit

Permalink
Renaming http argument(s) as _http. (#3235)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes authored and lukesneeringer committed Mar 30, 2017
1 parent aa5eeeb commit cb12e14
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 46 deletions.
46 changes: 25 additions & 21 deletions packages/google-cloud-vision/google/cloud/vision/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from google.cloud.vision.image import Image


_USE_GAX = not os.getenv(DISABLE_GRPC, False)
_USE_GRPC = not os.getenv(DISABLE_GRPC, False)


class Client(ClientWithProject):
Expand All @@ -38,37 +38,41 @@ class Client(ClientWithProject):
:type credentials: :class:`~google.auth.credentials.Credentials`
:param credentials: (Optional) The OAuth2 Credentials to use for this
client. If not passed (and if no ``http`` object is
client. If not passed (and if no ``_http`` object is
passed), falls back to the default inferred from the
environment.
:type http: :class:`~httplib2.Http`
:param http: (Optional) HTTP object to make requests. Can be any object
that defines ``request()`` with the same interface as
:meth:`~httplib2.Http.request`. If not passed, an
``http`` object is created that is bound to the
``credentials`` for the current object.
:type use_gax: bool
:param use_gax: (Optional) Explicitly specifies whether
to use the gRPC transport (via GAX) or HTTP. If unset,
falls back to the ``GOOGLE_CLOUD_DISABLE_GRPC`` environment
variable
:type _http: :class:`~httplib2.Http`
:param _http: (Optional) HTTP object to make requests. Can be any object
that defines ``request()`` with the same interface as
:meth:`~httplib2.Http.request`. If not passed, an
``_http`` object is created that is bound to the
``credentials`` for the current object.
This parameter should be considered private, and could
change in the future.
:type _use_grpc: bool
:param _use_grpc: (Optional) Explicitly specifies whether
to use the gRPC transport (via GAX) or HTTP. If unset,
falls back to the ``GOOGLE_CLOUD_DISABLE_GRPC``
environment variable.
This parameter should be considered private, and could
change in the future.
"""

SCOPE = ('https://www.googleapis.com/auth/cloud-platform',)
"""The scopes required for authenticating as a Cloud Vision consumer."""

_vision_api_internal = None

def __init__(self, project=None, credentials=None, http=None,
use_gax=None):
def __init__(self, project=None, credentials=None, _http=None,
_use_grpc=None):
super(Client, self).__init__(
project=project, credentials=credentials, http=http)
if use_gax is None:
self._use_gax = _USE_GAX
project=project, credentials=credentials, _http=_http)
if _use_grpc is None:
self._use_grpc = _USE_GRPC
else:
self._use_gax = use_gax
self._use_grpc = _use_grpc

def batch(self):
"""Batch multiple images into a single API request.
Expand Down Expand Up @@ -106,7 +110,7 @@ def _vision_api(self):
make requests.
"""
if self._vision_api_internal is None:
if self._use_gax:
if self._use_grpc:
self._vision_api_internal = _GAPICVisionAPI(self)
else:
self._vision_api_internal = _HTTPVisionAPI(self)
Expand Down
2 changes: 1 addition & 1 deletion packages/google-cloud-vision/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _assert_likelihood(self, likelihood):
self.assertIn(likelihood, levels)

def _pb_not_implemented_skip(self, message):
if Config.CLIENT._use_gax:
if Config.CLIENT._use_grpc:
self.skipTest(message)


Expand Down
48 changes: 24 additions & 24 deletions packages/google-cloud-vision/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_make_gax_client(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=None)
project=PROJECT, credentials=credentials, _use_grpc=None)
vision_api = client._vision_api
vision_api._connection = _Connection()
with mock.patch('google.cloud.vision.client._GAPICVisionAPI',
Expand All @@ -75,7 +75,7 @@ def test_make_http_client(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
self.assertIsInstance(client._vision_api, _HTTPVisionAPI)

def test_face_annotation(self):
Expand All @@ -101,7 +101,7 @@ def test_face_annotation(self):
}
credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
connection = _Connection(returned)
vision_api._connection = connection
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_image_with_client_raw_content(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
raw_image = client.image(content=IMAGE_CONTENT)
self.assertIsInstance(raw_image, Image)
self.assertEqual(raw_image.content, IMAGE_CONTENT)
Expand All @@ -145,7 +145,7 @@ def test_image_with_client_filename(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
with patch('google.cloud.vision.image.open',
mock_open(read_data=IMAGE_CONTENT)) as m:
file_image = client.image(filename='my_image.jpg')
Expand All @@ -166,7 +166,7 @@ def test_multiple_detection_from_content(self):

credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
_use_grpc=False)
vision_api = client._vision_api
connection = _Connection(returned)
vision_api._connection = connection
Expand Down Expand Up @@ -218,7 +218,7 @@ def test_detect_crop_hints_from_source(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
api = client._vision_api
api._connection = _Connection(CROP_HINTS_RESPONSE)
image = client.image(source_uri=IMAGE_SOURCE)
Expand All @@ -241,7 +241,7 @@ def test_face_detection_from_source(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
connection = _Connection(FACE_DETECTION_RESPONSE)
vision_api._connection = connection
Expand All @@ -263,7 +263,7 @@ def test_face_detection_from_content(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
connection = _Connection(FACE_DETECTION_RESPONSE)
vision_api._connection = connection
Expand All @@ -284,7 +284,7 @@ def test_face_detection_from_content_no_results(self):
}
credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
connection = _Connection(returned)
vision_api._connection = connection
Expand All @@ -305,7 +305,7 @@ def test_detect_full_text_annotation(self):
returned = FULL_TEXT_RESPONSE
credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
api = client._vision_api
api._connection = _Connection(returned)
image = client.image(source_uri=IMAGE_SOURCE)
Expand Down Expand Up @@ -339,7 +339,7 @@ def test_label_detection_from_source(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
connection = _Connection(LABEL_DETECTION_RESPONSE)
vision_api._connection = connection
Expand All @@ -364,7 +364,7 @@ def test_label_detection_no_results(self):
}
credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
vision_api._connection = _Connection(returned)

Expand All @@ -379,7 +379,7 @@ def test_landmark_detection_from_source(self):

credentials = _make_credentials()
client = self._make_one(project=PROJECT, credentials=credentials,
use_gax=False)
_use_grpc=False)
vision_api = client._vision_api
connection = _Connection(LANDMARK_DETECTION_RESPONSE)
vision_api._connection = connection
Expand All @@ -405,7 +405,7 @@ def test_landmark_detection_from_content(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
connection = _Connection(LANDMARK_DETECTION_RESPONSE)
vision_api._connection = connection
Expand All @@ -425,7 +425,7 @@ def test_landmark_detection_no_results(self):
}
credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
vision_api._connection = _Connection(returned)

Expand All @@ -440,7 +440,7 @@ def test_logo_detection_from_source(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
connection = _Connection(LOGO_DETECTION_RESPONSE)
vision_api._connection = connection
Expand All @@ -461,7 +461,7 @@ def test_logo_detection_from_content(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
connection = _Connection(LOGO_DETECTION_RESPONSE)
vision_api._connection = connection
Expand All @@ -481,7 +481,7 @@ def test_text_detection_from_source(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
connection = _Connection(TEXT_DETECTION_RESPONSE)
vision_api._connection = connection
Expand All @@ -507,7 +507,7 @@ def test_safe_search_detection_from_source(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
connection = _Connection(SAFE_SEARCH_DETECTION_RESPONSE)
vision_api._connection = connection
Expand All @@ -530,7 +530,7 @@ def test_safe_search_no_results(self):
}
credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
vision_api._connection = _Connection(returned)

Expand All @@ -545,7 +545,7 @@ def test_image_properties_detection_from_source(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
connection = _Connection(IMAGE_PROPERTIES_RESPONSE)
vision_api._connection = connection
Expand All @@ -570,7 +570,7 @@ def test_image_properties_no_results(self):
}
credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
vision_api = client._vision_api
vision_api._connection = _Connection(returned)

Expand All @@ -587,7 +587,7 @@ def test_detect_web_detection(self):

credentials = _make_credentials()
client = self._make_one(
project=PROJECT, credentials=credentials, use_gax=False)
project=PROJECT, credentials=credentials, _use_grpc=False)
api = client._vision_api
api._connection = _Connection(WEB_DETECTION_RESPONSE)
image = client.image(source_uri=IMAGE_SOURCE)
Expand Down

0 comments on commit cb12e14

Please sign in to comment.