Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh #955: make datastore.Client derive from base client. #1004

Merged
merged 1 commit into from Jul 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 18 additions & 8 deletions gcloud/datastore/client.py
Expand Up @@ -18,6 +18,7 @@
from gcloud._helpers import _LocalStack
from gcloud._helpers import _app_engine_id
from gcloud._helpers import _compute_engine_id
from gcloud.client import Client as _BaseClient
from gcloud.datastore import helpers
from gcloud.datastore.connection import Connection
from gcloud.datastore.batch import Batch
Expand Down Expand Up @@ -158,7 +159,7 @@ def _extended_lookup(connection, dataset_id, key_pbs,
return results


class Client(object):
class Client(_BaseClient):
"""Convenience wrapper for invoking APIs/factories w/ a dataset ID.

:type dataset_id: string
Expand All @@ -167,20 +168,29 @@ class Client(object):
:type namespace: string
:param namespace: (optional) namespace to pass to proxied API methods.

:type connection: :class:`gcloud.datastore.connection.Connection`, or None
:param connection: (optional) connection 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
``http`` object is created that is bound to the
``credentials`` for the current object.
"""
_connection_class = Connection

def __init__(self, dataset_id=None, namespace=None, connection=None):
def __init__(self, dataset_id=None, namespace=None,
credentials=None, http=None):
dataset_id = _determine_default_dataset_id(dataset_id)
if dataset_id is None:
raise EnvironmentError('Dataset ID could not be inferred.')
self.dataset_id = dataset_id
if connection is None:
connection = Connection.from_environment()
self.connection = connection
self._batch_stack = _LocalStack()
self.namespace = namespace
self._batch_stack = _LocalStack()
super(Client, self).__init__(credentials, http)

def _push_batch(self, batch):
"""Push a batch/transaction onto our stack.
Expand Down