From: aa8vb at vislab.epa.gov (Randall Hopper)
Date: Tue, 13 Apr 1999 11:11:31 GMT
Subject: RPC and XDR with python
In-Reply-To: <37119B99.B3E2633C@hons.cs.usyd.edu.au>; from Matthew Robert Gallagher on Mon, Apr 12, 1999 at 05:07:06PM +1000
References: <37119B99.B3E2633C@hons.cs.usyd.edu.au>
Message-ID: <19990413071131.A1293592@vislab.epa.gov>
Content-Length: 1225
X-UID: 111                                                  

 |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 ] )


