<s> import regex as re <EOL> from flanker . mime . message import errors <EOL> from flanker . utils import to_utf8 , to_unicode <EOL> def convert_to_unicode ( charset , value ) : <EOL> if isinstance ( value , unicode ) : <EOL> return value <EOL> charset = _translate_charset ( charset ) <EOL> return to_unicode ( value , charset = charset ) <EOL> def _translate_charset ( charset ) : <EOL> """<STR_LIT>""" <EOL> if "<STR_LIT>" in charset . lower ( ) : <EOL> return '<STR_LIT>' <EOL> if "<STR_LIT>" == charset . lower ( ) : <EOL> return "<STR_LIT>" <EOL> if '<STR_LIT>' in charset . lower ( ) : <EOL> return '<STR_LIT>' <EOL> if '<STR_LIT:utf-8>' in charset . lower ( ) or charset . lower ( ) == '<STR_LIT>' : <EOL> return '<STR_LIT:utf-8>' <EOL> return charset </s>
