8000 remove access to dictionary entries as attributes · codeplay/cf-python-client@04bb432 · GitHub
[go: up one dir, main page]

Skip to content

Commit 04bb432

Browse files
Romain DartiguesBen Einaudi
authored andcommitted
remove access to dictionary entries as attributes
This revert part of a438813; accessing dictionary as an object add some code complexity without big benefits (ie: obj.item vs obj['item']).
1 parent 5312af6 commit 04bb432

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/python/cloudfoundry_client/entities.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
class JsonObject(dict):
99
def __init__(self, *args, **kwargs):
1010
super(JsonObject, self).__init__(*args, **kwargs)
11-
self.__dict__ = self
1211

1312
json = json.dumps
1413

@@ -32,10 +31,6 @@ def new_method():
3231
new_method.__name__ = str(domain_name)
3332
setattr(self, domain_name, new_method)
3433

35-
def json(self, **kwargs):
36-
return json.dumps(dict([(k, v) for k, v in self.items() if k != 'client' and not hasattr(v, '__call__')]),
37-
**kwargs)
38-
3934

4035
class InvalidStatusCode(Exception):
4136
def __init__(self, status_code, body):
@@ -72,7 +67,7 @@ def _list(self, requested_path, entity_builder=None, **kwargs):
7267
while True:
7368
_logger.debug('GET - %s - %s', url_requested, response.text)
7469
response_json = self._read_response(response, JsonObject)
75-
for resource in response_json.resources:
70+
for resource in response_json['resources']:
7671
yield entity_builder(resource.items())
7772
if response_json['next_url'] is None:
7873
break

src/python/cloudfoundry_client/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def main():
209209
resource_id = resolve_id(arguments.id[0], lambda x: client.apps.get_first(name=x), 'application', True)
210210
name_property = application_extra_list_commands[arguments.action][2]
211211
for entity in getattr(client.apps, application_extra_list_commands[arguments.action][0])(resource_id):
212-
print('%s - %s' % (entity.metadata.guid, entity.entity[name_property]))
212+
print('%s - %s' % (entity['metadata']['guid'], entity['entity'][name_property]))
213213
elif arguments.action.find('list_') == 0:
214214
domain = arguments.action[len('list_'): len(arguments.action) - 1]
215215
filter_list = dict()
@@ -220,9 +220,9 @@ def main():
220220
for entity in _get_client_domain(client, domain).list(**filter_list):
221221
name_property = commands[domain]['name']
222222
if name_property is not None:
223-
print('%s - %s' % (entity.metadata.guid, entity.entity[name_property]))
223+
print('%s - %s' % (entity['metadata']['guid'], entity['entity'][name_property]))
224224
else:
225-
print(entity.metadata.guid)
225+
print(entity['metadata']['guid'])
226226
elif arguments.action.find('get_') == 0:
227227
domain = arguments.action[len('get_'):]
228228
resource_id = resolve_id(arguments.id[0],
@@ -257,7 +257,7 @@ def main():
257257
if entity is None:
258258
raise InvalidStatusCode(httplib.NOT_FOUND, '%s with name %s' % (domain, arguments.id[0]))
259259
else:
260-
_get_client_domain(client, domain)._remove(entity.metadata.guid)
260+
_get_client_domain(client, domain)._remove(entity['metadata']['guid'])
261261
else:
262262
raise ValueError('id: %s: does not allow search by name' % domain)
263263

0 commit comments

Comments
 (0)
0