gsoc_import_engine / Doc / library / xdrlib.rst

The branch 'legacy-trunk' does not exist.

:mod:`xdrlib` --- Encode and decode XDR data

The :mod:`xdrlib` module supports the External Data Representation Standard as described in RFC 1014, written by Sun Microsystems, Inc. June 1987. It supports most of the data types described in the RFC.

The :mod:`xdrlib` module defines two classes, one for packing variables into XDR representation, and another for unpacking from XDR representation. There are also two exception classes.

:class:`Packer` is the class for packing data into XDR representation. The :class:`Packer` class is instantiated with no arguments.

Unpacker is the complementary class which unpacks XDR data values from a string buffer. The input buffer is given as data.

Packer Objects

:class:`Packer` instances have the following methods:

In general, you can pack any of the most common XDR data types by calling the appropriate pack_type() method. Each method takes a single argument, the value to pack. The following simple data type packing methods are supported: :meth:`pack_uint`, :meth:`pack_int`, :meth:`pack_enum`, :meth:`pack_bool`, :meth:`pack_uhyper`, and :meth:`pack_hyper`.

The following methods support packing strings, bytes, and opaque data:

The following methods support packing arrays and lists:

Unpacker Objects

The :class:`Unpacker` class offers the following methods:

In addition, every data type that can be packed with a :class:`Packer`, can be unpacked with an :class:`Unpacker`. Unpacking methods are of the form unpack_type(), and take no arguments. They return the unpacked object.

In addition, the following methods unpack strings, bytes, and opaque data:

The following methods support unpacking arrays and lists:


Exceptions in this module are coded as class instances:

Here is an example of how you would catch one of these exceptions:

import xdrlib
p = xdrlib.Packer()
except xdrlib.ConversionError, instance:
    print 'packing the double failed:', instance.msg