blob: 6938eeb54c411f4eca2b2eaa8cb00ec7263fd834 [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
Jack Jansen7e183e91995-08-30 12:23:43 +000036As of this writing, \var{hexbin} appears to not work in all cases.
Jack Jansen4549b131995-08-29 11:30:24 +000037
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.
Jack Jansen7e183e91995-08-30 12:23:43 +000043Whereever a file argument is expected, the methods accept either a
44pathname (\code{'-'} for stdin/stdout) or a file-like object.
45
46Normally you would pass filenames, but there is one case where you
47have to open the file yourself: if you are on a non-unix platform and
48your binary file is actually a textfile that you want encoded
49unix-compatible you will have to open the file yourself as a textfile,
50so newline conversion is performed.
51
52This code was contributed by Lance Ellinghouse, and modified by Jack
53Jansen.
Jack Jansen4549b131995-08-29 11:30:24 +000054
55The \code{uu} module defines the following functions:
56
57\renewcommand{\indexsubitem}{(in module uu)}
58
Jack Jansen7e183e91995-08-30 12:23:43 +000059\begin{funcdesc}{encode}{in_file\, out_file\optional{\, name\, mode}}
60Uuencode file \var{in_file} into file \var{out_file}. The uuencoded
61file will have the header specifying \var{name} and \var{mode} as the
62defaults for the results of decoding the file. The default defaults
63are taken from \var{in_file}, or \code{'-'} and \code{0666}
64respectively.
Jack Jansen4549b131995-08-29 11:30:24 +000065\end{funcdesc}
66
Jack Jansen7e183e91995-08-30 12:23:43 +000067\begin{funcdesc}{decode}{in_file\optional{\, out_file\, mode}}
68This call decodes uuencoded file \var{in_file} placing the result on
69file \var{out_file}. If \var{out_file} is a pathname the \var{mode} is
70also set. Defaults for \var{out_file} and \var{mode} are taken from
71the uuencode header.
Jack Jansen4549b131995-08-29 11:30:24 +000072\end{funcdesc}
73
Jack Jansen4549b131995-08-29 11:30:24 +000074\section{Built-in Module \sectcode{binascii}} % If implemented in C
75\bimodindex{binascii}
76
77The binascii module contains a number of methods to convert between
78binary and various ascii-encoded binary representations. Normally, you
79will not use these modules directly but use wrapper modules like
80\var{uu} or \var{hexbin} in stead, this module solely exists because
81bit-manipuation of large amounts of data is slow in python.
82
83The \code{binascii} module defines the following functions:
84
85\renewcommand{\indexsubitem}{(in module binascii)}
86
87\begin{funcdesc}{a2b_uu}{string}
88Convert a single line of uuencoded data back to binary and return the
89binary data. Lines normally contain 45 (binary) bytes, except for the
90last line. Line data may be followed by whitespace.
91\end{funcdesc}
92
93\begin{funcdesc}{b2a_uu}{data}
94Convert binary data to a line of ascii characters, the return value is
95the converted line, including a newline char. The length of \var{data}
96should be at most 45.
97\end{funcdesc}
98
Jack Jansen06cf5d01995-10-10 14:41:03 +000099\begin{funcdesc}{a2b_base64}{string}
100Convert a block of base64 data back to binary and return the
101binary data. More than one line may be passed at a time.
102\end{funcdesc}
103
104\begin{funcdesc}{b2a_base64}{data}
105Convert binary data to a line of ascii characters in base64 coding.
106The return value is the converted line, including a newline char.
107The length of \var{data} should be at most 57 to adhere to the base64
108standard.
109\end{funcdesc}
110
Jack Jansen4549b131995-08-29 11:30:24 +0000111\begin{funcdesc}{a2b_hqx}{string}
112Convert binhex4 formatted ascii data to binary, without doing
113rle-decompression. The string should contain a complete number of
114binary bytes, or (in case of the last portion of the binhex4 data)
115have the remaining bits zero.
116\end{funcdesc}
117
118\begin{funcdesc}{rledecode_hqx}{data}
119Perform RLE-decompression on the data, as per the binhex4
120standard. The algorithm uses \code{0x90} after a byte as a repeat
121indicator, followed by a count. A count of \code{0} specifies a byte
122value of \code{0x90}. The routine returns the decompressed data,
123unless data input data ends in an orphaned repeat indicator, in which
124case the \var{Incomplete} exception is raised.
125\end{funcdesc}
126
127\begin{funcdesc}{rlecode_hqx}{data}
128Perform binhex4 style RLE-compression on \var{data} and return the
129result.
130\end{funcdesc}
131
132\begin{funcdesc}{b2a_hqx}{data}
133Perform hexbin4 binary-to-ascii translation and return the resulting
134string. The argument should already be rle-coded, and have a length
135divisible by 3 (except possibly the last fragment).
136\end{funcdesc}
137
138\begin{funcdesc}{crc_hqx}{data, crc}
139Compute the binhex4 crc value of \var{data}, starting with an initial
140\var{crc} and returning the result.
141\end{funcdesc}
142
143\begin{excdesc}{Error}
144Exception raised on errors. These are usually programming errors.
145\end{excdesc}
146
147\begin{excdesc}{Incomplete}
148Exception raised on incomplete data. These are usually not programming
149errors, but handled by reading a little more data and trying again.
150\end{excdesc}