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

Creating _generated pb directory for datastore #1328

Merged
merged 3 commits into from
Dec 24, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions gcloud/datastore/_generated/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Generated protobuf modules for Google Cloud Datastore API."""
12 changes: 6 additions & 6 deletions gcloud/datastore/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from gcloud.datastore import helpers
from gcloud.datastore.key import _dataset_ids_equal
from gcloud.datastore import _datastore_pb2
from gcloud.datastore._generated import datastore_pb2 as _datastore_pb2


class Batch(object):
Expand Down Expand Up @@ -101,7 +101,7 @@ def connection(self):
def _add_partial_key_entity_pb(self):
"""Adds a new mutation for an entity with a partial key.

:rtype: :class:`gcloud.datastore._entity_pb2.Entity`
:rtype: :class:`gcloud.datastore._generated.entity_pb2.Entity`
:returns: The newly created entity protobuf that will be
updated and sent with a commit.
"""
Expand All @@ -110,7 +110,7 @@ def _add_partial_key_entity_pb(self):
def _add_complete_key_entity_pb(self):
"""Adds a new mutation for an entity with a completed key.

:rtype: :class:`gcloud.datastore._entity_pb2.Entity`
:rtype: :class:`gcloud.datastore._generated.entity_pb2.Entity`
:returns: The newly created entity protobuf that will be
updated and sent with a commit.
"""
Expand All @@ -119,7 +119,7 @@ def _add_complete_key_entity_pb(self):
def _add_delete_key_pb(self):
"""Adds a new mutation for a key to be deleted.

:rtype: :class:`gcloud.datastore._entity_pb2.Key`
:rtype: :class:`gcloud.datastore._generated.entity_pb2.Key`
:returns: The newly created key protobuf that will be
deleted when sent with a commit.
"""
Expand All @@ -136,7 +136,7 @@ def mutations(self):
This getter returns the Mutation protobuf that
has been built-up so far.

:rtype: :class:`gcloud.datastore._datastore_pb2.Mutation`
:rtype: :class:`gcloud.datastore._generated.datastore_pb2.Mutation`
:returns: The Mutation protobuf to be sent in the commit request.
"""
return self._mutation
Expand Down Expand Up @@ -249,7 +249,7 @@ def _assign_entity_to_pb(entity_pb, entity):

Helper method for ``Batch.put``.

:type entity_pb: :class:`gcloud.datastore._entity_pb2.Entity`
:type entity_pb: :class:`gcloud.datastore._generated.entity_pb2.Entity`
:param entity_pb: The entity owned by a mutation.

