diff options
author | Abhishek Koneru <akoneru@redhat.com> | 2014-06-24 09:37:07 -0400 |
---|---|---|
committer | Abhishek Koneru <akoneru@redhat.com> | 2014-06-27 09:08:39 -0400 |
commit | 700caa5fcc213a2f5768a6142a5d71380e81a467 (patch) | |
tree | 6fcf70fcd87753f35c138873755ece450c823f72 /base/common/python/pki/encoder.py | |
parent | 5c86d1aa946d7bf1eff3e8b30c28ae3dc003f919 (diff) | |
download | pki-700caa5fcc213a2f5768a6142a5d71380e81a467.tar.gz pki-700caa5fcc213a2f5768a6142a5d71380e81a467.tar.xz pki-700caa5fcc213a2f5768a6142a5d71380e81a467.zip |
Fixes for #1040 and #1041 in cert and key python modules
Ticket 1040 - Perform null checks on JSON attributes.
Ticket 1041 - Rename module kraclient to kra.
Also refactored the code in cert module removing the usage of
property. Achieved the conversion of names(camelCase to '_' separated )
using a dictionaries in the objects. The default method in encoder module
has also been modified to perform the reverse conversion.
Diffstat (limited to 'base/common/python/pki/encoder.py')
-rw-r--r-- | base/common/python/pki/encoder.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/base/common/python/pki/encoder.py b/base/common/python/pki/encoder.py index 0ed194d0d..06a23250e 100644 --- a/base/common/python/pki/encoder.py +++ b/base/common/python/pki/encoder.py @@ -36,9 +36,20 @@ class CustomTypeEncoder(json.JSONEncoder): return {k: obj.__dict__} for k, v in NOTYPES.items(): if isinstance(obj, v): - return obj.__dict__ + return self.attr_name_conversion(obj.__dict__, v) 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 + def CustomTypeDecoder(dct): if len(dct) == 1: |