blob: d61c178831aa0732d31eb76e56c79f9d40dcf57b [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`uu` --- Encode and decode uuencode files
2==============================================
3
4.. module:: uu
5 :synopsis: Encode and decode files in uuencode format.
6.. moduleauthor:: Lance Ellinghouse
7
Raymond Hettinger10480942011-01-10 03:26:08 +00008**Source code:** :source:`Lib/uu.py`
Georg Brandl116aa622007-08-15 14:28:22 +00009
Raymond Hettinger4f707fd2011-01-10 19:54:11 +000010--------------
11
Georg Brandl116aa622007-08-15 14:28:22 +000012This module encodes and decodes files in uuencode format, allowing arbitrary
13binary data to be transferred over ASCII-only connections. Wherever a file
14argument is expected, the methods accept a file-like object. For backwards
15compatibility, a string containing a pathname is also accepted, and the
16corresponding file will be opened for reading and writing; the pathname ``'-'``
17is understood to mean the standard input or output. However, this interface is
18deprecated; it's better for the caller to open the file itself, and be sure
19that, when required, the mode is ``'rb'`` or ``'wb'`` on Windows.
20
21.. index::
22 single: Jansen, Jack
23 single: Ellinghouse, Lance
24
25This code was contributed by Lance Ellinghouse, and modified by Jack Jansen.
26
27The :mod:`uu` module defines the following functions:
28
29
Georg Brandl7f01a132009-09-16 15:58:14 +000030.. function:: encode(in_file, out_file, name=None, mode=None)
Georg Brandl116aa622007-08-15 14:28:22 +000031
Georg Brandlf4a41232008-05-26 17:55:52 +000032 Uuencode file *in_file* into file *out_file*. The uuencoded file will have
33 the header specifying *name* and *mode* as the defaults for the results of
34 decoding the file. The default defaults are taken from *in_file*, or ``'-'``
35 and ``0o666`` respectively.
Georg Brandl116aa622007-08-15 14:28:22 +000036
37
Georg Brandl7f01a132009-09-16 15:58:14 +000038.. function:: decode(in_file, out_file=None, mode=None, quiet=False)
Georg Brandl116aa622007-08-15 14:28:22 +000039
40 This call decodes uuencoded file *in_file* placing the result on file
41 *out_file*. If *out_file* is a pathname, *mode* is used to set the permission
42 bits if the file must be created. Defaults for *out_file* and *mode* are taken
43 from the uuencode header. However, if the file specified in the header already
44 exists, a :exc:`uu.Error` is raised.
45
46 :func:`decode` may print a warning to standard error if the input was produced
47 by an incorrect uuencoder and Python could recover from that error. Setting
48 *quiet* to a true value silences this warning.
49
50
51.. exception:: Error()
52
53 Subclass of :exc:`Exception`, this can be raised by :func:`uu.decode` under
54 various situations, such as described above, but also including a badly
55 formatted header, or truncated input file.
56
57
58.. seealso::
59
60 Module :mod:`binascii`
61 Support module containing ASCII-to-binary and binary-to-ASCII conversions.