Skip to content

Commit

Permalink
Manually creating Client._connection in subclasses.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Dec 15, 2016
1 parent ae2d90c commit 2c42b7c
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 150 deletions.
25 changes: 15 additions & 10 deletions bigquery/google/cloud/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,25 @@ class Client(JSONClient):
passed when creating a dataset / job. If not passed,
falls back to the default inferred from the environment.
:type credentials: :class:`oauth2client.client.OAuth2Credentials` or
:class:`NoneType`
:param credentials: The OAuth2 Credentials to use for the connection
owned by this 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` or class that defines ``request()``.
:param http: An optional HTTP object to make requests. If not passed, an
: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
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.
"""

_connection_class = Connection
def __init__(self, project=None, credentials=None, http=None):
super(Client, self).__init__(
project=project, credentials=credentials, http=http)
self._connection = Connection(
credentials=self._credentials, http=self._http)

def list_projects(self, max_results=None, page_token=None):
"""List projects for the project associated with this client.
Expand Down
8 changes: 4 additions & 4 deletions core/google/cloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class Client(_ClientFactoryMixin):
: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
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.
"""
Expand Down Expand Up @@ -148,8 +148,8 @@ class JSONClient(Client, _ClientProjectMixin):
: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
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.
Expand Down
25 changes: 14 additions & 11 deletions datastore/google/cloud/datastore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,26 +157,29 @@ class Client(_BaseClient, _ClientProjectMixin):
:type namespace: str
:param namespace: (optional) namespace to pass to proxied API methods.
:type credentials: :class:`oauth2client.client.OAuth2Credentials` or
:class:`NoneType`
:param credentials: The OAuth2 Credentials to use for the connection
owned by this 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` or class that defines ``request()``.
:param http: An optional HTTP object to make requests. If not passed, an
: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
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.
"""
_connection_class = Connection

def __init__(self, project=None, namespace=None,
credentials=None, http=None):
_ClientProjectMixin.__init__(self, project=project)
_BaseClient.__init__(self, credentials=credentials, http=http)
self._connection = Connection(
credentials=self._credentials, http=self._http)

self.namespace = namespace
self._batch_stack = _LocalStack()
super(Client, self).__init__(credentials, http)

@staticmethod
def _determine_default(project):
Expand Down
12 changes: 7 additions & 5 deletions datastore/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@ class TestClient(unittest.TestCase):
PROJECT = 'PROJECT'

def setUp(self):
KLASS = self._get_target_class()
self.original_cnxn_class = KLASS._connection_class
KLASS._connection_class = _MockConnection
from google.cloud.datastore import client as MUT

self.original_cnxn_class = MUT.Connection
MUT.Connection = _MockConnection

def tearDown(self):
KLASS = self._get_target_class()
KLASS._connection_class = self.original_cnxn_class
from google.cloud.datastore import client as MUT

MUT.Connection = self.original_cnxn_class

@staticmethod
def _get_target_class():
Expand Down
25 changes: 15 additions & 10 deletions dns/google/cloud/dns/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,25 @@ class Client(JSONClient):
passed when creating a zone. If not passed,
falls back to the default inferred from the environment.
:type credentials: :class:`oauth2client.client.OAuth2Credentials` or
:class:`NoneType`
:param credentials: The OAuth2 Credentials to use for the connection
owned by this 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` or class that defines ``request()``.
:param http: An optional HTTP object to make requests. If not passed, an
: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
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.
"""

_connection_class = Connection
def __init__(self, project=None, credentials=None, http=None):
super(Client, self).__init__(
project=project, credentials=credentials, http=http)
self._connection = Connection(
credentials=self._credentials, http=self._http)

