annotate Doc/lib/libxdrlib.tex @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents b218f294b726
children 3468ea8645ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4047
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 \section{Standard module \sectcode{xdrlib}}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 \stmodindex{xdrlib}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 \index{XDR}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 \renewcommand{\indexsubitem}{(in module xdrlib)}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 The \code{xdrlib} module supports the External Data Representation
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 Standard as described in RFC 1014, written by Sun Microsystems,
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 Inc. June 1987. It supports most of the data types described in the
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 RFC, although some, most notably \code{float} and \code{double} are
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 only supported on those operating systems that provide an XDR
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 library.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 The \code{xdrlib} module defines two classes, one for packing
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 variables into XDR representation, and another for unpacking from XDR
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 representation. There are also two exception classes.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
19
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 \subsection{Packer Objects}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
21
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 \code{Packer} is the class for packing data into XDR representation.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 The \code{Packer} class is instantiated with no arguments.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
24
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 \begin{funcdesc}{get_buffer}{}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 Returns the current pack buffer as a string.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 \begin{funcdesc}{reset}{}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 Resets the pack buffer to the empty string.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 In general, you can pack any of the most common XDR data types by
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 calling the appropriate \code{pack_\var{type}} method. Each method
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 takes a single argument, the value to pack. The following simple data
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 type packing methods are supported: \code{pack_uint}, \code{pack_int},
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 \code{pack_enum}, \code{pack_bool}, \code{pack_uhyper},
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 and \code{pack_hyper}.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 The following methods pack floating point numbers, however they
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 require C library support. Without the optional C built-in module,
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 both of these methods will raise an \code{xdrlib.ConversionError}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 exception. See the note at the end of this chapter for details.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 \begin{funcdesc}{pack_float}{value}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 Packs the single-precision floating point number \var{value}.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 \begin{funcdesc}{pack_double}{value}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 Packs the double-precision floating point number \var{value}.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
52
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 The following methods support packing strings, bytes, and opaque data:
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
54
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 \begin{funcdesc}{pack_fstring}{n\, s}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 Packs a fixed length string, \var{s}. \var{n} is the length of the
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 string but it is \emph{not} packed into the data buffer. The string
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 is padded with null bytes if necessary to guaranteed 4 byte alignment.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
60
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 \begin{funcdesc}{pack_fopaque}{n\, data}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 Packs a fixed length opaque data stream, similarly to
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 \code{pack_fstring}.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
65
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 \begin{funcdesc}{pack_string}{s}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 Packs a variable length string, \var{s}. The length of the string is
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 first packed as an unsigned integer, then the string data is packed
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 with \code{pack_fstring}.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
71
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 \begin{funcdesc}{pack_opaque}{data}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 Packs a variable length opaque data string, similarly to
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 \code{pack_string}.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 \begin{funcdesc}{pack_bytes}{bytes}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 Packs a variable length byte stream, similarly to \code{pack_string}.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
80
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 The following methods support packing arrays and lists:
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
82
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 \begin{funcdesc}{pack_list}{list\, pack_item}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 Packs a \var{list} of homogeneous items. This method is useful for
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 lists with an indeterminate size; i.e. the size is not available until
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 the entire list has been walked. For each item in the list, an
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 unsigned integer \code{1} is packed first, followed by the data value
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 from the list. \var{pack_item} is the function that is called to pack
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 the individual item. At the end of the list, an unsigned integer
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 \code{0} is packed.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 \begin{funcdesc}{pack_farray}{n\, array\, pack_item}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 Packs a fixed length list (\var{array}) of homogeneous items. \var{n}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 is the length of the list; it is \emph{not} packed into the buffer,
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 but a \code{ValueError} exception is raised if \code{len(array)} is not
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 equal to \var{n}. As above, \var{pack_item} is the function used to
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 pack each element.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
100
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 \begin{funcdesc}{pack_array}{list\, pack_item}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 Packs a variable length \var{list} of homogeneous items. First, the
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 length of the list is packed as an unsigned integer, then each element
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 is packed as in \code{pack_farray} above.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
106
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 \subsection{Unpacker Objects}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
108
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 \code{Unpacker} is the complementary class which unpacks XDR data
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 values from a string buffer, and has the following methods:
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
111
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 \begin{funcdesc}{__init__}{data}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 Instantiates an \code{Unpacker} object with the string buffer
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 \var{data}.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
116
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 \begin{funcdesc}{reset}{data}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 Resets the string buffer with the given \var{data}.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
120
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 \begin{funcdesc}{get_position}{}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 Returns the current unpack position in the data buffer.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
124
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 \begin{funcdesc}{set_position}{position}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 Sets the data buffer unpack position to \var{position}. You should be
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 careful about using \code{get_position()} and \code{set_position()}.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
4579
e3f71ce8e6bb Describe the new Unpacker.get_buffer() method.
Barry Warsaw <barry@python.org>
parents: 4339
diff changeset
130 \begin{funcdesc}{get_buffer}{}
e3f71ce8e6bb Describe the new Unpacker.get_buffer() method.
Barry Warsaw <barry@python.org>
parents: 4339
diff changeset
131 Returns the current unpack data buffer as a string.
e3f71ce8e6bb Describe the new Unpacker.get_buffer() method.
Barry Warsaw <barry@python.org>
parents: 4339
diff changeset
132 \end{funcdesc}
e3f71ce8e6bb Describe the new Unpacker.get_buffer() method.
Barry Warsaw <barry@python.org>
parents: 4339
diff changeset
133
4047
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 \begin{funcdesc}{done}{}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 Indicates unpack completion. Raises an \code{xdrlib.Error} exception
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 if all of the data has not been unpacked.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
138
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 In addition, every data type that can be packed with a \code{Packer},
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 can be unpacked with an \code{Unpacker}. Unpacking methods are of the
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 form \code{unpack_\var{type}}, and take no arguments. They return the
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 unpacked object. The same caveats apply for \code{unpack_float} and
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 \code{unpack_double} as above.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
144
4339
e7ba092c3cf3 Nits corrected by Fred
Guido van Rossum <guido@python.org>
parents: 4047
diff changeset
145 \begin{funcdesc}{unpack_float}{}
e7ba092c3cf3 Nits corrected by Fred
Guido van Rossum <guido@python.org>
parents: 4047
diff changeset
146 Unpacks a single-precision floating point number.
e7ba092c3cf3 Nits corrected by Fred
Guido van Rossum <guido@python.org>
parents: 4047
diff changeset
147 \end{funcdesc}
e7ba092c3cf3 Nits corrected by Fred
Guido van Rossum <guido@python.org>
parents: 4047
diff changeset
148
e7ba092c3cf3 Nits corrected by Fred
Guido van Rossum <guido@python.org>
parents: 4047
diff changeset
149 \begin{funcdesc}{unpack_double}{}
e7ba092c3cf3 Nits corrected by Fred
Guido van Rossum <guido@python.org>
parents: 4047
diff changeset
150 Unpacks a double-precision floating point number, similarly to
e7ba092c3cf3 Nits corrected by Fred
Guido van Rossum <guido@python.org>
parents: 4047
diff changeset
151 \code{unpack_float}.
e7ba092c3cf3 Nits corrected by Fred
Guido van Rossum <guido@python.org>
parents: 4047
diff changeset
152 \end{funcdesc}
e7ba092c3cf3 Nits corrected by Fred
Guido van Rossum <guido@python.org>
parents: 4047
diff changeset
153
4047
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 In addition, the following methods unpack strings, bytes, and opaque
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 data:
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
156
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 \begin{funcdesc}{unpack_fstring}{n}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 Unpacks and returns a fixed length string. \var{n} is the number of
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 characters expected. Padding with null bytes to guaranteed 4 byte
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 alignment is assumed.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
162
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 \begin{funcdesc}{unpack_fopaque}{n}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 Unpacks and returns a fixed length opaque data stream, similarly to
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 \code{unpack_fstring}.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
167
4339
e7ba092c3cf3 Nits corrected by Fred
Guido van Rossum <guido@python.org>
parents: 4047
diff changeset
168 \begin{funcdesc}{unpack_string}{}
4047
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 Unpacks and returns a variable length string. The length of the
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 string is first unpacked as an unsigned integer, then the string data
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 is unpacked with \code{unpack_fstring}.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
173
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 \begin{funcdesc}{unpack_opaque}{}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 Unpacks and returns a variable length opaque data string, similarly to
4339
e7ba092c3cf3 Nits corrected by Fred
Guido van Rossum <guido@python.org>
parents: 4047
diff changeset
176 \code{unpack_string}.
4047
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
178
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 \begin{funcdesc}{unpack_bytes}{}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 Unpacks and returns a variable length byte stream, similarly to
4339
e7ba092c3cf3 Nits corrected by Fred
Guido van Rossum <guido@python.org>
parents: 4047
diff changeset
181 \code{unpack_string}.
4047
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
183
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 The following methods support unpacking arrays and lists:
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
185
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 \begin{funcdesc}{unpack_list}{unpack_item}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 Unpacks and returns a list of homogeneous items. The list is unpacked
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 one element at a time
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 by first unpacking an unsigned integer flag. If the flag is \code{1},
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 then the item is unpacked and appended to the list. A flag of
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 \code{0} indicates the end of the list. \var{unpack_item} is the
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 function that is called to unpack the items.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
194
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 \begin{funcdesc}{unpack_farray}{n\, unpack_item}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 Unpacks and returns (as a list) a fixed length array of homogeneous
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 items. \var{n} is number of list elements to expect in the buffer.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 As above, \var{unpack_item} is the function used to unpack each element.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
200
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 \begin{funcdesc}{unpack_array}{unpack_item}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 Unpacks and returns a variable length \var{list} of homogeneous items.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 First, the length of the list is unpacked as an unsigned integer, then
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 each element is unpacked as in \code{unpack_farray} above.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 \end{funcdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
206
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 \subsection{Exceptions}
4728
b218f294b726 (lib<all sorts of stuff>.tex):
Fred Drake <fdrake@acm.org>
parents: 4579
diff changeset
208 \nodename{Exceptions in xdrlib module}
4047
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
209
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 Exceptions in this module are coded as class instances:
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
211
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 \begin{excdesc}{Error}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 The base exception class. \code{Error} has a single public data
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 member \code{msg} containing the description of the error.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 \end{excdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
216
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 \begin{excdesc}{ConversionError}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 Class derived from \code{Error}. Contains no additional instance
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 variables.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 \end{excdesc}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
221
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 Here is an example of how you would catch one of these exceptions:
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
223
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 \begin{verbatim}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 import xdrlib
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 p = xdrlib.Packer()
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 try:
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 p.pack_double(8.01)
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 except xdrlib.ConversionError, instance:
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 print 'packing the double failed:', instance.msg
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 \end{verbatim}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
232
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 \subsection{Supporting Floating Point Data}
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
234
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 Packing and unpacking floating point data,
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 i.e. \code{Packer.pack_float}, \code{Packer.pack_double},
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 \code{Unpacker.unpack_float}, and \code{Unpacker.unpack_double}, are
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 only supported with the helper built-in \code{_xdr} module, which
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 relies on your operating system having the appropriate XDR library
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 routines.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
241
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 If you have built the Python interpeter with the \code{_xdr} module,
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 or have built the \code{_xdr} module as a shared library,
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 \code{xdrlib} will use these to pack and unpack floating point
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 numbers. Otherwise, using these routines will raise a
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 \code{ConversionError} exception.
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
247
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 See the Python installation instructions for details on building the
3e6863cea383 Added imghdr,xdrlib; reformatted Makefile somewhat
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 \code{_xdr} module.