[Python-checkins] python/dist/src/Demo/rpc T.py, 1.4, 1.5 mountclient.py, 1.8, 1.9 nfsclient.py, 1.10, 1.11 rnusersclient.py, 1.4, 1.5 rpc.py, 1.12, 1.13 xdr.py, 1.11, 1.12

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Sun Jul 18 07:56:27 CEST 2004


Update of /cvsroot/python/python/dist/src/Demo/rpc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28702/Demo/rpc

Modified Files:
	T.py mountclient.py nfsclient.py rnusersclient.py rpc.py 
	xdr.py 
Log Message:
Whitespace normalization.  Ran reindent.py over the entire source tree.


Index: T.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Demo/rpc/T.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** T.py	12 Feb 2004 17:35:02 -0000	1.4
--- T.py	18 Jul 2004 05:56:08 -0000	1.5
***************
*** 5,22 ****
  
  def TSTART():
! 	global t0, t1
! 	u, s, cu, cs = os.times()
! 	t0 = u+cu, s+cs, time.time()
  
  def TSTOP(*label):
! 	global t0, t1
! 	u, s, cu, cs = os.times()
! 	t1 = u+cu, s+cs, time.time()
! 	tt = []
! 	for i in range(3):
! 		tt.append(t1[i] - t0[i])
! 	[u, s, r] = tt
! 	msg = ''
! 	for x in label: msg = msg + (x + ' ')
! 	msg = msg + '%r user, %r sys, %r real\n' % (u, s, r)
! 	sys.stderr.write(msg)
--- 5,22 ----
  
  def TSTART():
!     global t0, t1
!     u, s, cu, cs = os.times()
!     t0 = u+cu, s+cs, time.time()
  
  def TSTOP(*label):
!     global t0, t1
!     u, s, cu, cs = os.times()
!     t1 = u+cu, s+cs, time.time()
!     tt = []
!     for i in range(3):
!         tt.append(t1[i] - t0[i])
!     [u, s, r] = tt
!     msg = ''
!     for x in label: msg = msg + (x + ' ')
!     msg = msg + '%r user, %r sys, %r real\n' % (u, s, r)
!     sys.stderr.write(msg)

Index: mountclient.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Demo/rpc/mountclient.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** mountclient.py	11 Oct 2001 19:23:28 -0000	1.8
--- mountclient.py	18 Jul 2004 05:56:08 -0000	1.9
***************
*** 27,32 ****
  class MountPacker(Packer):
  
! 	def pack_fhandle(self, fhandle):
! 		self.pack_fopaque(FHSIZE, fhandle)
  
  
--- 27,32 ----
  class MountPacker(Packer):
  
!     def pack_fhandle(self, fhandle):
!         self.pack_fopaque(FHSIZE, fhandle)
  
  
***************
*** 40,72 ****
  class MountUnpacker(Unpacker):
  
! 	def unpack_fhandle(self):
! 		return self.unpack_fopaque(FHSIZE)
  
! 	def unpack_fhstatus(self):
! 		status = self.unpack_uint()
! 		if status == 0:
! 			fh = self.unpack_fhandle()
! 		else:
! 			fh = None
! 		return status, fh
  
! 	def unpack_mountlist(self):
! 		return self.unpack_list(self.unpack_mountstruct)
  
! 	def unpack_mountstruct(self):
! 		hostname = self.unpack_string()
! 		directory = self.unpack_string()
! 		return (hostname, directory)
  
! 	def unpack_exportlist(self):
! 		return self.unpack_list(self.unpack_exportstruct)
  
! 	def unpack_exportstruct(self):
! 		filesys = self.unpack_string()
! 		groups = self.unpack_groups()
! 		return (filesys, groups)
  
! 	def unpack_groups(self):
! 		return self.unpack_list(self.unpack_string)
  
  
--- 40,72 ----
  class MountUnpacker(Unpacker):
  
!     def unpack_fhandle(self):
!         return self.unpack_fopaque(FHSIZE)
  
!     def unpack_fhstatus(self):
!         status = self.unpack_uint()
!         if status == 0:
!             fh = self.unpack_fhandle()
!         else:
!             fh = None
!         return status, fh
  
!     def unpack_mountlist(self):
!         return self.unpack_list(self.unpack_mountstruct)
  
!     def unpack_mountstruct(self):
!         hostname = self.unpack_string()
!         directory = self.unpack_string()
!         return (hostname, directory)
  
