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

Making datastore.connection.Connection inherit from base Connection. #198

Merged
merged 1 commit into from
Sep 29, 2014
Merged
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
30 changes: 3 additions & 27 deletions gcloud/datastore/connection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import httplib2

from gcloud import connection
from gcloud.datastore import datastore_v1_pb2 as datastore_pb
from gcloud.datastore import helpers
from gcloud.datastore.dataset import Dataset
from gcloud.datastore.transaction import Transaction


class Connection(object):
class Connection(connection.Connection):
"""A connection to the Google Cloud Datastore via the Protobuf API.

This class should understand only the basic types (and protobufs)
Expand All @@ -16,41 +17,16 @@ class Connection(object):
:param credentials: The OAuth2 Credentials to use for this connection.
"""

API_BASE_URL = 'https://www.googleapis.com'
"""The base of the API call URL."""

API_VERSION = 'v1beta2'
"""The version of the API, used in building the API call's URL."""

API_URL_TEMPLATE = ('{api_base}/datastore/{api_version}'
'/datasets/{dataset_id}/{method}')
"""A template used to craft the URL pointing toward a particular API call."""

_EMPTY = object()
"""A pointer to represent an empty value for default arguments."""

def __init__(self, credentials=None):
self._credentials = credentials
self._current_transaction = None
self._http = None

@property
def credentials(self):
return self._credentials

@property
def http(self):
"""A getter for the HTTP transport used in talking to the API.

:rtype: :class:`httplib2.Http`
:returns: A Http object used to transport data.
"""

if not self._http:
self._http = httplib2.Http()
if self._credentials:
self._http = self._credentials.authorize(self._http)
return self._http

def _request(self, dataset_id, method, data):
"""Make a request over the Http transport to the Cloud Datastore API.
Expand Down Expand Up @@ -117,7 +93,7 @@ def build_api_url(cls, dataset_id, method, base_url=None, api_version=None):
api_version=(api_version or cls.API_VERSION),
dataset_id=dataset_id, method=method)

def transaction(self, transaction=_EMPTY):
def transaction(self, transaction=connection.Connection._EMPTY):
if transaction is self._EMPTY:
return self._current_transaction
else:
Expand Down