diff options
author | Guido van Rossum <guido@python.org> | 1997-07-11 16:33:26 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-07-11 16:33:26 (GMT) |
commit | e3cd151d1f9b280217247d6e4f28932b96dc5322 (patch) | |
tree | b70e07a42d0ade7639f99489dcb52f640e15bac8 /Lib/mimetools.py | |
parent | 31cbc846ac3c7f95e570e7b122d4345cf4553d93 (diff) | |
download | cpython-e3cd151d1f9b280217247d6e4f28932b96dc5322.zip cpython-e3cd151d1f9b280217247d6e4f28932b96dc5322.tar.gz cpython-e3cd151d1f9b280217247d6e4f28932b96dc5322.tar.bz2 |
Use the modules base64, quopri, and uu, instead of external programs
to decode/encode the standard transfer encodings.
Diffstat (limited to 'Lib/mimetools.py')
-rw-r--r-- | Lib/mimetools.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/Lib/mimetools.py b/Lib/mimetools.py index eadc11a..cda1f37 100644 --- a/Lib/mimetools.py +++ b/Lib/mimetools.py @@ -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 |