%PDF- %PDF-
| Direktori : /proc/thread-self/root/proc/self/root/lib/python2.7/site-packages/salt/utils/ |
| Current File : //proc/thread-self/root/proc/self/root/lib/python2.7/site-packages/salt/utils/dicttrim.pyc |
�
���^c @@ sY d d l m Z m Z m Z d d l Z d d l Z d � Z d d d e e d � Z d S( i ( t absolute_importt print_functiont unicode_literalsNc C@ se x^ | D]V } t | | t � r7 t | | | | � q t j | | � | k r | | | <q q Wd S( u�
Takes a dictionary, max_val_size and replace_with
and recursively loops through and replaces any values
that are greater than max_val_size.
N( t
isinstancet dictt _trim_dict_in_dictt syst getsizeof( t datat max_val_sizet replace_witht key( ( s7 /usr/lib/python2.7/site-packages/salt/utils/dicttrim.pyR s
g I@i
u
VALUE_TRIMMEDc
C@ s t j j i d d 6� } | r1 t j | � } n t j | j | � � } | | k r�| r� | ry | j | d d �} q� | j | � } n x7t r�t | � } t | | d � } y� x^ | D]V }
t | |
t
� r� t | |
| | � q� t j | |
� | k r� | | |
<q� q� W| | } t | | d � } | rT| j | d t �} n | j | � } t j | � } | | k r�| r�| S| Sn | d k r�| r�| S| Sn Wq� t k
r�q� Xq� W| r�| r�| j | d t �S| j | � Sq�| Sn | Sd S( u�
Takes a dictionary and iterates over its keys, looking for
large values and replacing them with a trimmed string.
If after the first pass over dictionary keys, the dictionary
is not sufficiently small, the stepper_size will be increased
and the dictionary will be rescanned. This allows for progressive
scanning, removing large items first and only making additional
passes for smaller items if necessary.
This function uses msgpack to calculate the size of the dictionary
in question. While this might seem like unnecessary overhead, a
data structure in python must be serialized in order for sys.getsizeof()
to accurately return the items referenced in the structure.
Ex:
>>> salt.utils.trim_dict({'a': 'b', 'c': 'x' * 10000}, 100)
{'a': 'b', 'c': 'VALUE_TRIMMED'}
To improve performance, it is adviseable to pass in msgpacked
data structures instead of raw dictionaries. If a msgpack
structure is passed in, it will not be unserialized unless
necessary.
If a msgpack is passed in, it will be repacked if necessary
before being returned.
:param use_bin_type: Set this to true if "is_msgpacked=True"
and the msgpack data has been encoded
with "use_bin_type=True". This also means
that the msgpack data should be decoded with
"encoding='utf-8'".
u msgpacku serialt encodingu utf-8id t use_bin_typei N(
t saltt payloadt SerialR R t dumpst loadst Truet floatR R R t
ValueError(
R t max_dict_bytest percentt stepper_sizeR
t is_msgpackedR
t
serializert dict_sizeR R t dump_datat
cur_dict_size( ( s7 /usr/lib/python2.7/site-packages/salt/utils/dicttrim.pyt trim_dict sT )
(
t
__future__R R R R t salt.payloadR R t FalseR ( ( ( s7 /usr/lib/python2.7/site-packages/salt/utils/dicttrim.pyt <module> s