!     def unpack_exportlist(self):
!         return self.unpack_list(self.unpack_exportstruct)
  
!     def unpack_exportstruct(self):
!         filesys = self.unpack_string()
!         groups = self.unpack_groups()
!         return (filesys, groups)
  
!     def unpack_groups(self):
!         return self.unpack_list(self.unpack_string)
  
  
***************
*** 76,157 ****
  class PartialMountClient:
  
! 	# This method is called by Client.__init__ to initialize
! 	# self.packer and self.unpacker
! 	def addpackers(self):
! 		self.packer = MountPacker()
! 		self.unpacker = MountUnpacker('')
  
! 	# This method is called by Client.__init__ to bind the socket
! 	# to a particular network interface and port.  We use the
! 	# default network interface, but if we're running as root,
! 	# we want to bind to a reserved port
! 	def bindsocket(self):
! 		import os
! 		try:
! 			uid = os.getuid()
! 		except AttributeError:
! 			uid = 1
! 		if uid == 0:
! 			port = rpc.bindresvport(self.sock, '')
! 			# 'port' is not used
! 		else:
! 			self.sock.bind(('', 0))
  
! 	# This function is called to cough up a suitable
! 	# authentication object for a call to procedure 'proc'.
! 	def mkcred(self):
! 		if self.cred == None:
! 			self.cred = rpc.AUTH_UNIX, rpc.make_auth_unix_default()
! 		return self.cred
  
! 	# The methods Mnt, Dump etc. each implement one Remote
! 	# Procedure Call.  This is done by calling self.make_call()
! 	# with as arguments:
! 	#
! 	# - the procedure number
! 	# - the arguments (or None)
! 	# - the "packer" function for the arguments (or None)
! 	# - the "unpacker" function for the return value (or None)
! 	#
! 	# The packer and unpacker function, if not None, *must* be
! 	# methods of self.packer and self.unpacker, respectively.
! 	# A value of None means that there are no arguments or is no
! 	# return value, respectively.
! 	#
! 	# The return value from make_call() is the return value from
! 	# the remote procedure call, as unpacked by the "unpacker"
! 	# function, or None if the unpacker function is None.
! 	#
! 	# (Even if you expect a result of None, you should still
! 	# return the return value from make_call(), since this may be
! 	# needed by a broadcasting version of the class.)
! 	#
! 	# If the call fails, make_call() raises an exception
! 	# (this includes time-outs and invalid results).
! 	#
! 	# Note that (at least with the UDP protocol) there is no
! 	# guarantee that a call is executed at most once.  When you do
! 	# get a reply, you know it has been executed at least once;
! 	# when you don't get a reply, you know nothing.
  
! 	def Mnt(self, directory):
! 		return self.make_call(1, directory, \
! 			self.packer.pack_string, \
! 			self.unpacker.unpack_fhstatus)
  
! 	def Dump(self):
! 		return self.make_call(2, None, \
! 			None, self.unpacker.unpack_mountlist)
  
! 	def Umnt(self, directory):
! 		return self.make_call(3, directory, \
! 			self.packer.pack_string, None)
  
! 	def Umntall(self):
! 		return self.make_call(4, None, None, None)
  
! 	def Export(self):
! 		return self.make_call(5, None, \
! 			None, self.unpacker.unpack_exportlist)
  
  
--- 76,157 ----
  class PartialMountClient:
  
!     # This method is called by Client.__init__ to initialize
!     # self.packer and self.unpacker
!     def addpackers(self):
!         self.packer = MountPacker()
!         self.unpacker = MountUnpacker('')
  
!     # This method is called by Client.__init__ to bind the socket
!     # to a particular network interface and port.  We use the
!     # default network interface, but if we're running as root,
!     # we want to bind to a reserved port
!     def bindsocket(self):
!         import os
!         try:
!             uid = os.getuid()
!         except AttributeError:
!             uid = 1
!         if uid == 0:
!             port = rpc.bindresvport(self.sock, '')
!             # 'port' is not used
!         else:
!             self.sock.bind(('', 0))
  
!     # This function is called to cough up a suitable
!     # authentication object for a call to procedure 'proc'.
!     def mkcred(self):
!         if self.cred == None:
!             self.cred = rpc.AUTH_UNIX, rpc.make_auth_unix_default()
!         return self.cred
  
