home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
p
/
python
/
pyhtmldoc
/
u
/
unpacker_o
next >
Wrap
Text File
|
1996-11-14
|
4KB
|
86 lines
<TITLE>Unpacker Objects -- Python library reference</TITLE>
Next: <A HREF="../e/exceptions" TYPE="Next">Exceptions</A>
Prev: <A HREF="../p/packer_objects" TYPE="Prev">Packer Objects</A>
Up: <A HREF="../x/xdrlib" TYPE="Up">xdrlib</A>
Top: <A HREF="../t/top" TYPE="Top">Top</A>
<H2>10.16.2. Unpacker Objects</H2>
<CODE>Unpacker</CODE> is the complementary class which unpacks XDR data
values from a string buffer, and has the following methods:
<P>
<DL><DT><B>__init__</B> (<VAR>data</VAR>) -- function of module xdrlib<DD>
Instantiates an <CODE>Unpacker</CODE> object with the string buffer
<VAR>data</VAR>.
</DL>
<DL><DT><B>reset</B> (<VAR>data</VAR>) -- function of module xdrlib<DD>
Resets the string buffer with the given <VAR>data</VAR>.
</DL>
<DL><DT><B>get_position</B> () -- function of module xdrlib<DD>
Returns the current unpack position in the data buffer.
</DL>
<DL><DT><B>set_position</B> (<VAR>position</VAR>) -- function of module xdrlib<DD>
Sets the data buffer unpack position to <VAR>position</VAR>. You should be
careful about using <CODE>get_position()</CODE> and <CODE>set_position()</CODE>.
</DL>
<DL><DT><B>done</B> () -- function of module xdrlib<DD>
Indicates unpack completion. Raises an <CODE>xdrlib.Error</CODE> exception
if all of the data has not been unpacked.
</DL>
In addition, every data type that can be packed with a <CODE>Packer</CODE>,
can be unpacked with an <CODE>Unpacker</CODE>. Unpacking methods are of the
form <CODE>unpack_<VAR>type</VAR></CODE>, and take no arguments. They return the
unpacked object. The same caveats apply for <CODE>unpack_float</CODE> and
<CODE>unpack_double</CODE> as above.
<P>
<DL><DT><B>unpack_float</B> () -- function of module xdrlib<DD>
Unpacks a single-precision floating point number.
</DL>
<DL><DT><B>unpack_double</B> () -- function of module xdrlib<DD>
Unpacks a double-precision floating point number, similarly to
<CODE>unpack_float</CODE>.
</DL>
In addition, the following methods unpack strings, bytes, and opaque
data:
<P>
<DL><DT><B>unpack_fstring</B> (<VAR>n</VAR>) -- function of module xdrlib<DD>
Unpacks and returns a fixed length string. <VAR>n</VAR> is the number of
characters expected. Padding with null bytes to guaranteed 4 byte
alignment is assumed.
</DL>
<DL><DT><B>unpack_fopaque</B> (<VAR>n</VAR>) -- function of module xdrlib<DD>
Unpacks and returns a fixed length opaque data stream, similarly to
<CODE>unpack_fstring</CODE>.
</DL>
<DL><DT><B>unpack_string</B> () -- function of module xdrlib<DD>
Unpacks and returns a variable length string. The length of the
string is first unpacked as an unsigned integer, then the string data
is unpacked with <CODE>unpack_fstring</CODE>.
</DL>
<DL><DT><B>unpack_opaque</B> () -- function of module xdrlib<DD>
Unpacks and returns a variable length opaque data string, similarly to
<CODE>unpack_string</CODE>.
</DL>
<DL><DT><B>unpack_bytes</B> () -- function of module xdrlib<DD>
Unpacks and returns a variable length byte stream, similarly to
<CODE>unpack_string</CODE>.
</DL>
The following methods support unpacking arrays and lists:
<P>
<DL><DT><B>unpack_list</B> (<VAR>unpack_item</VAR>) -- function of module xdrlib<DD>
Unpacks and returns a list of homogeneous items. The list is unpacked
one element at a time
by first unpacking an unsigned integer flag. If the flag is <CODE>1</CODE>,
then the item is unpacked and appended to the list. A flag of
<CODE>0</CODE> indicates the end of the list. <VAR>unpack_item</VAR> is the
function that is called to unpack the items.
</DL>
<DL><DT><B>unpack_farray</B> (<VAR>n</VAR>, <VAR>unpack_item</VAR>) -- function of module xdrlib<DD>
Unpacks and returns (as a list) a fixed length array of homogeneous
items. <VAR>n</VAR> is number of list elements to expect in the buffer.
As above, <VAR>unpack_item</VAR> is the function used to unpack each element.
</DL>
<DL><DT><B>unpack_array</B> (<VAR>unpack_item</VAR>) -- function of module xdrlib<DD>
Unpacks and returns a variable length <VAR>list</VAR> of homogeneous items.
First, the length of the list is unpacked as an unsigned integer, then
each element is unpacked as in <CODE>unpack_farray</CODE> above.
</DL>