diff options
| author | Christian Heimes <cheimes@redhat.com> | 2015-08-16 19:00:00 +0200 |
|---|---|---|
| committer | Christian Heimes <cheimes@redhat.com> | 2015-08-17 21:14:11 +0200 |
| commit | 3725265993960285315942ea5a0355165282dd7c (patch) | |
| tree | 01b2422355a1bfd7b70dda9bd982fa713840c611 /base/common/python/pki/encoder.py | |
| parent | 632b935f59cd4c05004db6525757dd805a9b9e3f (diff) | |
| download | pki-3725265993960285315942ea5a0355165282dd7c.tar.gz pki-3725265993960285315942ea5a0355165282dd7c.tar.xz pki-3725265993960285315942ea5a0355165282dd7c.zip | |
Py3 modernization: libmodernize.fixes.fix_dict_six
In Python 3 dict methods like values(), items() and keys() return views
rather than lists. The iter equivalents are gone. Use six to use
iterators on Python 2 and 3.
In some places like setup.py a list is required. Use
list(somedict.values()) to get a list on all Python versions.
Diffstat (limited to 'base/common/python/pki/encoder.py')
| -rw-r--r-- | base/common/python/pki/encoder.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/base/common/python/pki/encoder.py b/base/common/python/pki/encoder.py index cebcc566b..bf5d2e473 100644 --- a/base/common/python/pki/encoder.py +++ b/base/common/python/pki/encoder.py @@ -1,5 +1,6 @@ from __future__ import absolute_import import json +from six import iteritems, itervalues TYPES = {} NOTYPES = {} @@ -35,10 +36,10 @@ class CustomTypeEncoder(json.JSONEncoder): # pylint: disable=E0202 def default(self, obj): - for k, v in TYPES.iteritems(): + for k, v in iteritems(TYPES): if isinstance(obj, v): return {k: obj.__dict__} - for t in NOTYPES.itervalues(): + for t in itervalues(NOTYPES): if isinstance(obj, t): return self.attr_name_conversion(obj.__dict__, type(obj)) return json.JSONEncoder.default(self, obj) @@ -48,9 +49,9 @@ class CustomTypeEncoder(json.JSONEncoder): if not hasattr(object_class, 'json_attribute_names'): return attr_dict reverse_dict = {v: k for k, v in - object_class.json_attribute_names.iteritems()} + iteritems(object_class.json_attribute_names)} new_dict = dict() - for k, v in attr_dict.iteritems(): + for k, v in iteritems(attr_dict): if k in reverse_dict: new_dict[reverse_dict[k]] = v else: @@ -60,7 +61,8 @@ class CustomTypeEncoder(json.JSONEncoder): def CustomTypeDecoder(dct): # nopep8 if len(dct) == 1: - type_name, value = dct.items()[0] + type_name = list(dct)[0] + value = dct[type_name] if type_name in TYPES: return TYPES[type_name].from_dict(value) return dct |
