Skip to content

Commit

Permalink
Making datastore client inherit from base class.
Browse files Browse the repository at this point in the history
This required lots of changes since the tests assume
a client only optionally has a connection attached.
  • Loading branch information
dhermes committed Jun 26, 2015
1 parent a65c4ab commit 793d7a8
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 196 deletions.
26 changes: 19 additions & 7 deletions gcloud/datastore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@
# limitations under the License.
"""Convenience wrapper for invoking APIs/factories w/ a dataset ID."""

from gcloud.client import Client as BaseClient
from gcloud.datastore.api import delete
from gcloud.datastore.api import delete_multi
from gcloud.datastore.api import get
from gcloud.datastore.api import get_multi
from gcloud.datastore.api import put
from gcloud.datastore.api import put_multi
from gcloud.datastore.batch import Batch
from gcloud.datastore.connection import Connection
from gcloud.datastore.key import Key
from gcloud.datastore.query import Query
from gcloud.datastore.transaction import Transaction


class Client(object):
class Client(BaseClient):
"""Convenience wrapper for invoking APIs/factories w/ a dataset ID.
:type dataset_id: string
Expand All @@ -34,16 +36,26 @@ 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.
"""

def __init__(self, dataset_id, namespace=None, connection=None):
if dataset_id is None:
raise ValueError('dataset_id required')
_connection_class = Connection

def __init__(self, dataset_id, namespace=None,
credentials=None, http=None):
self.dataset_id = dataset_id
self.namespace = namespace
self.connection = connection
super(Client, self).__init__(credentials=credentials, http=http)

def get(self, key, missing=None, deferred=None):
"""Proxy to :func:`gcloud.datastore.api.get`.
Expand Down
Loading

0 comments on commit 793d7a8

Please sign in to comment.