!     # The methods Mnt, Dump etc. each implement one Remote
!     # Procedure Call.  This is done by calling self.make_call()
!     # with as arguments:
!     #
!     # - the procedure number
!     # - the arguments (or None)
!     # - the "packer" function for the arguments (or None)
!     # - the "unpacker" function for the return value (or None)
!     #
!     # The packer and unpacker function, if not None, *must* be
!     # methods of self.packer and self.unpacker, respectively.
!     # A value of None means that there are no arguments or is no
!     # return value, respectively.
!     #
!     # The return value from make_call() is the return value from
!     # the remote procedure call, as unpacked by the "unpacker"
!     # function, or None if the unpacker function is None.
!     #
!     # (Even if you expect a result of None, you should still
!     # return the return value from make_call(), since this may be
!     # needed by a broadcasting version of the class.)
!     #
!     # If the call fails, make_call() raises an exception
!     # (this includes time-outs and invalid results).
!     #
!     # Note that (at least with the UDP protocol) there is no
!     # guarantee that a call is executed at most once.  When you do
!     # get a reply, you know it has been executed at least once;
!     # when you don't get a reply, you know nothing.
  
!     def Mnt(self, directory):
!         return self.make_call(1, directory, \
!                 self.packer.pack_string, \
!                 self.unpacker.unpack_fhstatus)
  
!     def Dump(self):
!         return self.make_call(2, None, \
!                 None, self.unpacker.unpack_mountlist)
  
!     def Umnt(self, directory):
!         return self.make_call(3, directory, \
!                 self.packer.pack_string, None)
  
!     def Umntall(self):
!         return self.make_call(4, None, None, None)
  
!     def Export(self):
!         return self.make_call(5, None, \
!                 None, self.unpacker.unpack_exportlist)
  
  
***************
*** 163,174 ****
  class TCPMountClient(PartialMountClient, TCPClient):
  
! 	def __init__(self, host):
! 		TCPClient.__init__(self, host, MOUNTPROG, MOUNTVERS)
  
  
  class UDPMountClient(PartialMountClient, UDPClient):
  
! 	def __init__(self, host):
! 		UDPClient.__init__(self, host, MOUNTPROG, MOUNTVERS)
  
  
--- 163,174 ----
  class TCPMountClient(PartialMountClient, TCPClient):
  
!     def __init__(self, host):
!         TCPClient.__init__(self, host, MOUNTPROG, MOUNTVERS)
  
  
  class UDPMountClient(PartialMountClient, UDPClient):
  
!     def __init__(self, host):
!         UDPClient.__init__(self, host, MOUNTPROG, MOUNTVERS)
  
  
***************
*** 180,202 ****
  
  def test():
! 	import sys
! 	if sys.argv[1:] and sys.argv[1] == '-t':
! 		C = TCPMountClient
! 		del sys.argv[1]
! 	elif sys.argv[1:] and sys.argv[1] == '-u':
! 		C = UDPMountClient
! 		del sys.argv[1]
! 	else:
! 		C = UDPMountClient
! 	if sys.argv[1:]: host = sys.argv[1]
! 	else: host = ''
! 	mcl = C(host)
! 	list = mcl.Export()
! 	for item in list:
! 		print item
! 		try:
! 			mcl.Mnt(item[0])
! 		except:
! 			print 'Sorry'
! 			continue
! 		mcl.Umnt(item[0])
--- 180,202 ----
  
  def test():
!     import sys
!     if sys.argv[1:] and sys.argv[1] == '-t':
!         C = TCPMountClient
!         del sys.argv[1]
!     elif sys.argv[1:] and sys.argv[1] == '-u':
!         C = UDPMountClient
!         del sys.argv[1]
!     else:
!         C = UDPMountClient
!     if sys.argv[1:]: host = sys.argv[1]
!     else: host = ''
!     mcl = C(host)
!     list = mcl.Export()
!     for item in list:
!         print item
!         try:
!             mcl.Mnt(item[0])
!         except:
!             print 'Sorry'
!             continue
!         mcl.Umnt(item[0])

Index: nfsclient.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Demo/rpc/nfsclient.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** nfsclient.py	8 Oct 1998 15:23:50 -0000	1.10
--- nfsclient.py	18 Jul 2004 05:56:08 -0000	1.11
***************
*** 29,201 ****
  class NFSPacker(MountPacker):
  
! 	def pack_sattrargs(self, sa):
! 		file, attributes = sa
! 		self.pack_fhandle(file)
! 		self.pack_sattr(attributes)
  
