X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Ftools%2Fpapi%2Fvpp_papi_provider.py;h=676f5491ddb5ba9104a2f97e5a1293871de3dd3c;hb=56c1c013bd0d632256efa4cb6b0224bf9c608afa;hp=ded3c3069e14c8c835e83a4ae4eafb3259b1741c;hpb=3c863def2096b573832499985e3a12bbccf82ea8;p=csit.git diff --git a/resources/tools/papi/vpp_papi_provider.py b/resources/tools/papi/vpp_papi_provider.py index ded3c3069e..676f5491dd 100755 --- a/resources/tools/papi/vpp_papi_provider.py +++ b/resources/tools/papi/vpp_papi_provider.py @@ -91,25 +91,39 @@ def _convert_reply(api_r): """ unwanted_fields = ['count', 'index', 'context'] + def process_value(val): + """Process value. + + :param val: Value to be processed. + :type val: object + :returns: Processed value. + :rtype: dict or str or int + """ + if isinstance(val, dict): + for val_k, val_v in val.iteritems(): + val[str(val_k)] = process_value(val_v) + return val + elif isinstance(val, list): + for idx, val_l in enumerate(val): + val[idx] = process_value(val_l) + return val + elif hasattr(val, '__int__'): + return int(val) + elif hasattr(val, '__str__'): + return binascii.hexlify(str(val)) + # Next handles parameters not supporting preferred integer or string + # representation to get it logged + elif hasattr(val, '__repr__'): + return repr(val) + else: + return val + reply_dict = dict() reply_key = repr(api_r).split('(')[0] reply_value = dict() for item in dir(api_r): if not item.startswith('_') and item not in unwanted_fields: - attr_value = getattr(api_r, item) - if isinstance(attr_value, list) or isinstance(attr_value, dict): - value = attr_value - elif hasattr(attr_value, '__int__'): - value = int(attr_value) - elif hasattr(attr_value, '__str__'): - value = binascii.hexlify(str(attr_value)) - # Next handles parameters not supporting preferred integer or string - # representation to get it logged - elif hasattr(attr_value, '__repr__'): - value = repr(attr_value) - else: - value = attr_value - reply_value[item] = value + reply_value[item] = process_value(getattr(api_r, item)) reply_dict[reply_key] = reply_value return reply_dict @@ -132,11 +146,21 @@ def process_json_request(args): reply = list() def process_value(val): + """Process value. + + :param val: Value to be processed. + :type val: object + :returns: Processed value. + :rtype: dict or str or int + """ if isinstance(val, dict): - val_dict = dict() for val_k, val_v in val.iteritems(): - val_dict[str(val_k)] = process_value(val_v) - return val_dict + val[str(val_k)] = process_value(val_v) + return val + elif isinstance(val, list): + for idx, val_l in enumerate(val): + val[idx] = process_value(val_l) + return val elif isinstance(val, unicode): return binascii.unhexlify(val) elif isinstance(val, int):