def get_encoded_word(value):
    """ encoded-word = "=?" charset "?" encoding "?" encoded-text "?="

    """
    ew = EncodedWord()
    if not value.startswith('=?'):
        raise errors.HeaderParseError(
            "expected encoded word but found {}".format(value))
    _3to2list1 = list(value[2:].split('?=', 1))
    tok, remainder, = _3to2list1[:1] + [_3to2list1[1:]]
    if tok == value[2:]:
        raise errors.HeaderParseError(
            "expected encoded word but found {}".format(value))
    remstr = ''.join(remainder)
    if remstr[:2].isdigit():
        _3to2list3 = list(remstr.split('?=', 1))
        rest, remainder, = _3to2list3[:1] + [_3to2list3[1:]]
        tok = tok + '?=' + rest
    if len(tok.split()) > 1:
        ew.defects.append(errors.InvalidHeaderDefect(
            "whitespace inside encoded word"))
    ew.cte = value
    value = ''.join(remainder)
    try:
        text, charset, lang, defects = _ew.decode('=?' + tok + '?=')
    except ValueError:
        raise errors.HeaderParseError(
            "encoded word format invalid: '{}'".format(ew.cte))
    ew.charset = charset
    ew.lang = lang
    ew.defects.extend(defects)
    while text:
        if text[0] in WSP:
            token, text = get_fws(text)
            ew.append(token)
            continue
        _3to2list5 = list(_wsp_splitter(text, 1))
        chars, remainder, = _3to2list5[:1] + [_3to2list5[1:]]
        vtext = ValueTerminal(chars, 'vtext')
        _validate_xtext(vtext)
        ew.append(vtext)
        text = ''.join(remainder)
    return ew, value
def get_encoded_word ( value ) : ew = EncodedWord ( ) if not value . startswith ( '=?' ) : raise errors . HeaderParseError ( "expected encoded word but found {}" . format ( value ) ) _3to2list1 = list ( value [ 2 : ] . split ( '?=' , 1 ) ) tok , remainder , = _3to2list1 [ : 1 ] + [ _3to2list1 [ 1 : ] ] if tok == value [ 2 : ] : raise errors . HeaderParseError ( "expected encoded word but found {}" . format ( value ) ) remstr = '' . join ( remainder ) if remstr [ : 2 ] . isdigit ( ) : _3to2list3 = list ( remstr . split ( '?=' , 1 ) ) rest , remainder , = _3to2list3 [ : 1 ] + [ _3to2list3 [ 1 : ] ] tok = tok + '?=' + rest if len ( tok . split ( ) ) > 1 : ew . defects . append ( errors . InvalidHeaderDefect ( "whitespace inside encoded word" ) ) ew . cte = value value = '' . join ( remainder ) try : text , charset , lang , defects = _ew . decode ( '=?' + tok + '?=' ) except ValueError : raise errors . HeaderParseError ( "encoded word format invalid: '{}'" . format ( ew . cte ) ) ew . charset = charset ew . lang = lang ew . defects . extend ( defects ) while text : if text [ 0 ] in WSP : token , text = get_fws ( text ) ew . append ( token ) continue _3to2list5 = list ( _wsp_splitter ( text , 1 ) ) chars , remainder , = _3to2list5 [ : 1 ] + [ _3to2list5 [ 1 : ] ] vtext = ValueTerminal ( chars , 'vtext' ) _validate_xtext ( vtext ) ew . append ( vtext ) text = '' . join ( remainder ) return ew , value
encoded-word = "=?" charset "?" encoding "?" encoded-text "?="