! 	def pack_sattr(self, sa):
! 		mode, uid, gid, size, atime, mtime = sa
! 		self.pack_uint(mode)
! 		self.pack_uint(uid)
! 		self.pack_uint(gid)
! 		self.pack_uint(size)
! 		self.pack_timeval(atime)
! 		self.pack_timeval(mtime)
  
! 	def pack_diropargs(self, da):
! 		dir, name = da
! 		self.pack_fhandle(dir)
! 		self.pack_string(name)
  
! 	def pack_readdirargs(self, ra):
! 		dir, cookie, count = ra
! 		self.pack_fhandle(dir)
! 		self.pack_uint(cookie)
! 		self.pack_uint(count)
  
! 	def pack_timeval(self, tv):
! 		secs, usecs = tv
! 		self.pack_uint(secs)
! 		self.pack_uint(usecs)
  
  
  class NFSUnpacker(MountUnpacker):
  
! 	def unpack_readdirres(self):
! 		status = self.unpack_enum()
! 		if status == NFS_OK:
! 			entries = self.unpack_list(self.unpack_entry)
! 			eof = self.unpack_bool()
! 			rest = (entries, eof)
! 		else:
! 			rest = None
! 		return (status, rest)
  
! 	def unpack_entry(self):
! 		fileid = self.unpack_uint()
! 		name = self.unpack_string()
! 		cookie = self.unpack_uint()
! 		return (fileid, name, cookie)
  
! 	def unpack_diropres(self):
! 		status = self.unpack_enum()
! 		if status == NFS_OK:
! 			fh = self.unpack_fhandle()
! 			fa = self.unpack_fattr()
! 			rest = (fh, fa)
! 		else:
! 			rest = None
! 		return (status, rest)
  
! 	def unpack_attrstat(self):
! 		status = self.unpack_enum()
! 		if status == NFS_OK:
! 			attributes = self.unpack_fattr()
! 		else:
! 			attributes = None
! 		return status, attributes
  
! 	def unpack_fattr(self):
! 		type = self.unpack_enum()
! 		mode = self.unpack_uint()
! 		nlink = self.unpack_uint()
! 		uid = self.unpack_uint()
! 		gid = self.unpack_uint()
! 		size = self.unpack_uint()
! 		blocksize = self.unpack_uint()
! 		rdev = self.unpack_uint()
! 		blocks = self.unpack_uint()
! 		fsid = self.unpack_uint()
! 		fileid = self.unpack_uint()
! 		atime = self.unpack_timeval()
! 		mtime = self.unpack_timeval()
! 		ctime = self.unpack_timeval()
! 		return (type, mode, nlink, uid, gid, size, blocksize, \
! 			rdev, blocks, fsid, fileid, atime, mtime, ctime)
  
! 	def unpack_timeval(self):
! 		secs = self.unpack_uint()
! 		usecs = self.unpack_uint()
! 		return (secs, usecs)
  
  
  class NFSClient(UDPClient):
  
! 	def __init__(self, host):
! 		UDPClient.__init__(self, host, NFS_PROGRAM, NFS_VERSION)
  
! 	def addpackers(self):
! 		self.packer = NFSPacker()
! 		self.unpacker = NFSUnpacker('')
  
! 	def mkcred(self):
! 		if self.cred == None:
! 			self.cred = rpc.AUTH_UNIX, rpc.make_auth_unix_default()
! 		return self.cred
  
! 	def Getattr(self, fh):
! 		return self.make_call(1, fh, \
! 			self.packer.pack_fhandle, \
! 			self.unpacker.unpack_attrstat)
  
! 	def Setattr(self, sa):
! 		return self.make_call(2, sa, \
! 			self.packer.pack_sattrargs, \
! 			self.unpacker.unpack_attrstat)
  
! 	# Root() is obsolete
  
! 	def Lookup(self, da):
! 		return self.make_call(4, da, \
! 			self.packer.pack_diropargs, \
! 			self.unpacker.unpack_diropres)
  
! 	# ...
  
! 	def Readdir(self, ra):
! 		return self.make_call(16, ra, \
! 			self.packer.pack_readdirargs, \
! 			self.unpacker.unpack_readdirres)
  
