Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c4698fb

Browse files
committed
Improved exception handing. Added some XXX comments.
1 parent 4ac605e commit c4698fb

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

Demo/rpc/rpc.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Implement (a subset of) Sun RPC, version 2 -- RFC1057.
22

3+
# XXX There should be separate exceptions for the various reasons why
4+
# XXX an RPC can fail, rather than using RuntimeError for everything
5+
6+
# XXX The UDP version of the protocol resends requests when it does
7+
# XXX not receive a timely reply -- use only for idempotent calls!
8+
39
import xdr
410
import socket
511
import os
@@ -80,24 +86,32 @@ def unpack_replyheader(self):
8086
xid = self.unpack_uint()
8187
mtype = self.unpack_enum()
8288
if mtype <> REPLY:
83-
raise RuntimeError, 'no REPLY but ' + str(mtype)
89+
raise RuntimeError, 'no REPLY but ' + `mtype`
8490
stat = self.unpack_enum()
91+
if stat == MSG_DENIED:
92+
stat = self.unpack_enum()
93+
if stat == RPC_MISMATCH:
94+
low = self.unpack_uint()
95+
high = self.unpack_uint()
96+
raise RuntimeError, \
97+
'MSG_DENIED: RPC_MISMATCH: ' + `low, high`
98+
if stat == AUTH_ERROR:
99+
stat = self.unpack_uint()
100+
raise RuntimeError, \
101+
'MSG_DENIED: AUTH_ERROR: ' + `stat`
102+
raise RuntimeError, 'MSG_DENIED: ' + `stat`
85103
if stat <> MSG_ACCEPTED:
86-
if stat == MSG_DENIED:
87-
stat = self.unpack_enum()
88-
if stat == RPC_MISMATCH:
89-
low = self.unpack_uint()
90-
high = self.unpack_uint()
91-
raise 'RPC_MISMATCH', (low, high)
92-
if stat == AUTH_ERROR:
93-
stat = self.unpack_uint()
94-
raise 'AUTH_ERROR', str(stat)
95-
raise 'MSG_REJECTED', str(stat)
96-
raise RuntimeError, 'no MSG_ACCEPTED but ' + str(stat)
104+
raise RuntimeError, \
105+
'Neither MSG_DENIED nor MSG_ACCEPTED: ' + `stat`
97106
verf = self.unpack_auth()
98107
stat = self.unpack_enum()
108+
if stat == PROG_MISMATCH:
109+
low = self.unpack_uint()
110+
high = self.unpack_uint()
111+
raise RuntimeError, \
112+
'call failed: PROG_MISMATCH: ' + `low, high`
99113
if stat <> SUCCESS:
100-
raise RuntimeError, 'no SUCCESS but ' + str(stat)
114+
raise RuntimeError, 'call failed: ' + `stat`
101115
return xid, verf
102116
# Caller must get procedure-specific part of reply
103117

@@ -229,7 +243,6 @@ def end_call(self):
229243

230244

231245
# Raw UDP-based client
232-
# XXX This class does not recover from missed/duplicated packets!
233246

234247
class RawUDPClient(Client):
235248

0 commit comments

Comments
 (0)