[Zope3-checkins] CVS: ZODB4/src/zodb/zeo/zrpc - client.py:1.5 connection.py:1.4 log.py:1.3 marshal.py:1.4 server.py:1.3 smac.py:1.4

Barry Warsaw barry@wooz.org
Thu, 13 Mar 2003 17:11:37 -0500


Update of /cvs-repository/ZODB4/src/zodb/zeo/zrpc
In directory cvs.zope.org:/tmp/cvs-serv922/src/zodb/zeo/zrpc

Modified Files:
	client.py connection.py log.py marshal.py server.py smac.py 
Log Message:
Eradicate the types module in ZODB (where possible).  Also normalize
on isinstance() instead of type comparisons.


=== ZODB4/src/zodb/zeo/zrpc/client.py 1.4 => 1.5 ===
--- ZODB4/src/zodb/zeo/zrpc/client.py:1.4	Mon Mar  3 12:59:53 2003
+++ ZODB4/src/zodb/zeo/zrpc/client.py	Thu Mar 13 17:11:36 2003
@@ -17,7 +17,6 @@
 import sys
 import threading
 import time
-import types
 
 from zodb.storage.interfaces import ReadOnlyError
 
@@ -69,12 +68,12 @@
             return addrlist
 
     def _guess_type(self, addr):
-        if isinstance(addr, types.StringType):
+        if isinstance(addr, str):
             return socket.AF_UNIX
 
         if (len(addr) == 2
-            and isinstance(addr[0], types.StringType)
-            and isinstance(addr[1], types.IntType)):
+            and isinstance(addr[0], str)
+            and isinstance(addr[1], int)):
             return socket.AF_INET
 
         # not anything I know about


=== ZODB4/src/zodb/zeo/zrpc/connection.py 1.3 => 1.4 ===
--- ZODB4/src/zodb/zeo/zrpc/connection.py:1.3	Tue Feb 25 13:55:06 2003
+++ ZODB4/src/zodb/zeo/zrpc/connection.py	Thu Mar 13 17:11:36 2003
@@ -16,7 +16,6 @@
 import select
 import sys
 import threading
-import types
 import logging
 
 from zodb.zeo import threadedasync
@@ -125,7 +124,7 @@
         self.closed = 0
         self.msgid = 0
         self.peer_protocol_version = None # set in recv_handshake()
-        if isinstance(addr, types.TupleType):
+        if isinstance(addr, tuple):
             self.log_label = "zrpc-conn:%s:%d" % addr
         else:
             self.log_label = "zrpc-conn:%s" % addr
@@ -290,7 +289,7 @@
         if flags & ASYNC:
             self.log_error("Asynchronous call raised exception: %s" % self)
             return
-        if type(err_value) is not types.InstanceType:
+        if not isinstance(err_value, types.InstanceType):
             err_value = err_type, err_value
 
         try:
@@ -328,8 +327,8 @@
             raise DisconnectedError()
         msgid = self.send_call(method, args, 0)
         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 isinstance(r_args[0], types.ClassType)
             and issubclass(r_args[0], Exception)):
             inst = r_args[1]
             raise inst # error raised by server
@@ -351,7 +350,7 @@
 
     def _deferred_wait(self, 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 issubclass(r_args[0], Exception)):
             inst = r_args[1]


=== ZODB4/src/zodb/zeo/zrpc/log.py 1.2 => 1.3 ===
--- ZODB4/src/zodb/zeo/zrpc/log.py:1.2	Wed Dec 25 09:12:23 2002
+++ ZODB4/src/zodb/zeo/zrpc/log.py	Thu Mar 13 17:11:36 2003
@@ -12,7 +12,6 @@
 #
 ##############################################################################
 import os
-import types
 import threading
 import logging
 
@@ -67,7 +66,7 @@
     # The pickle is near the beginning, too, and you can often fit the
     # module name in the pickle.
 
-    if isinstance(obj, types.StringType):
+    if isinstance(obj, str):
         if len(obj) > REPR_LIMIT:
             r = repr(obj[:REPR_LIMIT])
         else:
@@ -75,7 +74,7 @@
         if len(r) > REPR_LIMIT:
             r = r[:REPR_LIMIT-4] + '...' + r[-1]
         return r
-    elif isinstance(obj, types.TupleType):
+    elif isinstance(obj, tuple):
         elts = []
         size = 0
         for elt in obj:


=== ZODB4/src/zodb/zeo/zrpc/marshal.py 1.3 => 1.4 ===
--- ZODB4/src/zodb/zeo/zrpc/marshal.py:1.3	Tue Feb 25 13:55:06 2003
+++ ZODB4/src/zodb/zeo/zrpc/marshal.py	Thu Mar 13 17:11:36 2003
@@ -59,7 +59,7 @@
         return r
 
     # XXX what's a better way to do this?  esp w/ 2.1 & 2.2
-    if type(r) == types.ClassType and issubclass(r, Exception):
+    if isinstance(r, types.ClassType) and issubclass(r, Exception):
         return r
 
     raise ZRPCError("Unsafe global: %s.%s" % (module, name))


=== ZODB4/src/zodb/zeo/zrpc/server.py 1.2 => 1.3 ===
--- ZODB4/src/zodb/zeo/zrpc/server.py:1.2	Wed Dec 25 09:12:23 2002
+++ ZODB4/src/zodb/zeo/zrpc/server.py	Thu Mar 13 17:11:36 2003
@@ -13,7 +13,6 @@
 ##############################################################################
 import asyncore
 import socket
-import types
 
 from zodb.zeo import threadedasync
 from zodb.zeo.zrpc.connection import Connection, Delay
@@ -38,7 +37,7 @@
         self._open_socket()
 
     def _open_socket(self):
-        if type(self.addr) == types.TupleType:
+        if isinstance(self.addr, tuple):
             self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
         else:
             self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM)


=== ZODB4/src/zodb/zeo/zrpc/smac.py 1.3 => 1.4 ===
--- ZODB4/src/zodb/zeo/zrpc/smac.py:1.3	Tue Feb 25 13:55:06 2003
+++ ZODB4/src/zodb/zeo/zrpc/smac.py	Thu Mar 13 17:11:36 2003
@@ -16,7 +16,6 @@
 import asyncore, struct
 import threading
 import socket, errno
-from types import StringType
 
 from zodb.zeo.zrpc.interfaces import DisconnectedError
 from zodb.zeo.zrpc import log
@@ -105,7 +104,7 @@
             if msg_size > input_len:
                 if inp is None:
                     self.__inp = d
-                elif type(self.__inp) is StringType:
+                elif isinstance(self.__inp, str):
                     self.__inp = [self.__inp, d]
                 else:
                     self.__inp.append(d)
@@ -113,7 +112,7 @@
                 return # keep waiting for more input
 
             # load all previous input and d into single string inp
-            if isinstance(inp, StringType):
+            if isinstance(inp, str):
                 inp = inp + d
             elif inp is None:
                 inp = d