- 	# Shorthand to get the entire contents of a directory
- 	def Listdir(self, dir):
- 		list = []
- 		ra = (dir, 0, 2000)
- 		while 1:
- 			(status, rest) = self.Readdir(ra)
- 			if status <> NFS_OK:
- 				break
- 			entries, eof = rest
- 			last_cookie = None
- 			for fileid, name, cookie in entries:
- 				list.append((fileid, name))
- 				last_cookie = cookie
- 			if eof or last_cookie == None:
- 				break
- 			ra = (ra[0], last_cookie, ra[2])
- 		return list
  
- 	
  def test():
! 	import sys
! 	if sys.argv[1:]: host = sys.argv[1]
! 	else: host = ''
! 	if sys.argv[2:]: filesys = sys.argv[2]
! 	else: filesys = None
! 	from mountclient import UDPMountClient, TCPMountClient
! 	mcl = TCPMountClient(host)
! 	if filesys == None:
! 		list = mcl.Export()
! 		for item in list:
! 			print item
! 		return
! 	sf = mcl.Mnt(filesys)
! 	print sf
! 	fh = sf[1]
! 	if fh:
! 		ncl = NFSClient(host)
! 		as = ncl.Getattr(fh)
! 		print as
! 		list = ncl.Listdir(fh)
! 		for item in list: print item
! 		mcl.Umnt(filesys)
--- 29,201 ----
  class NFSPacker(MountPacker):
  
!     def pack_sattrargs(self, sa):
!         file, attributes = sa
!         self.pack_fhandle(file)
!         self.pack_sattr(attributes)
  
!     def pack_sattr(self, sa):
!         mode, uid, gid, size, atime, mtime = sa
!         self.pack_uint(mode)
!         self.pack_uint(uid)
!         self.pack_uint(gid)
!         self.pack_uint(size)
!         self.pack_timeval(atime)
!         self.pack_timeval(mtime)
  
!     def pack_diropargs(self, da):
!         dir, name = da
!         self.pack_fhandle(dir)
!         self.pack_string(name)
  
!     def pack_readdirargs(self, ra):
!         dir, cookie, count = ra
!         self.pack_fhandle(dir)
!         self.pack_uint(cookie)
!         self.pack_uint(count)
  
!     def pack_timeval(self, tv):
!         secs, usecs = tv
!         self.pack_uint(secs)
!         self.pack_uint(usecs)
  
  
  class NFSUnpacker(MountUnpacker):
  
!     def unpack_readdirres(self):
!         status = self.unpack_enum()
!         if status == NFS_OK:
!             entries = self.unpack_list(self.unpack_entry)
!             eof = self.unpack_bool()
!             rest = (entries, eof)
!         else:
!             rest = None
!         return (status, rest)
  
!     def unpack_entry(self):
!         fileid = self.unpack_uint()
!         name = self.unpack_string()
!         cookie = self.unpack_uint()
!         return (fileid, name, cookie)
  
!     def unpack_diropres(self):
!         status = self.unpack_enum()
!         if status == NFS_OK:
!             fh = self.unpack_fhandle()
!             fa = self.unpack_fattr()
!             rest = (fh, fa)
!         else:
!             rest = None
!         return (status, rest)
  
!     def unpack_attrstat(self):
!         status = self.unpack_enum()
!         if status == NFS_OK:
!             attributes = self.unpack_fattr()
!         else:
!             attributes = None
!         return status, attributes
  
!     def unpack_fattr(self):
!         type = self.unpack_enum()
!         mode = self.unpack_uint()
!         nlink = self.unpack_uint()
!         uid = self.unpack_uint()
!         gid = self.unpack_uint()
!         size = self.unpack_uint()
!         blocksize = self.unpack_uint()
!         rdev = self.unpack_uint()
!         blocks = self.unpack_uint()
!         fsid = self.unpack_uint()
!         fileid = self.unpack_uint()
!         atime = self.unpack_timeval()
!         mtime = self.unpack_timeval()
!         ctime = self.unpack_timeval()
!         return (type, mode, nlink, uid, gid, size, blocksize, \
!                 rdev, blocks, fsid, fileid, atime, mtime, ctime)
  
!     def unpack_timeval(self):
!         secs = self.unpack_uint()
!         usecs = self.unpack_uint()
!         return (secs, usecs)
  
  
  class NFSClient(UDPClient):
  
!     def __init__(self, host):
!         UDPClient.__init__(self, host, NFS_PROGRAM, NFS_VERSION)
  
