Use the modules base64, quopri, and uu, instead of external programs
to decode/encode the standard transfer encodings.
This commit is contained in:
parent
31cbc846ac
commit
e3cd151d1f
|
@ -131,9 +131,16 @@ def choose_boundary():
|
|||
|
||||
# Subroutines for decoding some common content-transfer-types
|
||||
|
||||
# XXX This requires that uudecode and mmencode are in $PATH
|
||||
|
||||
def decode(input, output, encoding):
|
||||
if encoding == 'base64':
|
||||
import base64
|
||||
return base64.decode(input, output)
|
||||
if encoding == 'quoted-printable':
|
||||
import quopri
|
||||
return quopri.decode(input, output)
|
||||
if encoding in ('uuencode', 'x-uuencode'):
|
||||
import uu
|
||||
return uu.decode(input, output)
|
||||
if decodetab.has_key(encoding):
|
||||
pipethrough(input, decodetab[encoding], output)
|
||||
else:
|
||||
|
@ -141,12 +148,25 @@ def decode(input, output, encoding):
|
|||
'unknown Content-Transfer-Encoding: %s' % encoding
|
||||
|
||||
def encode(input, output, encoding):
|
||||
if encoding == 'base64':
|
||||
import base64
|
||||
return base64.encode(input, output)
|
||||
if encoding == 'quoted-printable':
|
||||
import quopri
|
||||
return quopri.encode(input, output, 0)
|
||||
if encoding in ('uuencode', 'x-uuencode'):
|
||||
import uu
|
||||
return uu.encode(input, output)
|
||||
if encodetab.has_key(encoding):
|
||||
pipethrough(input, encodetab[encoding], output)
|
||||
else:
|
||||
raise ValueError, \
|
||||
'unknown Content-Transfer-Encoding: %s' % encoding
|
||||
|
||||
# The following is no longer used for standard encodings
|
||||
|
||||
# XXX This requires that uudecode and mmencode are in $PATH
|
||||
|
||||
uudecode_pipe = '''(
|
||||
TEMP=/tmp/@uu.$$
|
||||
sed "s%^begin [0-7][0-7]* .*%begin 600 $TEMP%" | uudecode
|
||||
|
|
Loading…
Reference in New Issue