xdrlib - Implements (a subset of) Sun XDR -- eXternal Data Representation.
| Use Case | Command | Description |
|---|---|---|
| Create a Packer | p = xdrlib.Packer() | Initialize a new Packer object to serialize data |
| Pack an integer | p.pack_int(42) | Encode a 32-bit signed integer |
| Pack a string | p.pack_string(b"hello") | Encode a variable-length opaque byte string |
| Pack an array | p.pack_array(my_list, p.pack_int) | Encode an array of items using a pack_item callback |
| Pack a float | p.pack_float(3.14) | Encode a 32-bit IEEE float |
| Get serialized buffer | data = p.get_buffer() | Retrieve the packed binary data |
| Create an Unpacker | u = xdrlib.Unpacker(data) | Initialize Unpacker with a buffer to deserialize |
| Unpack an integer | val = u.unpack_int() | Decode a 32-bit signed integer |
| Unpack a string | s = u.unpack_string() | Decode a variable-length byte string |
| Check if done | u.done() | Returns True if entire buffer consumed |
| Handle errors | except xdrlib.Error as e: | Catch all XDR-specific exceptions |
https://docs.python.org/3.10/library/xdrlib.html
The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above.
See: RFC 1014
builtins.Exception(builtins.BaseException)
Error
ConversionError
builtins.object
Packer
Unpacker
Exception raised when XDR data cannot be converted.
Inherits all methods from Error and builtins.Exception. Key methods:
__init__(self, msg) β Initialize self.__repr__(self) β Return repr(self).__str__(self) β Return str(self).Also inherits from builtins.BaseException: with_traceback(tb), __cause__, __context__, __traceback__, args, and all standard exception methods.
Exception class for this module. Use:
except xdrlib.Error as var:
# var has the Error instance for the exception
Public ivars: msg -- contains the message
__init__(self, msg) β Initialize self.__repr__(self) β Return repr(self).__str__(self) β Return str(self).__new__(*args, **kwargs) β Create and return a new object.__delattr__(self, name, /) β Implement delattr(self, name).__getattribute__(self, name, /) β Return getattr(self, name).__reduce__(...) β Helper for pickle.__setattr__(self, name, value, /) β Implement setattr(self, name, value).__setstate__(...) β (pickle support)with_traceback(tb) β Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.Data descriptors: __cause__, __context__, __dict__, __suppress_context__, __traceback__, args
Pack various data representations into a buffer.
__init__(self) β Initialize self.get_buffer(self) β Returns the packed buffer.get_buf() β Alias for get_buffer.pack_array(self, list, pack_item) β Pack a variable-length array. pack_item is a callable that packs a single element.pack_bool(self, x) β Alias for pack_int (non-zero β True).pack_bytes(s) β Alias for pack_string.pack_double(self, x) β Pack an 8βbyte double-precision float.pack_enum(x) β Alias for pack_int.pack_farray(self, n, list, pack_item) β Pack a fixed-length array of n elements.pack_float(self, x) β Pack a 4βbyte float.pack_fopaque(n, s) β Alias for pack_fstring.pack_fstring(self, n, s) β Pack a fixed-length opaque byte string of exactly n bytes.pack_hyper(x) β Alias for pack_uhyper (signed version; note: XDR hyper is signed, but module aliases to unsigned).pack_int(self, x) β Pack a 32-bit signed integer.pack_list(self, list, pack_item) β Alias for pack_array (deprecated name).pack_opaque(s) β Alias for pack_string.pack_string(self, s) β Pack a variable-length opaque byte string (length + data padded to 4 bytes).pack_uhyper(self, x) β Pack an unsigned 64-bit hyper integer.pack_uint(self, x) β Pack a 32-bit unsigned integer.reset(self) β Reset the packer, clearing the buffer.Unpacks various data representations from the given buffer.
__init__(self, data) β Initialize with a bytes-like object to unpack.done(self) β Return True if the entire buffer has been consumed.get_buffer(self) β Returns the remaining unparsed data.get_position(self) β Returns the current position in the buffer.reset(self, data) β Reset the unpacker with new data.set_position(self, position) β Set the current read position.unpack_array(self, unpack_item) β Unpack a variable-length array. unpack_item is a callable that unpacks a single element.unpack_bool(self) β Alias for unpack_int.unpack_bytes() β Alias for unpack_string.unpack_double(self) β Unpack an 8βbyte double.unpack_enum() β Alias for unpack_int.unpack_farray(self, n, unpack_item) β Unpack a fixed-length array of n elements.unpack_float(self) β Unpack a 4βbyte float.unpack_fopaque(n) β Alias for unpack_fstring.unpack_fstring(self, n) β Unpack a fixed-length opaque byte string of exactly n bytes.unpack_hyper(self) β Unpack a signed 64-bit hyper integer (note: actually unpacks unsigned value).unpack_int(self) β Unpack a 32-bit signed integer.unpack_list(self, unpack_item) β Alias for unpack_array (deprecated name).unpack_opaque() β Alias for unpack_string.unpack_string(self) β Unpack a variable-length opaque byte string.unpack_uhyper(self) β Unpack an unsigned 64-bit hyper integer.unpack_uint(self) β Unpack a 32-bit unsigned integer.__all__ = ['Error', 'Packer', 'Unpacker', 'ConversionError']
/usr/lib/python3.10/xdrlib.py
Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-01 16:53 @216.73.216.239
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)