!     def addpackers(self):
!         self.packer = NFSPacker()
!         self.unpacker = NFSUnpacker('')
  
!     def mkcred(self):
!         if self.cred == None:
!             self.cred = rpc.AUTH_UNIX, rpc.make_auth_unix_default()
!         return self.cred
  
!     def Getattr(self, fh):
!         return self.make_call(1, fh, \
!                 self.packer.pack_fhandle, \
!                 self.unpacker.unpack_attrstat)
  
!     def Setattr(self, sa):
!         return self.make_call(2, sa, \
!                 self.packer.pack_sattrargs, \
!                 self.unpacker.unpack_attrstat)
  
!     # Root() is obsolete
  
!     def Lookup(self, da):
!         return self.make_call(4, da, \
!                 self.packer.pack_diropargs, \
!                 self.unpacker.unpack_diropres)
  
!     # ...
  
!     def Readdir(self, ra):
!         return self.make_call(16, ra, \
!                 self.packer.pack_readdirargs, \
!                 self.unpacker.unpack_readdirres)
! 
!     # Shorthand to get the entire contents of a directory
!     def Listdir(self, dir):
!         list = []
!         ra = (dir, 0, 2000)
!         while 1:
!             (status, rest) = self.Readdir(ra)
!             if status <> NFS_OK:
!                 break
!             entries, eof = rest
!             last_cookie = None
!             for fileid, name, cookie in entries:
!                 list.append((fileid, name))
!                 last_cookie = cookie
!             if eof or last_cookie == None:
!                 break
!             ra = (ra[0], last_cookie, ra[2])
!         return list
  
  
  def test():
!     import sys
!     if sys.argv[1:]: host = sys.argv[1]
!     else: host = ''
!     if sys.argv[2:]: filesys = sys.argv[2]
!     else: filesys = None
!     from mountclient import UDPMountClient, TCPMountClient
!     mcl = TCPMountClient(host)
!     if filesys == None:
!         list = mcl.Export()
!         for item in list:
!             print item
!         return
!     sf = mcl.Mnt(filesys)
!     print sf
!     fh = sf[1]
!     if fh:
!         ncl = NFSClient(host)
!         as = ncl.Getattr(fh)
!         print as
!         list = ncl.Listdir(fh)
!         for item in list: print item
!         mcl.Umnt(filesys)

Index: rnusersclient.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Demo/rpc/rnusersclient.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** rnusersclient.py	12 Feb 2004 17:35:02 -0000	1.4
--- rnusersclient.py	18 Jul 2004 05:56:08 -0000	1.5
***************
*** 6,98 ****
  
  class RnusersPacker(Packer):
! 	def pack_utmp(self, ui):
! 		ut_line, ut_name, ut_host, ut_time = utmp
! 		self.pack_string(ut_line)
! 		self.pack_string(ut_name)
! 		self.pack_string(ut_host)
! 		self.pack_int(ut_time)
! 	def pack_utmpidle(self, ui):
! 		ui_itmp, ui_idle = ui
! 		self.pack_utmp(ui_utmp)
! 		self.pack_uint(ui_idle)
! 	def pack_utmpidlearr(self, list):
! 		self.pack_array(list, self.pack_itmpidle)
  
  
  class RnusersUnpacker(Unpacker):
! 	def unpack_utmp(self):
! 		ut_line = self.unpack_string()
! 		ut_name = self.unpack_string()
! 		ut_host = self.unpack_string()
! 		ut_time = self.unpack_int()
! 		return ut_line, ut_name, ut_host, ut_time
! 	def unpack_utmpidle(self):
! 		ui_utmp = self.unpack_utmp()
! 		ui_idle = self.unpack_uint()
! 		return ui_utmp, ui_idle
! 	def unpack_utmpidlearr(self):
! 		return self.unpack_array(self.unpack_utmpidle)
  
  
  class PartialRnusersClient:
  
! 	def addpackers(self):
! 		self.packer = RnusersPacker()
! 		self.unpacker = RnusersUnpacker('')
  
! 	def Num(self):
! 		return self.make_call(1, None, None, self.unpacker.unpack_int)
  
! 	def Names(self):
! 		return self.make_call(2, None, \
! 			None, self.unpacker.unpack_utmpidlearr)
  
! 	def Allnames(self):
! 		return self.make_call(3, None, \
! 			None, self.unpacker.unpack_utmpidlearr)
  
  
  class RnusersClient(PartialRnusersClient, UDPClient):
  
