blob: 4e3d67414c20e23b992e76855e7601900351b649 [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}}
Guido van Rossume9a07321997-04-27 21:29:51 +000021Decode a binhex file \var{input}. \var{input} may be a filename or a
Jack Jansen4549b131995-08-29 11:30:24 +000022file-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.
Guido van Rossume9a07321997-04-27 21:29:51 +000043Wherever a file argument is expected, the methods accept a file-like
44object. For backwards compatibility, a string containing a pathname
45is also accepted, and the corresponding file will be opened for
46reading and writing; the pathname \code{'-'} is understood to mean the
47standard input or output. However, this interface is deprecated; it's
48better for the caller to open the file itself, and be sure that, when
49required, the mode is \code{'rb'} or \code{'wb'} on Windows or DOS.
Jack Jansen7e183e91995-08-30 12:23:43 +000050
51This code was contributed by Lance Ellinghouse, and modified by Jack
52Jansen.
Jack Jansen4549b131995-08-29 11:30:24 +000053
54The \code{uu} module defines the following functions:
55
56\renewcommand{\indexsubitem}{(in module uu)}
57
Jack Jansen7e183e91995-08-30 12:23:43 +000058\begin{funcdesc}{encode}{in_file\, out_file\optional{\, name\, mode}}
59Uuencode file \var{in_file} into file \var{out_file}. The uuencoded
60file will have the header specifying \var{name} and \var{mode} as the
61defaults for the results of decoding the file. The default defaults
62are taken from \var{in_file}, or \code{'-'} and \code{0666}
63respectively.
Jack Jansen4549b131995-08-29 11:30:24 +000064\end{funcdesc}
65
Jack Jansen7e183e91995-08-30 12:23:43 +000066\begin{funcdesc}{decode}{in_file\optional{\, out_file\, mode}}
67This call decodes uuencoded file \var{in_file} placing the result on
68file \var{out_file}. If \var{out_file} is a pathname the \var{mode} is
69also set. Defaults for \var{out_file} and \var{mode} are taken from
70the uuencode header.
Jack Jansen4549b131995-08-29 11:30:24 +000071\end{funcdesc}
72
Jack Jansen4549b131995-08-29 11:30:24 +000073\section{Built-in Module \sectcode{binascii}} % If implemented in C
74\bimodindex{binascii}
75
76The binascii module contains a number of methods to convert between
77binary and various ascii-encoded binary representations. Normally, you
78will not use these modules directly but use wrapper modules like
79\var{uu} or \var{hexbin} in stead, this module solely exists because
80bit-manipuation of large amounts of data is slow in python.
81
82The \code{binascii} module defines the following functions:
83
84\renewcommand{\indexsubitem}{(in module binascii)}
85
86\begin{funcdesc}{a2b_uu}{string}
87Convert a single line of uuencoded data back to binary and return the
88binary data. Lines normally contain 45 (binary) bytes, except for the
89last line. Line data may be followed by whitespace.
90\end{funcdesc}
91
92\begin{funcdesc}{b2a_uu}{data}
93Convert binary data to a line of ascii characters, the return value is
94the converted line, including a newline char. The length of \var{data}
95should be at most 45.
96\end{funcdesc}
97
Jack Jansen06cf5d01995-10-10 14:41:03 +000098\begin{funcdesc}{a2b_base64}{string}
99Convert a block of base64 data back to binary and return the
100binary data. More than one line may be passed at a time.
101\end{funcdesc}
102
103\begin{funcdesc}{b2a_base64}{data}
104Convert binary data to a line of ascii characters in base64 coding.
105The return value is the converted line, including a newline char.
106The length of \var{data} should be at most 57 to adhere to the base64
107standard.
108\end{funcdesc}
109
Jack Jansen4549b131995-08-29 11:30:24 +0000110\begin{funcdesc}{a2b_hqx}{string}
111Convert binhex4 formatted ascii data to binary, without doing
112rle-decompression. The string should contain a complete number of
113binary bytes, or (in case of the last portion of the binhex4 data)
114have the remaining bits zero.
115\end{funcdesc}
116
117\begin{funcdesc}{rledecode_hqx}{data}
118Perform RLE-decompression on the data, as per the binhex4
119standard. The algorithm uses \code{0x90} after a byte as a repeat
120indicator, followed by a count. A count of \code{0} specifies a byte
121value of \code{0x90}. The routine returns the decompressed data,
122unless data input data ends in an orphaned repeat indicator, in which
123case the \var{Incomplete} exception is raised.
124\end{funcdesc}
125
126\begin{funcdesc}{rlecode_hqx}{data}
127Perform binhex4 style RLE-compression on \var{data} and return the
128result.
129\end{funcdesc}
130
131\begin{funcdesc}{b2a_hqx}{data}
132Perform hexbin4 binary-to-ascii translation and return the resulting
133string. The argument should already be rle-coded, and have a length
134divisible by 3 (except possibly the last fragment).
135\end{funcdesc}
136
137\begin{funcdesc}{crc_hqx}{data, crc}
138Compute the binhex4 crc value of \var{data}, starting with an initial
139\var{crc} and returning the result.
140\end{funcdesc}
141
142\begin{excdesc}{Error}
143Exception raised on errors. These are usually programming errors.
144\end{excdesc}
145
146\begin{excdesc}{Incomplete}
147Exception raised on incomplete data. These are usually not programming
148errors, but handled by reading a little more data and trying again.
149\end{excdesc}