'Return the given header name or value, encoded for HTTP output.'

def encode(cls, v):

    for enc in cls.encodings:
        try:
            return v.encode(enc)
        except UnicodeEncodeError:
            continue
    if ((cls.protocol == (1, 1)) and cls.use_rfc_2047):
        v = b2a_base64(v.encode('utf-8'))
        return ((ntob('=?utf-8?b?') + v.strip(ntob('\n'))) + ntob('?='))
    raise ValueError(('Could    not    encode    header    part    %r    using    any    of    the    encodings    %r.' % (v, cls.encodings)))
