blob: 33974c8c52785d631656fa94ff26a9a32e67487a [file] [log] [blame]
Jack Jansen4549b131995-08-29 11:30:24 +00001\section{Standard module \sectcode{binhex}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-binhex}
Jack Jansen4549b131995-08-29 11:30:24 +00003\stmodindex{binhex}
4
5This module encodes and decodes files in binhex4 format, a format
6allowing representation of Macintosh files in ASCII. On the macintosh,
7both forks of a file and the finder information are encoded (or
8decoded), on other platforms only the data fork is handled.
9
10The \code{binhex} module defines the following functions:
11
12\renewcommand{\indexsubitem}{(in module binhex)}
13
14\begin{funcdesc}{binhex}{input\, output}
15Convert a binary file with filename \var{input} to binhex file
16\var{output}. The \var{output} parameter can either be a filename or a
17file-like object (any object supporting a \var{write} and \var{close}
18method).
19\end{funcdesc}
20
21\begin{funcdesc}{hexbin}{input\optional{\, output}}
Guido van Rossume9a07321997-04-27 21:29:51 +000022Decode a binhex file \var{input}. \var{input} may be a filename or a
Jack Jansen4549b131995-08-29 11:30:24 +000023file-like object supporting \var{read} and \var{close} methods.
24The resulting file is written to a file named \var{output}, unless the
25argument is empty in which case the output filename is read from the
26binhex file.
27\end{funcdesc}
28
29\subsection{notes}
30There is an alternative, more powerful interface to the coder and
31decoder, see the source for details.
32
33If you code or decode textfiles on non-Macintosh platforms they will
34still use the macintosh newline convention (carriage-return as end of
35line).
36
Jack Jansen7e183e91995-08-30 12:23:43 +000037As of this writing, \var{hexbin} appears to not work in all cases.
Jack Jansen4549b131995-08-29 11:30:24 +000038
39\section{Standard module \sectcode{uu}}
40\stmodindex{uu}
41
42This module encodes and decodes files in uuencode format, allowing
43arbitrary binary data to be transferred over ascii-only connections.
Guido van Rossume9a07321997-04-27 21:29:51 +000044Wherever a file argument is expected, the methods accept a file-like
45object. For backwards compatibility, a string containing a pathname
46is also accepted, and the corresponding file will be opened for
47reading and writing; the pathname \code{'-'} is understood to mean the
48standard input or output. However, this interface is deprecated; it's
49better for the caller to open the file itself, and be sure that, when
50required, the mode is \code{'rb'} or \code{'wb'} on Windows or DOS.
Jack Jansen7e183e91995-08-30 12:23:43 +000051
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}