@@ -0,0 +1,2809 @@
+# -*- coding: utf-8 -*-%0Afrom __future__ import absolute_import%0Afrom __future__ import print_function%0A%0Aimport sys%0A%0Aimport salt.payload%0A%0A%0Adef trim_dict(%0A        data,%0A        max_dict_bytes,%0A        percent=50.0,%0A        stepper_size=10,%0A        replace_with='VALUE_TRIMMED',%0A        is_msgpacked=False):%0A    '''%0A    Takes a dictionary and iterates over its keys, looking for%0A    large values and replacing them with a trimmed string.%0A%0A    If after the first pass over dictionary keys, the dictionary%0A    is not sufficiently small, the stepper_size will be increased%0A    and the dictionary will be rescanned. This allows for progressive%0A    scanning, removing large items first and only making additional%0A    passes for smaller items if necessary.%0A%0A    This function uses msgpack to calculate the size of the dictionary%0A    in question. While this might seem like unnecessary overhead, a%0A    data structure in python must be serialized in order for sys.getsizeof()%0A    to accurately return the items referenced in the structure.%0A%0A    Ex:%0A    %3E%3E%3E salt.utils.trim_dict(%7B'a': 'b', 'c': 'x' * 10000%7D, 100)%0A    %7B'a': 'b', 'c': 'VALUE_TRIMMED'%7D%0A%0A    To improve performance, it is adviseable to pass in msgpacked%0A    data structures instead of raw dictionaries. If a msgpack%0A    structure is passed in, it will not be unserialized unless%0A    necessary.%0A%0A    If a msgpack is passed in, it will be repacked if necessary%0A    before being returned.%0A    '''%0A    serializer = salt.payload.Serial(%7B'serial': 'msgpack'%7D)%0A    if is_msgpacked:%0A        dict_size = sys.getsizeof(data)%0A    else:%0A        dict_size = sys.getsizeof(serializer.dumps(data))%0A    if dict_size %3E max_dict_bytes:%0A        if is_msgpacked:%0A            data = serializer.loads(data)%0A        while True:%0A            percent = float(percent)%0A            max_val_size = float(max_dict_bytes * (percent / 100))%0A            try:%0A                for key in data:%0A                    if sys.getsizeof(data%5Bkey%5D) %3E max_val_size:%0A                        data%5Bkey%5D = replace_with%0A                percent = percent - stepper_size%0A                max_val_size = float(max_dict_bytes * (percent / 100))%0A                cur_dict_size = sys.getsizeof(serializer.dumps(data))%0A                if cur_dict_size %3C max_dict_bytes:%0A                    if is_msgpacked:  # Repack it%0A                        return serializer.dumps(data)%0A                    else:%0A                        return data%0A                elif max_val_size == 0:%0A                    if is_msgpacked:%0A                        return serializer.dumps(data)%0A                    else:%0A                        return data%0A            except ValueError:%0A                pass%0A        if is_msgpacked:%0A            return serializer.dumps(data)%0A        else:%0A            return data%0A    else:%0A        return data%0A

Add the needed file :]