Skip to content

Commit 20ab3b4

Browse files
committed
Updated datastore.entity by hand until fully passed pep8.
1 parent 4840c04 commit 20ab3b4

File tree

1 file changed

+93
-79
lines changed

1 file changed

+93
-79
lines changed

gcloud/datastore/entity.py

Lines changed: 93 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,46 @@
2323

2424
class Entity(dict):
2525
"""
26-
:type dataset: :class:`gcloud.datastore.dataset.Dataset`
27-
:param dataset: The dataset in which this entity belongs.
26+
:type dataset: :class:`gcloud.datastore.dataset.Dataset`
27+
:param dataset: The dataset in which this entity belongs.
2828
29-
:type kind: string
30-
:param kind: The kind of entity this is, akin to a table name in a
31-
relational database.
29+
:type kind: string
30+
:param kind: The kind of entity this is, akin to a table name in a
31+
relational database.
3232
33-
Entities are mutable and act like a subclass of a dictionary.
34-
This means you could take an existing entity and change the key
35-
to duplicate the object.
33+
Entities are mutable and act like a subclass of a dictionary.
34+
This means you could take an existing entity and change the key
35+
to duplicate the object.
3636
37-
This can be used on its own, however it is likely easier to use
38-
the shortcut methods provided by :class:`gcloud.datastore.dataset.Dataset`
39-
such as:
37+
This can be used on its own, however it is likely easier to use
38+
the shortcut methods provided by :class:`gcloud.datastore.dataset.Dataset`
39+
such as:
4040
41-
- :func:`gcloud.datastore.dataset.Dataset.entity` to create a new entity.
41+
- :func:`gcloud.datastore.dataset.Dataset.entity` to create a new entity.
4242
43-
>>> dataset.entity('MyEntityKind')
44-
<Entity[{'kind': 'MyEntityKind'}] {}>
43+
>>> dataset.entity('MyEntityKind')
44+
<Entity[{'kind': 'MyEntityKind'}] {}>
4545
46-
- :func:`gcloud.datastore.dataset.Dataset.get_entity` to retrive an existing entity.
46+
- :func:`gcloud.datastore.dataset.Dataset.get_entity` to retrive an
47+
existing entity.
4748
48-
>>> dataset.get_entity(key)
49-
<Entity[{'kind': 'EntityKind', id: 1234}] {'property': 'value'}>
49+
>>> dataset.get_entity(key)
50+
<Entity[{'kind': 'EntityKind', id: 1234}] {'property': 'value'}>
5051
51-
You can the set values on the entity just like you would on any other dictionary.
52+
You can the set values on the entity just like you would on any other
53+
dictionary.
5254
53-
>>> entity['age'] = 20
54-
>>> entity['name'] = 'JJ'
55-
>>> entity
56-
<Entity[{'kind': 'EntityKind', id: 1234}] {'age': 20, 'name': 'JJ'}>
55+
>>> entity['age'] = 20
56+
>>> entity['name'] = 'JJ'
57+
>>> entity
58+
<Entity[{'kind': 'EntityKind', id: 1234}] {'age': 20, 'name': 'JJ'}>
5759
58-
And you can cast an entity to a regular Python dictionary with the `dict` builtin:
60+
And you can cast an entity to a regular Python dictionary with the `dict`
61+
builtin:
5962
60-
>>> dict(entity)
61-
{'age': 20, 'name': 'JJ'}
62-
"""
63+
>>> dict(entity)
64+
{'age': 20, 'name': 'JJ'}
65+
"""
6366

6467
def __init__(self, dataset=None, kind=None):
6568
if dataset and kind:
@@ -68,30 +71,34 @@ def __init__(self, dataset=None, kind=None):
6871
self._key = None
6972

7073
def dataset(self):
71-
"""Get the :class:`gcloud.datastore.dataset.Dataset` in which this entity belonds.
72-
73-
.. note::
74-
This is based on the :class:`gcloud.datastore.key.Key` set on the entity.
75-
That means that if you have no key set, the dataset might be `None`.
76-
It also means that if you change the key on the entity, this will refer
77-
to that key's dataset.
78-
"""
74+
"""Get the Dataset in which this entity belongs.
75+
76+
:rtype: :class:`gcloud.datastore.dataset.Dataset`
77+
:returns: The Dataset containing the entity if there is a key,
78+
else None.
79+
80+
.. note::
81+
This is based on the :class:`gcloud.datastore.key.Key` set on the
82+
entity. That means that if you have no key set, the dataset might
83+
be `None`. It also means that if you change the key on the entity,
84+
this will refer to that key's dataset.
85+
"""
7986
if self.key():
8087
return self.key().dataset()
8188

8289
def key(self, key=None):
8390
"""Get or set the :class:`gcloud.datastore.key.Key` on the current entity.
8491
85-
:type key: :class:`glcouddatastore.key.Key`
86-
:param key: The key you want to set on the entity.
92+
:type key: :class:`glcouddatastore.key.Key`
93+
:param key: The key you want to set on the entity.
8794
88-
:returns: Either the current key or the :class:`Entity`.
95+
:returns: Either the current key or the :class:`Entity`.
8996
90-
>>> entity.key(my_other_key) # This returns the original entity.
91-
<Entity[{'kind': 'OtherKeyKind', 'id': 1234}] {'property': 'value'}>
92-
>>> entity.key() # This returns the key.
93-
<Key[{'kind': 'OtherKeyKind', 'id': 1234}]>
94-
"""
97+
>>> entity.key(my_other_key) # This returns the original entity.
98+
<Entity[{'kind': 'OtherKeyKind', 'id': 1234}] {'property': 'value'}>
99+
>>> entity.key() # This returns the key.
100+
<Key[{'kind': 'OtherKeyKind', 'id': 1234}]>
101+
"""
95102

