src/pyams_utils/dict.py
changeset 380 c062ab4db6cd
parent 292 b338586588ad
equal deleted inserted replaced
379:07fe5bb08599 380:c062ab4db6cd
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
    10 # FOR A PARTICULAR PURPOSE.
    10 # FOR A PARTICULAR PURPOSE.
    11 #
    11 #
    12 
    12 
       
    13 """PyAMS_utils.dict module
       
    14 
       
    15 This helper module only contains a single function which can be used to update an input
       
    16 dictionary; if given value argument is a boolean 'true' value, given dictionary's key is created
       
    17 or updated, otherwise dictionary is left unchanged.
       
    18 """
       
    19 
    13 __docformat__ = 'restructuredtext'
    20 __docformat__ = 'restructuredtext'
    14 
    21 
    15 
    22 
    16 # import standard library
    23 def update_dict(input_dict, key, value):
    17 
       
    18 # import interfaces
       
    19 
       
    20 # import packages
       
    21 
       
    22 
       
    23 def update_dict(input, key, value):
       
    24     """Update given mapping if input value is a boolean 'true' value
    24     """Update given mapping if input value is a boolean 'true' value
    25 
    25 
    26     :param dict input: input dictionary
    26     :param dict input_dict: input dictionary
    27     :param key: mapping key
    27     :param key: mapping key
    28     :param value: new value
    28     :param value: new value
    29 
    29 
    30     'False' values leave mapping unchanged::
    30     'False' values leave mapping unchanged::
    31 
    31 
    49     >>> update_dict(mydict, 'key1', 'value2')
    49     >>> update_dict(mydict, 'key1', 'value2')
    50     >>> mydict
    50     >>> mydict
    51     {'key1': 'value2'}
    51     {'key1': 'value2'}
    52     """
    52     """
    53     if value:
    53     if value:
    54         input[key] = value
    54         input_dict[key] = value