RPC and XDR with python

Randall Hopper aa8vb at vislab.epa.gov
Tue Apr 13 07:11:31 EDT 1999


 |Does anybody know where these resource are located.
 |python.org has a couple of ref but nothing concrete
 |
 |It would be better find an example thou

Well, haven't looked for RPC, but XDR is there.  Here's a code snip from
something I wrote recently, brutally cut and simplified to highlight how
xdrlib can be used:







-------------- next part --------------
import os                                # popen
import struct                            # unpack
import xdrlib                            # Unpacker
import string                            # join

#
# Basic example
#
fp       = os.popen( "SomeXDRGeneratingTool" )
buffer   = fp.read()
fp.close()
unpacker = xdrlib.Unpacker( buffer )

a_double = unpacker.unpack_double()
an_int   = unpacker.unpack_int()
a_float  = unpacker.unpack_float()

#
# Utility rtn to read an undelimited array
#
def UnpackString( unpacker, str_len ):
  """ Unpack an undelimited XDR string with the characters stored as ints
  """
  
  str = string.join(
           unpacker.unpack_farray( str_len,
             lambda unp=unpacker: chr( unp.unpack_uint() ) ),
           '' )
  end = string.find( str, "\0" )
  if end < 0: end = len( str )
  return string.rstrip( str[ 0:end ] )


More information about the Python-list mailing list