diff options
author | Sergei Trofimov <sergei.trofimov@arm.com> | 2018-05-24 13:51:05 +0100 |
---|---|---|
committer | Marc Bonnici <marc.bonnici@arm.com> | 2018-05-25 10:21:06 +0100 |
commit | 4cc5aec39a31e612e3e7959591e099965577626e (patch) | |
tree | e41d078339b9c13e2924e69134f39ee469084a5b /wa/utils | |
parent | 86ba51be729b6fc57195caf80b963d663460b4e1 (diff) |
utils/serializer: make is_pod() recursive
If the object being passed into is_pod() is iterable (and not a
string), recursively check that its elements are also PODs.
Diffstat (limited to 'wa/utils')
-rw-r--r-- | wa/utils/serializer.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/wa/utils/serializer.py b/wa/utils/serializer.py index 0681b49d..a41892f6 100644 --- a/wa/utils/serializer.py +++ b/wa/utils/serializer.py @@ -305,6 +305,7 @@ def _read_pod(fh, fmt=None): else: raise ValueError('Unknown format "{}": {}'.format(fmt, getattr(fh, 'name', '<none>'))) + def _write_pod(pod, wfh, fmt=None): if fmt is None: fmt = os.path.splitext(wfh.name)[1].lower().strip('.') @@ -317,6 +318,19 @@ def _write_pod(pod, wfh, fmt=None): else: raise ValueError('Unknown format "{}": {}'.format(fmt, getattr(wfh, 'name', '<none>'))) + def is_pod(obj): - return type(obj) in POD_TYPES + if type(obj) not in POD_TYPES: + return False + if hasattr(obj, 'iteritems'): + for k, v in obj.iteritems(): + if not (is_pod(k) and is_pod(v)): + return False + elif isiterable(obj): + for v in obj: + if not is_pod(v): + return False + return True + + |