def style_string(string, ansi_style, colormode, nested=False):
ansi_start_code, ansi_end_code = ansi_style<EOL>if PY2:<EOL><INDENT>if isinstance(string, str):<EOL><INDENT>string = string.decode(DEFAULT_ENCODING)<EOL><DEDENT><DEDENT>string = UNICODE(string).replace(ansi.NEST_PLACEHOLDER, ansi_start_code)<EOL>return '<STR_LIT>'.format(<EOL>start_code=ansi_start_code,<EOL>string=string,<EOL>end_code=ansi_end_code,<EOL>nest_ph=ansi.NEST_PLACEHOLDER if nested else '<STR_LIT>')<EOL>
Style the given string according to the given
ANSI style string.

:param str string: the string to style
:param tuple ansi_style: the styling string returned by ``translate_style``
:param int colormode: the color mode to use. See ``translate_rgb_to_ansi_code``

:returns: a string containing proper ANSI sequence