'Encodes all integer values in the dict rval whose keys are \'id\' or end
with \'_id\' excluding `tool_id` which are consumed and produced as is
via the API.'

def encode_all_ids(self, rval, recursive=False):

    if (not isinstance(rval, dict)):
        return rval
    for (k, v) in rval.items():
        if (((k == 'id') or k.endswith('_id')) and (v is not None) and (k not in ['tool_id', 'external_id'])):
            try:
                rval[k] = self.encode_id(v)
            except Exception:
                pass
        if (k.endswith('_ids') and isinstance(v, list)):
            try:
                o = []
                for i in v:
                    o.append(self.encode_id(i))
                rval[k] = o
            except Exception:
                pass
        elif (recursive and isinstance(v, dict)):
            rval[k] = self.encode_all_ids(v, recursive)
        elif (recursive and isinstance(v, list)):
            rval[k] = map((lambda el: self.encode_all_ids(el, True)), v)
    return rval
