43 def encode(input, output, quotetabs, header = 0):
44 """Read 'input', apply quoted-printable encoding, and write to 'output'.
46 'input' and 'output' are files with readline() and write() methods.
47 The 'quotetabs' flag indicates whether embedded tabs and spaces should be
48 quoted. Note that line-ending tabs and spaces are always encoded, as per
50 The 'header' flag indicates whether we are encoding spaces as _ as per
54 if b2a_qp
is not None:
56 odata =
b2a_qp(data, quotetabs = quotetabs, header = header)
60 def write(s, output=output, lineEnd='\n'):
63 if s
and s[-1:]
in ' \t':
64 output.write(s[:-1] +
quote(s[-1]) + lineEnd)
66 output.write(
quote(s) + lineEnd)
68 output.write(s + lineEnd)
72 line = input.readline()
85 if header
and c ==
' ':
90 if prevline
is not None:
94 thisline = EMPTYSTRING.join(outline)
95 while len(thisline) > MAXLINESIZE:
98 write(thisline[:MAXLINESIZE-1], lineEnd=
'=\n')
99 thisline = thisline[MAXLINESIZE-1:]
103 if prevline
is not None:
104 write(prevline, lineEnd=stripped)