def translate_style(style, colormode, colorpalette):
style_parts = iter(style.split('<STR_LIT:_>'))<EOL>ansi_start_sequence = []<EOL>ansi_end_sequence = []<EOL>try:<EOL><INDENT>part = None<EOL>for mod_part in style_parts:<EOL><INDENT>part = mod_part<EOL>if part not in ansi.MODIFIERS:<EOL><INDENT>break  <EOL><DEDENT>mod_start_code, mod_end_code = resolve_modifier_to_ansi_code(part, colormode)<EOL>ansi_start_sequence.append(mod_start_code)<EOL>ansi_end_sequence.append(mod_end_code)<EOL><DEDENT>else:  <EOL><INDENT>raise StopIteration()<EOL><DEDENT>if part != '<STR_LIT>':<EOL><INDENT>ansi_start_code, ansi_end_code = translate_colorname_to_ansi_code(<EOL>part, ansi.FOREGROUND_COLOR_OFFSET, colormode, colorpalette)<EOL>ansi_start_sequence.append(ansi_start_code)<EOL>ansi_end_sequence.append(ansi_end_code)<EOL>next(style_parts)<EOL><DEDENT>part = next(style_parts)<EOL>ansi_start_code, ansi_end_code = translate_colorname_to_ansi_code(<EOL>part, ansi.BACKGROUND_COLOR_OFFSET, colormode, colorpalette)<EOL>ansi_start_sequence.append(ansi_start_code)<EOL>ansi_end_sequence.append(ansi_end_code)<EOL><DEDENT>except StopIteration:  <EOL><INDENT>pass<EOL><DEDENT>return '<STR_LIT>'.join(ansi_start_sequence), '<STR_LIT>'.join(ansi_end_sequence)<EOL>
Translate the given style to an ANSI escape code
sequence.

``style`` examples are:

* green
* bold
* red_on_black
* bold_green
* italic_yellow_on_cyan

:param str style: the style to translate
:param int colormode: the color mode to use. See ``translate_rgb_to_ansi_code``
:parma dict colorpalette: the color palette to use for the color name mapping