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

Fixed a majority of pep8 errors in gcloud. #200

Merged
merged 6 commits into from
Oct 1, 2014
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
1 change: 0 additions & 1 deletion gcloud/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ def http(self):
if self._credentials:
self._http = self._credentials.authorize(self._http)
return self._http

1 change: 1 addition & 0 deletions gcloud/datastore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def get_connection(client_email, private_key_path):
client_email, private_key_path, scope=SCOPE)
return Connection(credentials=credentials)


def get_dataset(dataset_id, client_email, private_key_path):
"""Shortcut method to establish a connection to a particular dataset in the Cloud Datastore.

This comment was marked as spam.


Expand Down
8 changes: 5 additions & 3 deletions gcloud/datastore/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _request(self, dataset_id, method, data):
headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': str(len(data)),
}
}
headers, content = self.http.request(
uri=self.build_api_url(dataset_id=dataset_id, method=method),
method='POST', headers=headers, body=data)
Expand Down Expand Up @@ -132,7 +132,8 @@ def begin_transaction(self, dataset_id, serializable=False):
request = datastore_pb.BeginTransactionRequest()

if serializable:
request.isolation_level = datastore_pb.BeginTransactionRequest.SERIALIZABLE
request.isolation_level = (
datastore_pb.BeginTransactionRequest.SERIALIZABLE)
else:
request.isolation_level = datastore_pb.BeginTransactionRequest.SNAPSHOT

Expand Down Expand Up @@ -202,7 +203,8 @@ def run_query(self, dataset_id, query_pb, namespace=None):
request.partition_id.namespace = namespace

request.query.CopyFrom(query_pb)
response = self._rpc(dataset_id, 'runQuery', request, datastore_pb.RunQueryResponse)
response = self._rpc(dataset_id, 'runQuery', request,
datastore_pb.RunQueryResponse)
return [e.entity for e in response.batch.entity_result]

def lookup(self, dataset_id, key_pbs):
Expand Down
6 changes: 4 additions & 2 deletions gcloud/datastore/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ def get_entities(self, keys):
# This import is here to avoid circular references.
from gcloud.datastore.entity import Entity

entity_pbs = self.connection().lookup(dataset_id=self.id(),
key_pbs=[k.to_protobuf() for k in keys])
entity_pbs = self.connection().lookup(
dataset_id=self.id(),
key_pbs=[k.to_protobuf() for k in keys]
)

entities = []
for entity_pb in entity_pbs:
Expand Down
5 changes: 3 additions & 2 deletions gcloud/datastore/demo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
__all__ = ['get_dataset', 'CLIENT_EMAIL', 'DATASET_ID', 'PRIVATE_KEY_PATH']


CLIENT_EMAIL = '754762820716-gimou6egs2hq1rli7el2t621a1b04t9i@developer.gserviceaccount.com'
CLIENT_EMAIL = ('754762820716-gimou6egs2hq1rli7el2t621a1b04t9i'
'@developer.gserviceaccount.com')
DATASET_ID = 'gcloud-datastore-demo'
PRIVATE_KEY_PATH = os.path.join(os.path.dirname(__file__), 'demo.key')


def get_dataset(): #pragma NO COVER
def get_dataset(): # pragma NO COVER

This comment was marked as spam.

This comment was marked as spam.

return datastore.get_dataset(DATASET_ID, CLIENT_EMAIL, PRIVATE_KEY_PATH)
22 changes: 14 additions & 8 deletions gcloud/datastore/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,22 @@ class Entity(dict):
>>> dataset.entity('MyEntityKind')
<Entity[{'kind': 'MyEntityKind'}] {}>

- :func:`gcloud.datastore.dataset.Dataset.get_entity` to retrive an existing entity.
- :func:`gcloud.datastore.dataset.Dataset.get_entity`

This comment was marked as spam.

to retrieve an existing entity.

>>> dataset.get_entity(key)
<Entity[{'kind': 'EntityKind', id: 1234}] {'property': 'value'}>

You can the set values on the entity just like you would on any other dictionary.
You can the set values on the entity
just like you would on any other dictionary.

>>> entity['age'] = 20
>>> entity['name'] = 'JJ'
>>> entity
<Entity[{'kind': 'EntityKind', id: 1234}] {'age': 20, 'name': 'JJ'}>

And you can cast an entity to a regular Python dictionary with the `dict` builtin:
And you can cast an entity to a regular Python dictionary
with the `dict` builtin:

>>> dict(entity)
{'age': 20, 'name': 'JJ'}
Expand All @@ -68,7 +71,7 @@ def __init__(self, dataset=None, kind=None):
self._key = None

def dataset(self):
"""Get the :class:`gcloud.datastore.dataset.Dataset` in which this entity belonds.
"""Get the :class:`gcloud.datastore.dataset.Dataset` in which this entity belongs.

.. note::
This is based on the :class:`gcloud.datastore.key.Key` set on the entity.
Expand Down Expand Up @@ -121,7 +124,8 @@ def from_key(cls, key):
:type key: :class:`gcloud.datastore.key.Key`
:param key: The key for the entity.

:returns: The :class:`Entity` derived from the :class:`gcloud.datastore.key.Key`.
:returns: The :class:`Entity` derived from the
:class:`gcloud.datastore.key.Key`.
"""