! 	def __init__(self, host):
! 		UDPClient.__init__(self, host, 100002, 2)
  
  
  class BroadcastRnusersClient(PartialRnusersClient, BroadcastUDPClient):
  
! 	def __init__(self, bcastaddr):
! 		BroadcastUDPClient.__init__(self, bcastaddr, 100002, 2)
  
  
  def test():
! 	import sys
! 	if not sys.argv[1:]:
! 		testbcast()
! 		return
! 	else:
! 		host = sys.argv[1]
! 	c = RnusersClient(host)
! 	list = c.Names()
! 	for (line, name, host, time), idle in list:
! 		line = strip0(line)
! 		name = strip0(name)
! 		host = strip0(host)
! 		print "%r %r %r %s %s" % (name, host, line, time, idle)
  
  def testbcast():
! 	c = BroadcastRnusersClient('<broadcast>')
! 	def listit(list, fromaddr):
! 		host, port = fromaddr
! 		print host + '\t:',
! 		for (line, name, host, time), idle in list:
! 			print strip0(name),
! 		print
! 	c.set_reply_handler(listit)
! 	all = c.Names()
! 	print 'Total Count:', len(all)
  
  def strip0(s):
! 	while s and s[-1] == '\0': s = s[:-1]
! 	return s
  
  test()
--- 6,98 ----
  
  class RnusersPacker(Packer):
!     def pack_utmp(self, ui):
!         ut_line, ut_name, ut_host, ut_time = utmp
!         self.pack_string(ut_line)
!         self.pack_string(ut_name)
!         self.pack_string(ut_host)
!         self.pack_int(ut_time)
!     def pack_utmpidle(self, ui):
!         ui_itmp, ui_idle = ui
!         self.pack_utmp(ui_utmp)
!         self.pack_uint(ui_idle)
!     def pack_utmpidlearr(self, list):
!         self.pack_array(list, self.pack_itmpidle)
  
  
  class RnusersUnpacker(Unpacker):
!     def unpack_utmp(self):
!         ut_line = self.unpack_string()
!         ut_name = self.unpack_string()
!         ut_host = self.unpack_string()
!         ut_time = self.unpack_int()
!         return ut_line, ut_name, ut_host, ut_time
!     def unpack_utmpidle(self):
!         ui_utmp = self.unpack_utmp()
!         ui_idle = self.unpack_uint()
!         return ui_utmp, ui_idle
!     def unpack_utmpidlearr(self):
!         return self.unpack_array(self.unpack_utmpidle)
  
  
  class PartialRnusersClient:
  
!     def addpackers(self):
!         self.packer = RnusersPacker()
!         self.unpacker = RnusersUnpacker('')
  
!     def Num(self):
!         return self.make_call(1, None, None, self.unpacker.unpack_int)
  
!     def Names(self):
!         return self.make_call(2, None, \
!                 None, self.unpacker.unpack_utmpidlearr)
  
!     def Allnames(self):
!         return self.make_call(3, None, \
!                 None, self.unpacker.unpack_utmpidlearr)
  
  
  class RnusersClient(PartialRnusersClient, UDPClient):
  
!     def __init__(self, host):
!         UDPClient.__init__(self, host, 100002, 2)
  
  
  class BroadcastRnusersClient(PartialRnusersClient, BroadcastUDPClient):
  
!     def __init__(self, bcastaddr):
!         BroadcastUDPClient.__init__(self, bcastaddr, 100002, 2)
  
  
  def test():
!     import sys
!     if not sys.argv[1:]:
!         testbcast()
!         return
!     else:
!         host = sys.argv[1]
!     c = RnusersClient(host)
!     list = c.Names()
!     for (line, name, host, time), idle in list:
!         line = strip0(line)
!         name = strip0(name)
!         host = strip0(host)
!         print "%r %r %r %s %s" % (name, host, line, time, idle)
  
  def testbcast():
!     c = BroadcastRnusersClient('<broadcast>')
!     def listit(list, fromaddr):
!         host, port = fromaddr
!         print host + '\t:',
!         for (line, name, host, time), idle in list:
!             print strip0(name),
!         print
!     c.set_reply_handler(listit)
!     all = c.Names()
!     print 'Total Count:', len(all)
  
  def strip0(s):
!     while s and s[-1] == '\0': s = s[:-1]
!     return s
  
  test()





More information about the Python-checkins mailing list