def quotas(self):
"""Return DNS quotas for the project associated with this client.
Expand Down
24 changes: 15 additions & 9 deletions language/google/cloud/language/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,25 @@
class Client(client_module.Client):
"""Client to bundle configuration needed for API requests.
:type credentials: :class:`~oauth2client.client.OAuth2Credentials`
:param credentials: (Optional) The OAuth2 Credentials to use for the
connection owned by this 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` or class that defines ``request()``.
:param http: An optional HTTP object to make requests. If not passed, an
: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
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.
"""

_connection_class = Connection
def __init__(self, credentials=None, http=None):
super(Client, self).__init__(
credentials=credentials, http=http)
self._connection = Connection(
credentials=self._credentials, http=self._http)

def document_from_text(self, content, **kwargs):
"""Create a plain text document bound to this client.
Expand Down
29 changes: 17 additions & 12 deletions logging/google/cloud/logging/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,16 @@ class Client(JSONClient):
If not passed, falls back to the default inferred
from the environment.
:type credentials: :class:`oauth2client.client.OAuth2Credentials` or
:class:`NoneType`
:param credentials: The OAuth2 Credentials to use for the connection
owned by this 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` or class that defines ``request()``.
:param http: An optional HTTP object to make requests. If not passed, an
: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
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.
Expand All @@ -86,12 +87,16 @@ class Client(JSONClient):
variable
"""

_connection_class = Connection
_logging_api = _sinks_api = _metrics_api = None
_logging_api = None
_sinks_api = None
_metrics_api = None

def __init__(self, project=None, credentials=None,
http=None, use_gax=None):
super(Client, self).__init__(project, credentials, http)
super(Client, self).__init__(
project=project, credentials=credentials, http=http)
self._connection = Connection(
credentials=self._credentials, http=self._http)
if use_gax is None:
self._use_gax = _USE_GAX
else:
Expand Down
25 changes: 15 additions & 10 deletions monitoring/google/cloud/monitoring/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,25 @@ class Client(JSONClient):
:param project: The target project. If not passed, falls back to the
default inferred from the environment.
:type credentials: :class:`oauth2client.client.OAuth2Credentials` or
:class:`NoneType`
:param credentials: The OAuth2 Credentials to use for the connection
owned by this 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` or class that defines ``request()``
:param http: An optional HTTP object to make requests. If not passed, an
: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
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.
"""

_connection_class = Connection
def __init__(self, project=None, credentials=None, http=None):
super(Client, self).__init__(
project=project, credentials=credentials, http=http)
self._connection = Connection(
credentials=self._credentials, http=self._http)

def query(self,
metric_type=Query.DEFAULT_METRIC_TYPE,
Expand Down
32 changes: 19 additions & 13 deletions pubsub/google/cloud/pubsub/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ class Client(JSONClient):
passed when creating a topic. If not passed,
falls back to the default inferred from the environment.
:type credentials: :class:`oauth2client.client.OAuth2Credentials` or
:class:`NoneType`
:param credentials: The OAuth2 Credentials to use for the connection
owned by this 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` or class that defines ``request()``.
:param http: An optional HTTP object to make requests. If not passed, an
: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
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.
Expand All @@ -69,17 +70,22 @@ class Client(JSONClient):
falls back to the ``GOOGLE_CLOUD_DISABLE_GRPC`` environment
variable
"""

_publisher_api = None
_subscriber_api = None
_iam_policy_api = None

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

_connection_class = Connection
_publisher_api = _subscriber_api = _iam_policy_api = None

@property
def publisher_api(self):
"""Helper for publisher-related API calls."""
Expand Down
25 changes: 15 additions & 10 deletions resource_manager/google/cloud/resource_manager/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,25 @@ class Client(BaseClient):
>>> from google.cloud import resource_manager
>>> client = resource_manager.Client()
:type credentials: :class:`oauth2client.client.OAuth2Credentials` or
:class:`NoneType`
:param credentials: The OAuth2 Credentials to use for the connection
owned by this 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` or class that defines ``request()``.
:param http: An optional HTTP object to make requests. If not passed, an
: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
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.
"""

_connection_class = Connection
def __init__(self, credentials=None, http=None):
super(Client, self).__init__(
credentials=credentials, http=http)
self._connection = Connection(
credentials=self._credentials, http=self._http)

def new_project(self, project_id, name=None, labels=None):
"""Create a project bound to the current client.
Expand Down
29 changes: 17 additions & 12 deletions runtimeconfig/google/cloud/runtimeconfig/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,25 @@ class Client(JSONClient):
(Optional) The project which the client acts on behalf of. If not
passed, falls back to the default inferred from the environment.
:type credentials: :class:`oauth2client.client.OAuth2Credentials`
:param credentials:
(Optional) The OAuth2 Credentials to use for the connection owned by
this 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` or class that defines ``request()``.
:param http:
(Optional) An HTTP object to make requests. If not passed, an ``http``
object is created that is bound to the ``credentials`` for the current
object.
: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
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.
"""

_connection_class = Connection
def __init__(self, project=None, credentials=None, http=None):
super(Client, self).__init__(
project=project, credentials=credentials, http=http)
self._connection = Connection(
credentials=self._credentials, http=self._http)

def config(self, config_name):
"""Factory constructor for config object.
Expand Down
Loading

0 comments on commit 2c42b7c

Please sign in to comment.