summaryrefslogtreecommitdiffstats
path: root/base/common/python/pki/encoder.py
diff options
context:
space:
mode:
authorAbhishek Koneru <akoneru@redhat.com>2014-06-30 16:04:34 -0400
committerAbhishek Koneru <akoneru@redhat.com>2014-07-11 12:46:51 -0400
commitcabfda3ed8840fe7dd17d80e3ee922d72f9b7787 (patch)
tree398f32cab35aa08d07e1831ceb2f48ceba43ab85 /base/common/python/pki/encoder.py
parent7a7f8bb635ff819efc638b97b3619d48061197ac (diff)
downloadpki-cabfda3ed8840fe7dd17d80e3ee922d72f9b7787.tar.gz
pki-cabfda3ed8840fe7dd17d80e3ee922d72f9b7787.tar.xz
pki-cabfda3ed8840fe7dd17d80e3ee922d72f9b7787.zip
Refactoring ProfileClient to remove the property fields.
Replaced the usage of python property feature with a dict for attribute name conversion. Fixed an issue caused to traversing the NOTYPES dict in encoder.py to find the instance of an object. The traversal causes an issue in the presence of subclassing. Modified method attr_name_conversion to return a new dictionary with modified attribute names rather than making changes to the object's __dict__.
Diffstat (limited to 'base/common/python/pki/encoder.py')
-rw-r--r--base/common/python/pki/encoder.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/base/common/python/pki/encoder.py b/base/common/python/pki/encoder.py
index 06a23250e..09e8f5a9f 100644
--- a/base/common/python/pki/encoder.py
+++ b/base/common/python/pki/encoder.py
@@ -34,21 +34,23 @@ class CustomTypeEncoder(json.JSONEncoder):
for k, v in TYPES.items():
if isinstance(obj, v):
return {k: obj.__dict__}
- for k, v in NOTYPES.items():
- if isinstance(obj, v):
- return self.attr_name_conversion(obj.__dict__, v)
+ if type(obj) in NOTYPES.itervalues():
+ return self.attr_name_conversion(obj.__dict__, type(obj))
return json.JSONEncoder.default(self, obj)
@staticmethod
def attr_name_conversion(attr_dict, object_class):
if not hasattr(object_class, 'json_attribute_names'):
return attr_dict
- for k, v in object_class.json_attribute_names.items():
- if v in attr_dict:
- value = attr_dict[v]
- del attr_dict[v]
- attr_dict[k] = value
- return attr_dict
+ reverse_dict = {v: k for k,v in
+ object_class.json_attribute_names.iteritems()}
+ new_dict = dict()
+ for k, v in attr_dict.items():
+ if k in reverse_dict:
+ new_dict[reverse_dict[k]] = v
+ else:
+ new_dict[k] = v
+ return new_dict
def CustomTypeDecoder(dct):