:type entity: :class:`gcloud.datastore.entity.Entity`
Expand Down
4 changes: 2 additions & 2 deletions gcloud/datastore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _extended_lookup(connection, dataset_id, key_pbs,
:type dataset_id: string
:param dataset_id: The ID of the dataset of which to make the request.

:type key_pbs: list of :class:`gcloud.datastore._entity_pb2.Key`
:type key_pbs: list of :class:`gcloud.datastore._generated.entity_pb2.Key`
:param key_pbs: The keys to retrieve from the datastore.

:type missing: an empty list or None.
Expand All @@ -113,7 +113,7 @@ def _extended_lookup(connection, dataset_id, key_pbs,
the given transaction. Incompatible with
``eventual==True``.

:rtype: list of :class:`gcloud.datastore._entity_pb2.Entity`
:rtype: list of :class:`gcloud.datastore._generated.entity_pb2.Entity`
:returns: The requested entities.
:raises: :class:`ValueError` if missing / deferred are not null or
empty list.
Expand Down
42 changes: 22 additions & 20 deletions gcloud/datastore/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from gcloud import connection
from gcloud.environment_vars import GCD_HOST
from gcloud.exceptions import make_exception
from gcloud.datastore import _datastore_pb2
from gcloud.datastore import _entity_pb2
from gcloud.datastore._generated import datastore_pb2 as _datastore_pb2
from gcloud.datastore._generated import entity_pb2 as _entity_pb2


class Connection(connection.Connection):
Expand Down Expand Up @@ -151,8 +151,8 @@ def lookup(self, dataset_id, key_pbs,
Maps the ``DatastoreService.Lookup`` protobuf RPC.

This method deals only with protobufs
(:class:`gcloud.datastore._entity_pb2.Key` and
:class:`gcloud.datastore._entity_pb2.Entity`) and is used
(:class:`gcloud.datastore._generated.entity_pb2.Key` and
:class:`gcloud.datastore._generated.entity_pb2.Entity`) and is used
under the hood in :func:`gcloud.datastore.get`:

>>> from gcloud import datastore
Expand All @@ -168,7 +168,8 @@ def lookup(self, dataset_id, key_pbs,
:type dataset_id: string
:param dataset_id: The ID of the dataset to look up the keys.

:type key_pbs: list of :class:`gcloud.datastore._entity_pb2.Key`
:type key_pbs: list of
:class:`gcloud.datastore._generated.entity_pb2.Key`
:param key_pbs: The keys to retrieve from the datastore.

:type eventual: boolean
Expand All @@ -184,9 +185,9 @@ def lookup(self, dataset_id, key_pbs,
:rtype: tuple
:returns: A triple of (``results``, ``missing``, ``deferred``) where
both ``results`` and ``missing`` are lists of
:class:`gcloud.datastore._entity_pb2.Entity` and
:class:`gcloud.datastore._generated.entity_pb2.Entity` and
``deferred`` is a list of
:class:`gcloud.datastore._entity_pb2.Key`.
:class:`gcloud.datastore._generated.entity_pb2.Key`.
"""
lookup_request = _datastore_pb2.LookupRequest()
_set_read_options(lookup_request, eventual, transaction_id)
Expand Down Expand Up @@ -239,7 +240,7 @@ def run_query(self, dataset_id, query_pb, namespace=None,
:type dataset_id: string
:param dataset_id: The ID of the dataset over which to run the query.

:type query_pb: :class:`gcloud.datastore._query_pb2.Query`
:type query_pb: :class:`gcloud.datastore._generated.query_pb2.Query`
:param query_pb: The Protobuf representing the query to run.

:type namespace: string
Expand Down Expand Up @@ -279,7 +280,7 @@ def begin_transaction(self, dataset_id):
:type dataset_id: string
:param dataset_id: The ID dataset to which the transaction applies.

:rtype: :class:`._datastore_pb2.BeginTransactionResponse`
:rtype: :class:`._generated.datastore_pb2.BeginTransactionResponse`
:returns': the result protobuf for the begin transaction request.
"""
request = _datastore_pb2.BeginTransactionRequest()
Expand All @@ -297,7 +298,7 @@ def commit(self, dataset_id, mutation_pb, transaction_id):
:type dataset_id: string
:param dataset_id: The ID dataset to which the transaction applies.

:type mutation_pb: :class:`._datastore_pb2.Mutation`
:type mutation_pb: :class:`._generated.datastore_pb2.Mutation`
:param mutation_pb: The protobuf for the mutations being saved.

:type transaction_id: string or None
Expand All @@ -307,8 +308,8 @@ def commit(self, dataset_id, mutation_pb, transaction_id):

:rtype: tuple
:returns': The pair of the number of index updates and a list of
:class:`._entity_pb2.Key` for each incomplete key that was
completed in the commit.
:class:`._generated.entity_pb2.Key` for each incomplete key
that was completed in the commit.
"""
request = _datastore_pb2.CommitRequest()

Expand Down Expand Up @@ -351,10 +352,11 @@ def allocate_ids(self, dataset_id, key_pbs):
:param dataset_id: The ID of the dataset to which the transaction
belongs.

:type key_pbs: list of :class:`gcloud.datastore._entity_pb2.Key`
:type key_pbs: list of
:class:`gcloud.datastore._generated.entity_pb2.Key`
:param key_pbs: The keys for which the backend should allocate IDs.

:rtype: list of :class:`gcloud.datastore._entity_pb2.Key`
:rtype: list of :class:`gcloud.datastore._generated.entity_pb2.Key`
:returns: An equal number of keys, with IDs filled in by the backend.
"""
request = _datastore_pb2.AllocateIdsRequest()
Expand Down Expand Up @@ -390,10 +392,10 @@ def _prepare_key_for_request(key_pb): # pragma: NO COVER copied from helpers
This is copied from `helpers` to avoid a cycle:
_implicit_environ -> connection -> helpers -> key -> _implicit_environ

:type key_pb: :class:`gcloud.datastore._entity_pb2.Key`
:type key_pb: :class:`gcloud.datastore._generated.entity_pb2.Key`
:param key_pb: A key to be added to a request.

:rtype: :class:`gcloud.datastore._entity_pb2.Key`
:rtype: :class:`gcloud.datastore._generated.entity_pb2.Key`
:returns: A key which will be added to a request. It will be the
original if nothing needs to be changed.
"""
Expand All @@ -411,7 +413,7 @@ def _add_keys_to_request(request_field_pb, key_pbs):
:type request_field_pb: `RepeatedCompositeFieldContainer`
:param request_field_pb: A repeated proto field that contains keys.

:type key_pbs: list of :class:`gcloud.datastore._entity_pb2.Key`
:type key_pbs: list of :class:`gcloud.datastore._generated.entity_pb2.Key`
:param key_pbs: The keys to add to a request.
"""
for key_pb in key_pbs:
Expand All @@ -422,13 +424,13 @@ def _add_keys_to_request(request_field_pb, key_pbs):
def _parse_commit_response(commit_response_pb):
"""Extract response data from a commit response.

:type commit_response_pb: :class:`._datastore_pb2.CommitResponse`
:type commit_response_pb: :class:`._generated.datastore_pb2.CommitResponse`
:param commit_response_pb: The protobuf response from a commit request.

:rtype: tuple
:returns': The pair of the number of index updates and a list of
:class:`._entity_pb2.Key` for each incomplete key that was
completed in the commit.
:class:`._generated.entity_pb2.Key` for each incomplete key
that was completed in the commit.
"""
mut_result = commit_response_pb.mutation_result
index_updates = mut_result.index_updates
Expand Down
18 changes: 9 additions & 9 deletions gcloud/datastore/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from gcloud._helpers import _datetime_from_microseconds
from gcloud._helpers import _microseconds_from_datetime
from gcloud.datastore import _entity_pb2
from gcloud.datastore._generated import entity_pb2 as _entity_pb2
from gcloud.datastore.entity import Entity
from gcloud.datastore.key import Key

Expand Down Expand Up @@ -76,7 +76,7 @@ def find_true_dataset_id(dataset_id, connection):
def _get_meaning(value_pb, is_list=False):
"""Get the meaning from a protobuf value.

:type value_pb: :class:`gcloud.datastore._entity_pb2.Value`
:type value_pb: :class:`gcloud.datastore._generated.entity_pb2.Value`
:param value_pb: The protobuf value to be checked for an
associated meaning.

Expand Down Expand Up @@ -121,7 +121,7 @@ def entity_from_protobuf(pb):
The protobuf should be one returned from the Cloud Datastore
Protobuf API.

:type pb: :class:`gcloud.datastore._entity_pb2.Entity`
:type pb: :class:`gcloud.datastore._generated.entity_pb2.Entity`
:param pb: The Protobuf representing the entity.

:rtype: :class:`gcloud.datastore.entity.Entity`
Expand Down Expand Up @@ -173,7 +173,7 @@ def entity_to_protobuf(entity):
:type entity: :class:`gcloud.datastore.entity.Entity`
:param entity: The entity to be turned into a protobuf.

:rtype: :class:`gcloud.datastore._entity_pb2.Entity`
:rtype: :class:`gcloud.datastore._generated.entity_pb2.Entity`
:returns: The protobuf representing the entity.
"""
entity_pb = _entity_pb2.Entity()
Expand Down Expand Up @@ -223,7 +223,7 @@ def key_from_protobuf(pb):
The protobuf should be one returned from the Cloud Datastore
Protobuf API.

:type pb: :class:`gcloud.datastore._entity_pb2.Key`
:type pb: :class:`gcloud.datastore._generated.entity_pb2.Key`
:param pb: The Protobuf representing the key.

:rtype: :class:`gcloud.datastore.key.Key`
Expand Down Expand Up @@ -317,7 +317,7 @@ def _get_value_from_value_pb(value_pb):
Some work is done to coerce the return value into a more useful type
(particularly in the case of a timestamp value, or a key value).

:type value_pb: :class:`gcloud.datastore._entity_pb2.Value`
:type value_pb: :class:`gcloud.datastore._generated.entity_pb2.Value`
:param value_pb: The Value Protobuf.

:returns: The value provided by the Protobuf.
Expand Down Expand Up @@ -364,7 +364,7 @@ def _set_protobuf_value(value_pb, val):
Some value types (entities, keys, lists) cannot be directly
assigned; this function handles them correctly.

:type value_pb: :class:`gcloud.datastore._entity_pb2.Value`
:type value_pb: :class:`gcloud.datastore._generated.entity_pb2.Value`
:param value_pb: The value protobuf to which the value is being assigned.

:type val: :class:`datetime.datetime`, boolean, float, integer, string,
Expand Down Expand Up @@ -394,10 +394,10 @@ def _set_protobuf_value(value_pb, val):
def _prepare_key_for_request(key_pb):
"""Add protobuf keys to a request object.

:type key_pb: :class:`gcloud.datastore._entity_pb2.Key`
:type key_pb: :class:`gcloud.datastore._generated.entity_pb2.Key`
:param key_pb: A key to be added to a request.

:rtype: :class:`gcloud.datastore._entity_pb2.Key`
:rtype: :class:`gcloud.datastore._generated.entity_pb2.Key`
:returns: A key which will be added to a request. It will be the
original if nothing needs to be changed.
"""
Expand Down
4 changes: 2 additions & 2 deletions gcloud/datastore/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import copy
import six

from gcloud.datastore import _entity_pb2
from gcloud.datastore._generated import entity_pb2 as _entity_pb2


class Key(object):
Expand Down Expand Up @@ -235,7 +235,7 @@ def completed_key(self, id_or_name):
def to_protobuf(self):
"""Return a protobuf corresponding to the key.

:rtype: :class:`gcloud.datastore._entity_pb2.Key`
:rtype: :class:`gcloud.datastore._generated.entity_pb2.Key`
:returns: The protobuf representing the key.
"""
key = _entity_pb2.Key()
Expand Down
4 changes: 2 additions & 2 deletions gcloud/datastore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import base64

from gcloud._helpers import _ensure_tuple_or_list
from gcloud.datastore import _query_pb2
from gcloud.datastore._generated import query_pb2 as _query_pb2
from gcloud.datastore import helpers
from gcloud.datastore.key import Key

Expand Down Expand Up @@ -456,7 +456,7 @@ def _pb_from_query(query):
:type query: :class:`Query`
:param query: The source query.

:rtype: :class:`gcloud.datastore._query_pb2.Query`
:rtype: :class:`gcloud.datastore._generated.query_pb2.Query`
:returns: A protobuf that can be sent to the protobuf API. N.b. that
it does not contain "in-flight" fields for ongoing query
executions (cursors, offset, limit).
Expand Down
8 changes: 4 additions & 4 deletions gcloud/datastore/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _makeOne(self, client):
return self._getTargetClass()(client)

def test_ctor(self):
from gcloud.datastore._datastore_pb2 import Mutation
from gcloud.datastore._generated import datastore_pb2
_DATASET = 'DATASET'
_NAMESPACE = 'NAMESPACE'
connection = _Connection()
Expand All @@ -37,7 +37,7 @@ def test_ctor(self):
self.assertEqual(batch.connection, connection)
self.assertEqual(batch.namespace, _NAMESPACE)
self.assertTrue(batch._id is None)
self.assertTrue(isinstance(batch.mutations, Mutation))
self.assertTrue(isinstance(batch.mutations, datastore_pb2.Mutation))
self.assertEqual(batch._partial_key_entities, [])

def test_current(self):
Expand Down Expand Up @@ -350,8 +350,8 @@ def is_partial(self):
return self._id is None

def to_protobuf(self):
from gcloud.datastore import _entity_pb2
key = self._key = _entity_pb2.Key()
from gcloud.datastore._generated import entity_pb2
key = self._key = entity_pb2.Key()
# Don't assign it, because it will just get ripped out
# key.partition_id.dataset_id = self.dataset_id

Expand Down
Loading