def substitute_variables_with_mapping(content, mapping):
if isinstance(content, bool):<EOL><INDENT>return content<EOL><DEDENT>if isinstance(content, (numeric_types, type)):<EOL><INDENT>return content<EOL><DEDENT>if not content:<EOL><INDENT>return content<EOL><DEDENT>if isinstance(content, (list, set, tuple)):<EOL><INDENT>return [<EOL>substitute_variables_with_mapping(item, mapping)<EOL>for item in content<EOL>]<EOL><DEDENT>if isinstance(content, dict):<EOL><INDENT>substituted_data = {}<EOL>for key, value in content.items():<EOL><INDENT>eval_key = substitute_variables_with_mapping(key, mapping)<EOL>eval_value = substitute_variables_with_mapping(value, mapping)<EOL>substituted_data[eval_key] = eval_value<EOL><DEDENT>return substituted_data<EOL><DEDENT>logger.log_debug(u"<STR_LIT>".format(content, mapping))<EOL>for var, value in mapping.items():        <EOL><INDENT>logger.log_debug(u"<STR_LIT>".format(content, {var:value}))<EOL>if content == var:<EOL><INDENT>content = value<EOL><DEDENT>else:<EOL><INDENT>if not isinstance(value, str):<EOL><INDENT>value = builtin_str(value)<EOL><DEDENT>if isinstance(content, builtin_str):<EOL><INDENT>content = content.replace(var, value)<EOL><DEDENT><DEDENT><DEDENT>return content<EOL>
substitute variables in content with mapping
    e.g.
    @params
        content = {
            'request': {
                'url': '/api/users/$uid',
                'headers': {'token': '$token'}
            }
        }
        mapping = {"$uid": 1000}
    @return
        {
            'request': {
                'url': '/api/users/1000',
                'headers': {'token': '$token'}
            }
        }