In the following code segment:
try:
raise Bob()
except Fred:
print "blah"
How is the comparison of Bob and Fred implemented?
From playing around it seems to be calling isinstance underneath, is this correct?
I'm asking because I am attempting to subvert the process, specifically I want to be able to construct a Bob such that it gets caught by execpt Fred even though it isn't actually an instance of Fred or any of its subclasses.
A couple of people have asked why I'm trying to do this...
We have a RMI system, that is built around the philosophy of making it as seamless as possible, here's a quick example of it in use, note that there is no socket specific code in the RMI system, sockets just provided a convenient example.
import remobj
socket = remobj.RemObj("remote_server_name").getImport("socket")
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("", 0))
print "listening on port:", s.getsockname()[1]
s.settimeout(10)
try:
print "received:", s.recv(2048)
except socket.timeout:
print "timeout"
Now in this particular example the except doesn't work as expected because the raised object is not an instance of socket.timeout, it's an instance of one of our proxy helper classes.