[Zodb-checkins] SVN: ZODB/branches/3.8/src/ZEO/zrpc/ Updated to reflect differences in exception meta types ebtween Python

Jim Fulton jim at zope.com
Mon Jun 25 11:00:16 EDT 2007


Log message for revision 77047:
  Updated to reflect differences in exception meta types ebtween Python
  2.4 and 2.5.
  

Changed:
  U   ZODB/branches/3.8/src/ZEO/zrpc/connection.py
  U   ZODB/branches/3.8/src/ZEO/zrpc/marshal.py

-=-
Modified: ZODB/branches/3.8/src/ZEO/zrpc/connection.py
===================================================================
--- ZODB/branches/3.8/src/ZEO/zrpc/connection.py	2007-06-25 15:00:12 UTC (rev 77046)
+++ ZODB/branches/3.8/src/ZEO/zrpc/connection.py	2007-06-25 15:00:15 UTC (rev 77047)
@@ -17,7 +17,6 @@
 import select
 import sys
 import threading
-import types
 import logging
 
 import traceback, time
@@ -33,6 +32,8 @@
 REPLY = ".reply" # message name used for replies
 ASYNC = 1
 
+exception_type_type = type(Exception)
+
 ##############################################################################
 # Dedicated Client select loop:
 client_timeout = 30.0
@@ -361,7 +362,7 @@
         assert tag in "CS"
         self.tag = 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
         else:
             self.log_label = "(%s) " % addr
@@ -604,7 +605,7 @@
             self.log("Asynchronous call raised exception: %s" % self,
                      level=logging.ERROR, exc_info=True)
             return
-        if type(err_value) is not types.InstanceType:
+        if not isinstance(err_value, Exception):
             err_value = err_type, err_value
 
         # encode() can pass on a wide variety of exceptions from cPickle.
@@ -664,8 +665,8 @@
             raise DisconnectedError()
         msgid = self.send_call(method, args, 0)
         r_flags, r_args = self.wait(msgid)
-        if (isinstance(r_args, types.TupleType) and len(r_args) > 1
-            and type(r_args[0]) == types.ClassType
+        if (isinstance(r_args, tuple) and len(r_args) > 1
+            and type(r_args[0]) == exception_type_type
             and issubclass(r_args[0], Exception)):
             inst = r_args[1]
             raise inst # error raised by server
@@ -687,8 +688,8 @@
 
     def _deferred_wait(self, msgid):
         r_flags, r_args = self.wait(msgid)
-        if (isinstance(r_args, types.TupleType)
-            and type(r_args[0]) == types.ClassType
+        if (isinstance(r_args, tuple)
+            and type(r_args[0]) == exception_type_type
             and issubclass(r_args[0], Exception)):
             inst = r_args[1]
             raise inst # error raised by server

Modified: ZODB/branches/3.8/src/ZEO/zrpc/marshal.py
===================================================================
--- ZODB/branches/3.8/src/ZEO/zrpc/marshal.py	2007-06-25 15:00:12 UTC (rev 77046)
+++ ZODB/branches/3.8/src/ZEO/zrpc/marshal.py	2007-06-25 15:00:15 UTC (rev 77047)
@@ -13,7 +13,6 @@
 ##############################################################################
 import cPickle
 from cStringIO import StringIO
-import types
 import logging
 
 from ZEO.zrpc.error import ZRPCError
@@ -56,6 +55,8 @@
 _globals = globals()
 _silly = ('__doc__',)
 
+exception_type_type = type(Exception)
+
 def find_global(module, name):
     """Helper for message unpickler"""
     try:
@@ -73,7 +74,7 @@
         return r
 
     # 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
 
     raise ZRPCError("Unsafe global: %s.%s" % (module, name))



More information about the Zodb-checkins mailing list