blob: 9cf82a69274434672ff5339bc4afe51a737feea0 [file] [log] [blame]
Jack Jansen4549b131995-08-29 11:30:24 +00001\section{Standard module \sectcode{binhex}}
2\stmodindex{binhex}
3
4This module encodes and decodes files in binhex4 format, a format
5allowing representation of Macintosh files in ASCII. On the macintosh,
6both forks of a file and the finder information are encoded (or
7decoded), on other platforms only the data fork is handled.
8
9The \code{binhex} module defines the following functions:
10
11\renewcommand{\indexsubitem}{(in module binhex)}
12
13\begin{funcdesc}{binhex}{input\, output}
14Convert a binary file with filename \var{input} to binhex file
15\var{output}. The \var{output} parameter can either be a filename or a
16file-like object (any object supporting a \var{write} and \var{close}
17method).
18\end{funcdesc}
19
20\begin{funcdesc}{hexbin}{input\optional{\, output}}
21Decode a binhex file \var{input}. \var{Input} may be a filename or a
22file-like object supporting \var{read} and \var{close} methods.
23The resulting file is written to a file named \var{output}, unless the
24argument is empty in which case the output filename is read from the
25binhex file.
26\end{funcdesc}
27
28\subsection{notes}
29There is an alternative, more powerful interface to the coder and
30decoder, see the source for details.
31
32If you code or decode textfiles on non-Macintosh platforms they will
33still use the macintosh newline convention (carriage-return as end of
34line).
35
36As of this writing, hexbin appears to not work in all cases.
37
38\section{Standard module \sectcode{uu}}
39\stmodindex{uu}
40
41This module encodes and decodes files in uuencode format, allowing
42arbitrary binary data to be transferred over ascii-only connections.
43
44The \code{uu} module defines the following functions:
45
46\renewcommand{\indexsubitem}{(in module uu)}
47
48\begin{funcdesc}{encode}{filename\, mode\, in_file\, out_file}
49Uuencode file \var{in_file} into file \var{out_file}. Both are
50file-like objects supporting a \var{read} and \var{write} method
51respectively. The uuencoded file will have the header specifying
52\var{filename} and \var{mode} as the defaults for the results of
53decoding the file.
54\end{funcdesc}
55
56\begin{funcdesc}{decode}{filename\, mode\, in_file}
57Note that this function uses a non-standard form of variable
58arguments, see below for other variants of argument lists.
59
60This call decodes uuencoded file \var{in_file} (an object supporting a
61\var{readline} method), placing the result on a file with name
62\var{filename} and mode \var{mode}.
63\end{funcdesc}
64
65\begin{funcdesc}{decode}{in_file\, out_file}
66An alternative form of \var{decode} which writes the resulting data to
67\var{out_file} (an object supporting a \var{write} method).
68\end{funcdesc}
69
70\begin{funcdesc}{decode}{in_file}
71An alternative form of \var{decode} which stores the result in the
72file specified in the uuencoded file.
73\end{funcdesc}
74
75\subsection{notes}
76This code was contributed by Lance Ellinghouse, and modified by Jack
77Jansen to use the \var{binascii} module.
78
79Encoding a file on a non-unix platforms may well result in a file
80with the incorrect newline semantics or a file extractable only on the
81original platform.
82\section{Built-in Module \sectcode{binascii}} % If implemented in C
83\bimodindex{binascii}
84
85The binascii module contains a number of methods to convert between
86binary and various ascii-encoded binary representations. Normally, you
87will not use these modules directly but use wrapper modules like
88\var{uu} or \var{hexbin} in stead, this module solely exists because
89bit-manipuation of large amounts of data is slow in python.
90
91The \code{binascii} module defines the following functions:
92
93\renewcommand{\indexsubitem}{(in module binascii)}
94
95\begin{funcdesc}{a2b_uu}{string}
96Convert a single line of uuencoded data back to binary and return the
97binary data. Lines normally contain 45 (binary) bytes, except for the
98last line. Line data may be followed by whitespace.
99\end{funcdesc}
100
101\begin{funcdesc}{b2a_uu}{data}
102Convert binary data to a line of ascii characters, the return value is
103the converted line, including a newline char. The length of \var{data}
104should be at most 45.
105\end{funcdesc}
106
107\begin{funcdesc}{a2b_hqx}{string}
108Convert binhex4 formatted ascii data to binary, without doing
109rle-decompression. The string should contain a complete number of
110binary bytes, or (in case of the last portion of the binhex4 data)
111have the remaining bits zero.
112\end{funcdesc}
113
114\begin{funcdesc}{rledecode_hqx}{data}
115Perform RLE-decompression on the data, as per the binhex4
116standard. The algorithm uses \code{0x90} after a byte as a repeat
117indicator, followed by a count. A count of \code{0} specifies a byte
118value of \code{0x90}. The routine returns the decompressed data,
119unless data input data ends in an orphaned repeat indicator, in which
120case the \var{Incomplete} exception is raised.
121\end{funcdesc}
122
123\begin{funcdesc}{rlecode_hqx}{data}
124Perform binhex4 style RLE-compression on \var{data} and return the
125result.
126\end{funcdesc}
127
128\begin{funcdesc}{b2a_hqx}{data}
129Perform hexbin4 binary-to-ascii translation and return the resulting
130string. The argument should already be rle-coded, and have a length
131divisible by 3 (except possibly the last fragment).
132\end{funcdesc}
133
134\begin{funcdesc}{crc_hqx}{data, crc}
135Compute the binhex4 crc value of \var{data}, starting with an initial
136\var{crc} and returning the result.
137\end{funcdesc}
138
139\begin{excdesc}{Error}
140Exception raised on errors. These are usually programming errors.
141\end{excdesc}
142
143\begin{excdesc}{Incomplete}
144Exception raised on incomplete data. These are usually not programming
145errors, but handled by reading a little more data and trying again.
146\end{excdesc}