mirror of
https://github.com/python/cpython.git
synced 2025-11-13 15:40:05 +00:00
Improved exception handing. Added some XXX comments.
This commit is contained in:
parent
4ac605e627
commit
c4698fbfbe
1 changed files with 27 additions and 14 deletions
|
|
@ -1,5 +1,11 @@
|
||||||
# Implement (a subset of) Sun RPC, version 2 -- RFC1057.
|
# Implement (a subset of) Sun RPC, version 2 -- RFC1057.
|
||||||
|
|
||||||
|
# XXX There should be separate exceptions for the various reasons why
|
||||||
|
# XXX an RPC can fail, rather than using RuntimeError for everything
|
||||||
|
|
||||||
|
# XXX The UDP version of the protocol resends requests when it does
|
||||||
|
# XXX not receive a timely reply -- use only for idempotent calls!
|
||||||
|
|
||||||
import xdr
|
import xdr
|
||||||
import socket
|
import socket
|
||||||
import os
|
import os
|
||||||
|
|
@ -80,24 +86,32 @@ class Unpacker(xdr.Unpacker):
|
||||||
xid = self.unpack_uint()
|
xid = self.unpack_uint()
|
||||||
mtype = self.unpack_enum()
|
mtype = self.unpack_enum()
|
||||||
if mtype <> REPLY:
|
if mtype <> REPLY:
|
||||||
raise RuntimeError, 'no REPLY but ' + str(mtype)
|
raise RuntimeError, 'no REPLY but ' + `mtype`
|
||||||
stat = self.unpack_enum()
|
stat = self.unpack_enum()
|
||||||
|
if stat == MSG_DENIED:
|
||||||
|
stat = self.unpack_enum()
|
||||||
|
if stat == RPC_MISMATCH:
|
||||||
|
low = self.unpack_uint()
|
||||||
|
high = self.unpack_uint()
|
||||||
|
raise RuntimeError, \
|
||||||
|
'MSG_DENIED: RPC_MISMATCH: ' + `low, high`
|
||||||
|
if stat == AUTH_ERROR:
|
||||||
|
stat = self.unpack_uint()
|
||||||
|
raise RuntimeError, \
|
||||||
|
'MSG_DENIED: AUTH_ERROR: ' + `stat`
|
||||||
|
raise RuntimeError, 'MSG_DENIED: ' + `stat`
|
||||||
if stat <> MSG_ACCEPTED:
|
if stat <> MSG_ACCEPTED:
|
||||||
if stat == MSG_DENIED:
|
raise RuntimeError, \
|
||||||
stat = self.unpack_enum()
|
'Neither MSG_DENIED nor MSG_ACCEPTED: ' + `stat`
|
||||||
if stat == RPC_MISMATCH:
|
|
||||||
low = self.unpack_uint()
|
|
||||||
high = self.unpack_uint()
|
|
||||||
raise 'RPC_MISMATCH', (low, high)
|
|
||||||
if stat == AUTH_ERROR:
|
|
||||||
stat = self.unpack_uint()
|
|
||||||
raise 'AUTH_ERROR', str(stat)
|
|
||||||
raise 'MSG_REJECTED', str(stat)
|
|
||||||
raise RuntimeError, 'no MSG_ACCEPTED but ' + str(stat)
|
|
||||||
verf = self.unpack_auth()
|
verf = self.unpack_auth()
|
||||||
stat = self.unpack_enum()
|
stat = self.unpack_enum()
|
||||||
|
if stat == PROG_MISMATCH:
|
||||||
|
low = self.unpack_uint()
|
||||||
|
high = self.unpack_uint()
|
||||||
|
raise RuntimeError, \
|
||||||
|
'call failed: PROG_MISMATCH: ' + `low, high`
|
||||||
if stat <> SUCCESS:
|
if stat <> SUCCESS:
|
||||||
raise RuntimeError, 'no SUCCESS but ' + str(stat)
|
raise RuntimeError, 'call failed: ' + `stat`
|
||||||
return xid, verf
|
return xid, verf
|
||||||
# Caller must get procedure-specific part of reply
|
# Caller must get procedure-specific part of reply
|
||||||
|
|
||||||
|
|
@ -229,7 +243,6 @@ class RawTCPClient(Client):
|
||||||
|
|
||||||
|
|
||||||
# Raw UDP-based client
|
# Raw UDP-based client
|
||||||
# XXX This class does not recover from missed/duplicated packets!
|
|
||||||
|
|
||||||
class RawUDPClient(Client):
|
class RawUDPClient(Client):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue