Use vars() more readable then __dict__

Change-Id: I20ace9a4bf9aac5048a1e1b991648e17e07f9c74
This commit is contained in:
Eyal 2020-06-28 15:22:17 +03:00
parent 9a87f422c0
commit e364c1ed2c
11 changed files with 12 additions and 12 deletions

View File

@ -31,7 +31,7 @@ def enforce(rule, headers, enforcer, target):
} }
if not isinstance(target, dict): if not isinstance(target, dict):
target = target.__dict__ target = vars(target)
target = dict(recursive_keypairs(target)) target = dict(recursive_keypairs(target))

View File

@ -309,7 +309,7 @@ class AodhDriver(AlarmDriverBase):
entity.update(self._parse_changed_rule( entity.update(self._parse_changed_rule(
changed_rule[changed_type])) changed_rule[changed_type]))
# handle other changed alarm properties # handle other changed alarm properties
elif changed_type in AodhProps.__dict__.values(): elif changed_type in vars(AodhProps).values():
entity[changed_type] = changed_info entity[changed_type] = changed_info
return self._filter_and_cache_alarm(entity, old_alarm, return self._filter_and_cache_alarm(entity, old_alarm,

View File

@ -344,7 +344,7 @@ class CeilometerDriver(AlarmDriverBase):
entity.update(self._parse_changed_rule( entity.update(self._parse_changed_rule(
changed_rule[changed_type])) changed_rule[changed_type]))
# handle other changed alarm properties # handle other changed alarm properties
elif changed_type in CeilProps.__dict__.values(): elif changed_type in vars(CeilProps).values():
entity[changed_type] = changed_info entity[changed_type] = changed_info
return self._filter_and_cache_alarm(entity, old_alarm, return self._filter_and_cache_alarm(entity, old_alarm,

View File

@ -33,7 +33,7 @@ class CinderVolumeDriver(DriverBase):
@staticmethod @staticmethod
def extract_events(volumes): def extract_events(volumes):
return [volume.__dict__ for volume in volumes] return [vars(volume) for volume in volumes]
def get_all(self, datasource_action): def get_all(self, datasource_action):
return self.make_pickleable( return self.make_pickleable(

View File

@ -102,7 +102,7 @@ class InstanceDriver(NovaDriverBase):
@staticmethod @staticmethod
def extract_events(instances): def extract_events(instances):
events = [instance.__dict__ for instance in instances] events = [vars(instance) for instance in instances]
for e in events: for e in events:
if e['status'].lower() == 'deleted': if e['status'].lower() == 'deleted':
e[DSProps.EVENT_TYPE] = GraphAction.DELETE_ENTITY e[DSProps.EVENT_TYPE] = GraphAction.DELETE_ENTITY

View File

@ -22,7 +22,7 @@ class ZoneDriver(NovaDriverBase):
def filter_internal_zone(zones): def filter_internal_zone(zones):
zones_res = [] zones_res = []
for zone in zones: for zone in zones:
zone_dict = zone.__dict__ zone_dict = vars(zone)
if zone_dict['zoneName'] and zone_dict['zoneName'] != 'internal': if zone_dict['zoneName'] and zone_dict['zoneName'] != 'internal':
zones_res.append(zone_dict) zones_res.append(zone_dict)
return zones_res return zones_res

View File

@ -320,7 +320,7 @@ class TransformerBase(object):
:rtype: str :rtype: str
""" """
if DSProps.EVENT_TYPE in entity_event and \ if DSProps.EVENT_TYPE in entity_event and \
entity_event[DSProps.EVENT_TYPE] in GraphAction.__dict__.values(): entity_event[DSProps.EVENT_TYPE] in vars(GraphAction).values():
return entity_event[DSProps.EVENT_TYPE] return entity_event[DSProps.EVENT_TYPE]
datasource_action = entity_event[DSProps.DATASOURCE_ACTION] datasource_action = entity_event[DSProps.DATASOURCE_ACTION]

View File

@ -83,7 +83,7 @@ class Vertex(PropertiesElement):
:type other: Vertex :type other: Vertex
:rtype: bool :rtype: bool
""" """
return self.__dict__ == other.__dict__ and \ return vars(self) == vars(other) and \
self.properties == other.properties self.properties == other.properties
def copy(self): def copy(self):
@ -152,7 +152,7 @@ class Edge(PropertiesElement):
:type other: Edge :type other: Edge
:rtype: bool :rtype: bool
""" """
return self.__dict__ == other.__dict__ and \ return vars(self) == vars(other) and \
self.properties == other.properties self.properties == other.properties
def other_vertex(self, v_id): def other_vertex(self, v_id):

View File

@ -86,7 +86,7 @@ def datasources_opts():
return [(datasource, module.OPTS) for datasource in datasources return [(datasource, module.OPTS) for datasource in datasources
for module in for module in
[importutils.import_module(DATASOURCES_PATH + datasource)] [importutils.import_module(DATASOURCES_PATH + datasource)]
if 'OPTS' in module.__dict__] if 'OPTS' in vars(module)]
def _get_datasources_folders(top=os.getcwd()): def _get_datasources_folders(top=os.getcwd()):

View File

@ -65,7 +65,7 @@ class AodhTransformerBaseTest(base.BaseTest):
def _validate_action(self, alarm, wrapper): def _validate_action(self, alarm, wrapper):
if DSProps.EVENT_TYPE in alarm \ if DSProps.EVENT_TYPE in alarm \
and alarm[DSProps.EVENT_TYPE] in GraphAction.__dict__.values(): and alarm[DSProps.EVENT_TYPE] in vars(GraphAction).values():
self.assertEqual(alarm[DSProps.EVENT_TYPE], wrapper.action) self.assertEqual(alarm[DSProps.EVENT_TYPE], wrapper.action)
return return

View File

@ -69,7 +69,7 @@ class CeilometerTransformerBaseTest(base.BaseTest):
def _validate_action(self, alarm, wrapper): def _validate_action(self, alarm, wrapper):
if DSProps.EVENT_TYPE in alarm \ if DSProps.EVENT_TYPE in alarm \
and alarm[DSProps.EVENT_TYPE] in GraphAction.__dict__.values(): and alarm[DSProps.EVENT_TYPE] in vars(GraphAction).values():
self.assertEqual(alarm[DSProps.EVENT_TYPE], wrapper.action) self.assertEqual(alarm[DSProps.EVENT_TYPE], wrapper.action)
return return