Commit 1e712938 authored by Jim Fulton's avatar Jim Fulton

Updated to reflect differences in exception meta types ebtween Python

2.4 and 2.5.
parent 08b78663
...@@ -17,7 +17,6 @@ import errno ...@@ -17,7 +17,6 @@ import errno
import select import select
import sys import sys
import threading import threading
import types
import logging import logging
import traceback, time import traceback, time
...@@ -33,6 +32,8 @@ from ZODB.loglevels import BLATHER, TRACE ...@@ -33,6 +32,8 @@ from ZODB.loglevels import BLATHER, TRACE
REPLY = ".reply" # message name used for replies REPLY = ".reply" # message name used for replies
ASYNC = 1 ASYNC = 1
exception_type_type = type(Exception)
############################################################################## ##############################################################################
# Dedicated Client select loop: # Dedicated Client select loop:
client_timeout = 30.0 client_timeout = 30.0
...@@ -361,7 +362,7 @@ class Connection(smac.SizedMessageAsyncConnection, object): ...@@ -361,7 +362,7 @@ class Connection(smac.SizedMessageAsyncConnection, object):
assert tag in "CS" assert tag in "CS"
self.tag = tag self.tag = tag
self.logger = logging.getLogger('ZEO.zrpc.Connection(%c)' % tag) self.logger = logging.getLogger('ZEO.zrpc.Connection(%c)' % tag)
if isinstance(addr, types.TupleType): if isinstance(addr, tuple):
self.log_label = "(%s:%d) " % addr self.log_label = "(%s:%d) " % addr
else: else:
self.log_label = "(%s) " % addr self.log_label = "(%s) " % addr
...@@ -604,7 +605,7 @@ class Connection(smac.SizedMessageAsyncConnection, object): ...@@ -604,7 +605,7 @@ class Connection(smac.SizedMessageAsyncConnection, object):
self.log("Asynchronous call raised exception: %s" % self, self.log("Asynchronous call raised exception: %s" % self,
level=logging.ERROR, exc_info=True) level=logging.ERROR, exc_info=True)
return return
if type(err_value) is not types.InstanceType: if not isinstance(err_value, Exception):
err_value = err_type, err_value err_value = err_type, err_value
# encode() can pass on a wide variety of exceptions from cPickle. # encode() can pass on a wide variety of exceptions from cPickle.
...@@ -664,8 +665,8 @@ class Connection(smac.SizedMessageAsyncConnection, object): ...@@ -664,8 +665,8 @@ class Connection(smac.SizedMessageAsyncConnection, object):
raise DisconnectedError() raise DisconnectedError()
msgid = self.send_call(method, args, 0) msgid = self.send_call(method, args, 0)
r_flags, r_args = self.wait(msgid) r_flags, r_args = self.wait(msgid)
if (isinstance(r_args, types.TupleType) and len(r_args) > 1 if (isinstance(r_args, tuple) and len(r_args) > 1
and type(r_args[0]) == types.ClassType and type(r_args[0]) == exception_type_type
and issubclass(r_args[0], Exception)): and issubclass(r_args[0], Exception)):
inst = r_args[1] inst = r_args[1]
raise inst # error raised by server raise inst # error raised by server
...@@ -687,8 +688,8 @@ class Connection(smac.SizedMessageAsyncConnection, object): ...@@ -687,8 +688,8 @@ class Connection(smac.SizedMessageAsyncConnection, object):
def _deferred_wait(self, msgid): def _deferred_wait(self, msgid):
r_flags, r_args = self.wait(msgid) r_flags, r_args = self.wait(msgid)
if (isinstance(r_args, types.TupleType) if (isinstance(r_args, tuple)
and type(r_args[0]) == types.ClassType and type(r_args[0]) == exception_type_type
and issubclass(r_args[0], Exception)): and issubclass(r_args[0], Exception)):
inst = r_args[1] inst = r_args[1]
raise inst # error raised by server raise inst # error raised by server
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
############################################################################## ##############################################################################
import cPickle import cPickle
from cStringIO import StringIO from cStringIO import StringIO
import types
import logging import logging
from ZEO.zrpc.error import ZRPCError from ZEO.zrpc.error import ZRPCError
...@@ -56,6 +55,8 @@ class Marshaller: ...@@ -56,6 +55,8 @@ class Marshaller:
_globals = globals() _globals = globals()
_silly = ('__doc__',) _silly = ('__doc__',)
exception_type_type = type(Exception)
def find_global(module, name): def find_global(module, name):
"""Helper for message unpickler""" """Helper for message unpickler"""
try: try:
...@@ -73,7 +74,7 @@ def find_global(module, name): ...@@ -73,7 +74,7 @@ def find_global(module, name):
return r return r
# TODO: is there a better way to do this? # TODO: is there a better way to do this?
if type(r) == types.ClassType and issubclass(r, Exception): if type(r) == exception_type_type and issubclass(r, Exception):
return r return r
raise ZRPCError("Unsafe global: %s.%s" % (module, name)) raise ZRPCError("Unsafe global: %s.%s" % (module, name))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment