Changed to use new make_call method

This commit is contained in:
Guido van Rossum 1992-12-21 14:32:28 +00:00
parent 8f1506b126
commit 73065385e8
1 changed files with 43 additions and 38 deletions

View File

@ -86,7 +86,11 @@ class PartialMountClient:
# we want to bind to a reserved port # we want to bind to a reserved port
def bindsocket(self): def bindsocket(self):
import os import os
if os.getuid() == 0: try:
uid = os.getuid()
except AttributeError:
uid = 1
if uid == 0:
port = rpc.bindresvport(self.sock, '') port = rpc.bindresvport(self.sock, '')
# 'port' is not used # 'port' is not used
else: else:
@ -100,53 +104,54 @@ class PartialMountClient:
return self.cred return self.cred
# The methods Mnt, Dump etc. each implement one Remote # The methods Mnt, Dump etc. each implement one Remote
# Procedure Call. Their general structure is # Procedure Call. This is done by calling self.make_call()
# self.start_call(<procedure-number>) # with as arguments:
# <pack arguments using self.packer> #
# self.do_call() # This does the actual message exchange # - the procedure number
# <unpack reply using self.unpacker> # - the arguments (or None)
# self.end_call() # - the "packer" function for the arguments (or None)
# return <reply> # - the "unpacker" function for the return value (or None)
# If the call fails, an exception is raised by do_call(). #
# If the reply does not match what you unpack, an exception is # The packer and unpacker function, if not None, *must* be
# raised either during unpacking (if you overrun the buffer) # methods of self.packer and self.unpacker, respectively.
# or by end_call() (if you leave values in the buffer). # A value of None means that there are no arguments or is no
# Calling packer methods with invalid arguments (e.g. if # return value, respectively.
# invalid arguments were passed from outside) will also result #
# in exceptions during packing. # 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): def Mnt(self, directory):
self.start_call(1) return self.make_call(1, directory, \
self.packer.pack_string(directory) self.packer.pack_string, \
self.do_call() self.unpacker.unpack_fhstatus)
stat = self.unpacker.unpack_fhstatus()
self.end_call()
return stat
def Dump(self): def Dump(self):
self.start_call(2) return self.make_call(2, None, \
self.do_call() None, self.unpacker.unpack_mountlist)
list = self.unpacker.unpack_mountlist()
self.end_call()
return list
def Umnt(self, directory): def Umnt(self, directory):
self.start_call(3) return self.make_call(3, directory, \
self.packer.pack_string(directory) self.packer.pack_string, None)
self.do_call()
self.end_call()
def Umntall(self): def Umntall(self):
self.start_call(4) return self.make_call(4, None, None, None)
self.do_call()
self.end_call()
def Export(self): def Export(self):
self.start_call(5) return self.make_call(5, None, \
self.do_call() None, self.unpacker.unpack_exportlist)
list = self.unpacker.unpack_exportlist()
self.end_call()
return list
# We turn the partial Mount client into a full one for either protocol # We turn the partial Mount client into a full one for either protocol