uu — Encode and decode uuencode files

Source code:Lib/uu.py


This module encodes and decodes files in uuencode format, allowing arbitrarybinary data to be transferred over ASCII-only connections. Wherever a fileargument is expected, the methods accept a file-like object. For backwardscompatibility, a string containing a pathname is also accepted, and thecorresponding file will be opened for reading and writing; the pathname'-'is understood to mean the standard input or output. However, this interface isdeprecated; it’s better for the caller to open the file itself, and be surethat, when required, the mode is'rb' or'wb' on Windows.

This code was contributed by Lance Ellinghouse, and modified by Jack Jansen.

Theuu module defines the following functions:

uu.encode(in_file,out_file,name=None,mode=None,*,backtick=False)

Uuencode filein_file into fileout_file. The uuencoded file will havethe header specifyingname andmode as the defaults for the results ofdecoding the file. The default defaults are taken fromin_file, or'-'and0o666 respectively. Ifbacktick is true, zeros are represented by'`' instead of spaces.

Changed in version 3.7:Added thebacktick parameter.

uu.decode(in_file,out_file=None,mode=None,quiet=False)

This call decodes uuencoded filein_file placing the result on fileout_file. Ifout_file is a pathname,mode is used to set the permissionbits if the file must be created. Defaults forout_file andmode are takenfrom the uuencode header. However, if the file specified in the header alreadyexists, auu.Error is raised.

decode() may print a warning to standard error if the input was producedby an incorrect uuencoder and Python could recover from that error. Settingquiet to a true value silences this warning.

exceptionuu.Error

Subclass ofException, this can be raised byuu.decode() undervarious situations, such as described above, but also including a badlyformatted header, or truncated input file.

See also

Modulebinascii

Support module containing ASCII-to-binary and binary-to-ASCII conversions.