Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
Add basic helpers needed for GAPIC client in datastore.#3105
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,19 +19,30 @@ | ||
| from google.cloud._helpers import ( | ||
| _determine_default_project as _base_default_project) | ||
| from google.cloud.client import ClientWithProject | ||
| from google.cloud.environment_vars import DISABLE_GRPC | ||
| from google.cloud.environment_vars import GCD_DATASET | ||
| from google.cloud.datastore._http import Connection | ||
| from google.cloud.datastore._http import HTTPDatastoreAPI | ||
| from google.cloud.datastore import helpers | ||
| from google.cloud.datastore.batch import Batch | ||
| from google.cloud.datastore.entity import Entity | ||
| from google.cloud.datastore.key import Key | ||
| from google.cloud.datastore.query import Query | ||
| from google.cloud.datastore.transaction import Transaction | ||
| from google.cloud.environment_vars import GCD_DATASET | ||
| try: | ||
| from google.cloud.datastore._gax import make_datastore_api | ||
| _HAVE_GRPC = True | ||
| except ImportError: # pragma: NO COVER | ||
| make_datastore_api = None | ||
| _HAVE_GRPC = False | ||
| _MAX_LOOPS = 128 | ||
| """Maximum number of iterations to wait for deferred keys.""" | ||
| _USE_GAX = _HAVE_GRPC and not os.getenv(DISABLE_GRPC, False) | ||
| def _get_gcd_project(): | ||
| """Gets the GCD application ID if it can be inferred.""" | ||
| @@ -169,24 +180,45 @@ class Client(ClientWithProject): | ||
| :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. | ||
| """ | ||
| SCOPE = ('https://www.googleapis.com/auth/datastore',) | ||
| """The scopes required for authenticating as a Cloud Datastore consumer.""" | ||
| def __init__(self, project=None, namespace=None, | ||
| credentials=None, http=None): | ||
| credentials=None, http=None, use_gax=None): | ||
| super(Client, self).__init__( | ||
| project=project, credentials=credentials, http=http) | ||
| self._connection = Connection(self) | ||
| self.namespace = namespace | ||
| self._batch_stack = _LocalStack() | ||
| self._datastore_api_internal = None | ||
| if use_gax is None: | ||
| self._use_gax = _USE_GAX | ||
| else: | ||
| self._use_gax = use_gax | ||
| @staticmethod | ||
| def _determine_default(project): | ||
| """Helper: override default project detection.""" | ||
| return _determine_default_project(project) | ||
| @property | ||
| def _datastore_api(self): | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| """Getter for a wrapped API object.""" | ||
| if self._datastore_api_internal is None: | ||
| if self._use_gax: | ||
| self._datastore_api_internal = make_datastore_api(self) | ||
| else: | ||
| self._datastore_api_internal = HTTPDatastoreAPI(self) | ||
| return self._datastore_api_internal | ||
| def _push_batch(self, batch): | ||
| """Push a batch/transaction onto our stack. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.