return cls().key(key)
Expand All @@ -135,7 +139,8 @@ def from_protobuf(cls, pb, dataset=None):
:type key: :class:`gcloud.datastore.datastore_v1_pb2.Entity`
:param key: The Protobuf representing the entity.

:returns: The :class:`Entity` derived from the :class:`gcloud.datastore.datastore_v1_pb2.Entity`.
:returns: The :class:`Entity` derived from the
:class:`gcloud.datastore.datastore_v1_pb2.Entity`.
"""

# This is here to avoid circular imports.
Expand Down Expand Up @@ -205,9 +210,10 @@ def delete(self):
self.dataset().connection().delete_entity(
dataset_id=self.dataset().id(), key_pb=self.key().to_protobuf())

def __repr__(self): #pragma NO COVER
def __repr__(self): # pragma NO COVER
# An entity should have a key all the time (even if it's partial).
if self.key():
return '<Entity%s %s>' % (self.key().path(), super(Entity, self).__repr__())
return '<Entity%s %s>' % (self.key().path(),
super(Entity, self).__repr__())
else:
return '<Entity %s>' % (super(Entity, self).__repr__())
6 changes: 3 additions & 3 deletions gcloud/datastore/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, dataset=None, namespace=None, path=None):

:type path: sequence of dicts
:param path: Each dict must have keys 'kind' (a string) and optionally
'name' (a string) or 'id' (an integer).
'name' (a string) or 'id' (an integer).
"""
self._dataset = dataset
self._namespace = namespace
Expand Down Expand Up @@ -267,7 +267,7 @@ def id_or_name(self):
"""
return self.id() or self.name()

def parent(self):#pragma NO COVER
def parent(self): # pragma NO COVER
"""Getter: return a new key for the next highest element in path.

:rtype: :class:`gcloud.datastore.key.Key`
Expand All @@ -278,5 +278,5 @@ def parent(self):#pragma NO COVER
return None
return self.path(self.path()[:-1])

def __repr__(self): #pragma NO COVER
def __repr__(self): # pragma NO COVER
return '<Key%s>' % self.path()
2 changes: 1 addition & 1 deletion gcloud/datastore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Query(object):
'>': datastore_pb.PropertyFilter.GREATER_THAN,
'>=': datastore_pb.PropertyFilter.GREATER_THAN_OR_EQUAL,
'=': datastore_pb.PropertyFilter.EQUAL,
}
}
"""Mapping of operator strings and their protobuf equivalents."""

def __init__(self, kind=None, dataset=None):
Expand Down
8 changes: 6 additions & 2 deletions gcloud/datastore/test___init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest2


class Test_get_connection(unittest2.TestCase):

def _callFUT(self, client_email, private_key_path):
Expand All @@ -13,6 +14,7 @@ def test_it(self):
from gcloud.datastore.connection import Connection
from gcloud.test_credentials import _Client
from gcloud.test_credentials import _Monkey

CLIENT_EMAIL = 'phred@example.com'
PRIVATE_KEY = 'SEEkR1t'
client = _Client()
Expand All @@ -27,7 +29,8 @@ def test_it(self):
{'service_account_name': CLIENT_EMAIL,
'private_key': PRIVATE_KEY,
'scope': SCOPE,
})
})


class Test_get_dataset(unittest2.TestCase):

Expand All @@ -43,6 +46,7 @@ def test_it(self):
from gcloud.datastore.dataset import Dataset
from gcloud.test_credentials import _Client
from gcloud.test_credentials import _Monkey

CLIENT_EMAIL = 'phred@example.com'
PRIVATE_KEY = 'SEEkR1t'
DATASET_ID = 'DATASET'
Expand All @@ -59,4 +63,4 @@ def test_it(self):
{'service_account_name': CLIENT_EMAIL,
'private_key': PRIVATE_KEY,
'scope': SCOPE,
})
})
Loading