Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | :mod:`uu` --- Encode and decode uuencode files |
| 2 | ============================================== |
| 3 | |
| 4 | .. module:: uu |
| 5 | :synopsis: Encode and decode files in uuencode format. |
Terry Jan Reedy | fa089b9 | 2016-06-11 15:02:54 -0400 | [diff] [blame] | 6 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 7 | .. moduleauthor:: Lance Ellinghouse |
| 8 | |
Raymond Hettinger | 1048094 | 2011-01-10 03:26:08 +0000 | [diff] [blame] | 9 | **Source code:** :source:`Lib/uu.py` |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 10 | |
Raymond Hettinger | 4f707fd | 2011-01-10 19:54:11 +0000 | [diff] [blame] | 11 | -------------- |
| 12 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 13 | This module encodes and decodes files in uuencode format, allowing arbitrary |
| 14 | binary data to be transferred over ASCII-only connections. Wherever a file |
| 15 | argument is expected, the methods accept a file-like object. For backwards |
| 16 | compatibility, a string containing a pathname is also accepted, and the |
| 17 | corresponding file will be opened for reading and writing; the pathname ``'-'`` |
| 18 | is understood to mean the standard input or output. However, this interface is |
| 19 | deprecated; it's better for the caller to open the file itself, and be sure |
| 20 | that, when required, the mode is ``'rb'`` or ``'wb'`` on Windows. |
| 21 | |
| 22 | .. index:: |
| 23 | single: Jansen, Jack |
| 24 | single: Ellinghouse, Lance |
| 25 | |
| 26 | This code was contributed by Lance Ellinghouse, and modified by Jack Jansen. |
| 27 | |
| 28 | The :mod:`uu` module defines the following functions: |
| 29 | |
| 30 | |
Xiang Zhang | 13f1f42 | 2017-05-03 11:16:21 +0800 | [diff] [blame] | 31 | .. function:: encode(in_file, out_file, name=None, mode=None, *, backtick=False) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 32 | |
Georg Brandl | f4a4123 | 2008-05-26 17:55:52 +0000 | [diff] [blame] | 33 | Uuencode file *in_file* into file *out_file*. The uuencoded file will have |
| 34 | the header specifying *name* and *mode* as the defaults for the results of |
| 35 | decoding the file. The default defaults are taken from *in_file*, or ``'-'`` |
Xiang Zhang | 13f1f42 | 2017-05-03 11:16:21 +0800 | [diff] [blame] | 36 | and ``0o666`` respectively. If *backtick* is true, zeros are represented by |
| 37 | ``'`'`` instead of spaces. |
| 38 | |
| 39 | .. versionchanged:: 3.7 |
| 40 | Added the *backtick* parameter. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 41 | |
| 42 | |
Georg Brandl | 7f01a13 | 2009-09-16 15:58:14 +0000 | [diff] [blame] | 43 | .. function:: decode(in_file, out_file=None, mode=None, quiet=False) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 44 | |
| 45 | This call decodes uuencoded file *in_file* placing the result on file |
| 46 | *out_file*. If *out_file* is a pathname, *mode* is used to set the permission |
| 47 | bits if the file must be created. Defaults for *out_file* and *mode* are taken |
| 48 | from the uuencode header. However, if the file specified in the header already |
| 49 | exists, a :exc:`uu.Error` is raised. |
| 50 | |
| 51 | :func:`decode` may print a warning to standard error if the input was produced |
| 52 | by an incorrect uuencoder and Python could recover from that error. Setting |
| 53 | *quiet* to a true value silences this warning. |
| 54 | |
| 55 | |
| 56 | .. exception:: Error() |
| 57 | |
| 58 | Subclass of :exc:`Exception`, this can be raised by :func:`uu.decode` under |
| 59 | various situations, such as described above, but also including a badly |
| 60 | formatted header, or truncated input file. |
| 61 | |
| 62 | |
| 63 | .. seealso:: |
| 64 | |
| 65 | Module :mod:`binascii` |
| 66 | Support module containing ASCII-to-binary and binary-to-ASCII conversions. |