bgp: Clean up syntax in services/protocols/bgp/operator/views/base.py to avoid SyntaxErrors

When byte-compiled, base.py in the bgp protocol service generates a large number of SyntaxErrors for me.
This patch cleans up the SyntaxErrors, while retaining the original (intended?) semantics.

Signed-off-by: Victor J. Orlikowski <vjo@duke.edu>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Victor Orlikowski 2016-01-21 20:36:47 +00:00 committed by FUJITA Tomonori
parent e3d0721892
commit 0bfdd1e8fb

View File

@ -120,9 +120,11 @@ class OperatorDetailView(OperatorAbstractView):
return f.get(self._obj) return f.get(self._obj)
def encode(self): def encode(self):
return {field_name: field.get(self._obj) encoded = {}
for field_name, field in self._fields.items() for field_name, field in self._fields.items():
if isinstance(field, fields.DataField)} if isinstance(field, fields.DataField):
encoded[field_name] = field.get(self._obj)
return encoded
def rel(self, field_name): def rel(self, field_name):
f = self._fields[field_name] f = self._fields[field_name]
@ -150,12 +152,14 @@ class OperatorListView(OperatorAbstractView):
return RdyToFlattenList([f.get(obj) for obj in self.model]) return RdyToFlattenList([f.get(obj) for obj in self.model])
def encode(self): def encode(self):
return RdyToFlattenList( encoded_list = []
[{field_name: field.get(obj) for obj in self.model:
for field_name, field in self._fields.items() encoded_item = {}
if isinstance(field, fields.DataField)} for field_name, field in self._fields.items():
for obj in self.model] if isinstance(field, fields.DataField):
) encoded_item[field_name] = field.get(obj)
encoded_list.append(encoded_item)
return RdyToFlattenList(encoded_list)
@property @property
def model(self): def model(self):
@ -179,17 +183,20 @@ class OperatorDictView(OperatorAbstractView):
def get_field(self, field_name): def get_field(self, field_name):
f = self._fields[field_name] f = self._fields[field_name]
return RdyToFlattenDict( dict_to_flatten = {}
{key: f.get(obj) for key, obj in self.model.items()} for key, obj in self.model.items():
) dict_to_flatten[key] = f.get(obj)
return RdyToFlattenDict(dict_to_flatten)
def encode(self): def encode(self):
return RdyToFlattenDict( outer_dict_to_flatten = {}
{key: {field_name: field.get(obj) for key, obj in self.model.items():
for field_name, field in self._fields.items() inner_dict_to_flatten = {}
if isinstance(field, fields.DataField)} for field_name, field in self._fields.items():
for key, obj in self.model.items()} if isinstance(field, fields.DataField):
) inner_dict_to_flatten[field_name] = field.get(obj)
outer_dict_to_flatten[key] = inner_dict_to_flatten
return RdyToFlattenDict(outer_dict_to_flatten)
@property @property
def model(self): def model(self):
@ -280,8 +287,10 @@ def create_dict_view_class(detail_view_class, name):
encode = None encode = None
if 'encode' in dir(detail_view_class): if 'encode' in dir(detail_view_class):
def encode(self): def encode(self):
return RdyToFlattenDict({key: detail_view_class(obj).encode() dict_to_flatten = {}
for key, obj in self.model.items()}) for key, obj in self.model.items():
dict_to_flatten[key] = detail_view_class(obj).encode()
return RdyToFlattenDict(dict_to_flatten)
return _create_collection_view( return _create_collection_view(
detail_view_class, name, encode, OperatorDictView detail_view_class, name, encode, OperatorDictView