<s> """<STR_LIT>""" <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> from binascii import b2a_base64 , a2b_base64 <EOL> from email . utils import fix_eols <EOL> CRLF = '<STR_LIT:\r\n>' <EOL> NL = '<STR_LIT:\n>' <EOL> EMPTYSTRING = '<STR_LIT>' <EOL> MISC_LEN = <NUM_LIT:7> <EOL> def base64_len ( s ) : <EOL> """<STR_LIT>""" <EOL> groups_of_3 , leftover = divmod ( len ( s ) , <NUM_LIT:3> ) <EOL> n = groups_of_3 * <NUM_LIT:4> <EOL> if leftover : <EOL> n += <NUM_LIT:4> <EOL> return n <EOL> def header_encode ( header , charset = '<STR_LIT>' , keep_eols = False , <EOL> maxlinelen = <NUM_LIT> , eol = NL ) : <EOL> """<STR_LIT>""" <EOL> if not header : <EOL> return header <EOL> if not keep_eols : <EOL> header = fix_eols ( header ) <EOL> base64ed = [ ] <EOL> max_encoded = maxlinelen - len ( charset ) - MISC_LEN <EOL> max_unencoded = max_encoded * <NUM_LIT:3> // <NUM_LIT:4> <EOL> for i in range ( <NUM_LIT:0> , len ( header ) , max_unencoded ) : <EOL> base64ed . append ( b2a_base64 ( header [ i : i + max_unencoded ] ) ) <EOL> lines = [ ] <EOL> for line in base64ed : <EOL> if line . endswith ( NL ) : <EOL> line = line [ : - <NUM_LIT:1> ] <EOL> lines . append ( '<STR_LIT>' % ( charset , line ) ) <EOL> joiner = eol + '<STR_LIT:U+0020>' <EOL> return joiner . join ( lines ) <EOL> def encode ( s , binary = True , maxlinelen = <NUM_LIT> , eol = NL ) : <EOL> """<STR_LIT>""" <EOL> if not s : <EOL> return s <EOL> if not binary : <EOL> s = fix_eols ( s ) <EOL> encvec = [ ] <EOL> max_unencoded = maxlinelen * <NUM_LIT:3> // <NUM_LIT:4> <EOL> for i in range ( <NUM_LIT:0> , len ( s ) , max_unencoded ) : <EOL> enc = b2a_base64 ( s [ i : i + max_unencoded ] ) <EOL> if enc . endswith ( NL ) and eol != NL : <EOL> enc = enc [ : - <NUM_LIT:1> ] + eol <EOL> encvec . append ( enc ) <EOL> return EMPTYSTRING . join ( encvec ) <EOL> body_encode = encode <EOL> encodestring = encode <EOL> def decode ( s , convert_eols = None ) : <EOL> """<STR_LIT>""" <EOL> if not s : <EOL> return s <EOL> dec = a2b_base64 ( s ) <EOL> if convert_eols : <EOL> return dec . replace ( CRLF , convert_eols ) <EOL> return dec <EOL> body_decode = decode <EOL> decodestring = decode </s>