96103
if key:
97104
self._key = key
@@ -102,41 +109,44 @@ def key(self, key=None):
102109
def kind(self):
103110
"""Get the kind of the current entity.
104111
105-
.. note::
106-
This relies entirely on
107-
the :class:`gcloud.datastore.key.Key`
108-
set on the entity.
109-
That means that we're not storing the kind of the entity at all,
110-
just the properties and a pointer to a Key
111-
which knows its Kind.
112-
"""
112+
.. note::
113+
This relies entirely on
114+
the :class:`gcloud.datastore.key.Key`
115+
set on the entity.
116+
That means that we're not storing the kind of the entity at all,
117+
just the properties and a pointer to a Key
118+
which knows its Kind.
119+
"""
113120

114121
if self.key():
115122
return self.key().kind()
116123

117124
@classmethod
118125
def from_key(cls, key):
119-
"""Factory method for creating an entity based on the :class:`gcloud.datastore.key.Key`.
126+
"""Factory method for creating an entity based on the Key.
120127
121-
:type key: :class:`gcloud.datastore.key.Key`
122-
:param key: The key for the entity.
128+
:type key: :class:`gcloud.datastore.key.Key`
129+
:param key: The key for the entity.
123130
124-
:returns: The :class:`Entity` derived from the :class:`gcloud.datastore.key.Key`.
125-
"""
131+
:returns: The :class:`Entity` derived from the
132+
:class:`gcloud.datastore.key.Key`.
133+
"""
126134

127135
return cls().key(key)
128136

129137
@classmethod
130138
def from_protobuf(cls, pb, dataset=None):
131139
"""Factory method for creating an entity based on a protobuf.
132140
133-
The protobuf should be one returned from the Cloud Datastore Protobuf API.
141+
The protobuf should be one returned from the Cloud Datastore
142+
Protobuf API.
134143
135-
:type key: :class:`gcloud.datastore.datastore_v1_pb2.Entity`
136-
:param key: The Protobuf representing the entity.
144+
:type key: :class:`gcloud.datastore.datastore_v1_pb2.Entity`
145+
:param key: The Protobuf representing the entity.
137146
138-
:returns: The :class:`Entity` derived from the :class:`gcloud.datastore.datastore_v1_pb2.Entity`.
139-
"""
147+
:returns: The :class:`Entity` derived from the
148+
:class:`gcloud.datastore.datastore_v1_pb2.Entity`.
149+
"""
140150

141151
# This is here to avoid circular imports.
142152
from gcloud.datastore import helpers
@@ -153,15 +163,15 @@ def from_protobuf(cls, pb, dataset=None):
153163
def reload(self):
154164
"""Reloads the contents of this entity from the datastore.
155165
156-
This method takes the :class:`gcloud.datastore.key.Key`, loads all
157-
properties from the Cloud Datastore, and sets the updated properties on
158-
the current object.
166+
This method takes the :class:`gcloud.datastore.key.Key`, loads all
167+
properties from the Cloud Datastore, and sets the updated properties on
168+
the current object.
159169
160-
.. warning::
161-
This will override any existing properties if a different value exists
162-
remotely, however it will *not* override any properties that exist
163-
only locally.
164-
"""
170+
.. warning::
171+
This will override any existing properties if a different value
172+
exists remotely, however it will *not* override any properties that
173+
exist only locally.
174+
"""
165175

166176
# Note that you must have a valid key, otherwise this makes no sense.
167177
entity = self.dataset().get_entity(self.key().to_protobuf())
@@ -173,10 +183,12 @@ def reload(self):
173183
def save(self):
174184
"""Save the entity in the Cloud Datastore.
175185
176-
:rtype: :class:`gcloud.datastore.entity.Entity`
177-
:returns: The entity with a possibly updated Key.
178-
"""
179-
key_pb = self.dataset().connection().save_entity(dataset_id=self.dataset().id(), key_pb=self.key().to_protobuf(), properties=dict(self))
186+
:rtype: :class:`gcloud.datastore.entity.Entity`
187+
:returns: The entity with a possibly updated Key.
188+
"""
189+
key_pb = self.dataset().connection().save_entity(
190+
dataset_id=self.dataset().id(),
191+
key_pb=self.key().to_protobuf(), properties=dict(self))
180192

181193
# If we are in a transaction and the current entity needs an
182194
# automatically assigned ID, tell the transaction where to put that.
@@ -195,16 +207,18 @@ def save(self):
195207
def delete(self):
196208
"""Delete the entity in the Cloud Datastore.
197209
198-
.. note::
199-
This is based entirely off of the :class:`gcloud.datastore.key.Key` set
200-
on the entity. Whatever is stored remotely using the key on the entity
201-
will be deleted.
202-
"""
203-
self.dataset().connection().delete_entity(dataset_id=self.dataset().id(), key_pb=self.key().to_protobuf())
210+
.. note::
211+
This is based entirely off of the :class:`gcloud.datastore.key.Key`
212+
set on the entity. Whatever is stored remotely using the key on the
213+
entity will be deleted.
214+
"""
215+
self.dataset().connection().delete_entity(
216+
dataset_id=self.dataset().id(), key_pb=self.key().to_protobuf())
204217

205218
def __repr__(self): # pragma NO COVER
206219
# An entity should have a key all the time (even if it's partial).
207220
if self.key():
208-
return '<Entity%s %s>' % (self.key().path(), super(Entity, self).__repr__())
221+
return '<Entity%s %s>' % (self.key().path(),
222+
super(Entity, self).__repr__())
209223
else:
210224
return '<Entity %s>' % (super(Entity, self).__repr__())

0 commit comments

Comments
 (0)