[Zodb-checkins] SVN: ZODB/trunk/src/ Modernized type introspection

Jim Fulton jim at zope.com
Thu Nov 17 14:06:41 UTC 2011


Log message for revision 123412:
  Modernized type introspection

Changed:
  U   ZODB/trunk/src/BTrees/check.py
  U   ZODB/trunk/src/ZEO/ClientStorage.py
  U   ZODB/trunk/src/ZEO/monitor.py
  U   ZODB/trunk/src/ZEO/scripts/cache_stats.py
  U   ZODB/trunk/src/ZEO/tests/stress.py
  U   ZODB/trunk/src/ZEO/zrpc/client.py
  U   ZODB/trunk/src/ZEO/zrpc/server.py
  U   ZODB/trunk/src/ZEO/zrpc/smac.py
  U   ZODB/trunk/src/ZODB/scripts/analyze.py
  U   ZODB/trunk/src/ZODB/scripts/checkbtrees.py
  U   ZODB/trunk/src/ZODB/scripts/fsrefs.py
  U   ZODB/trunk/src/ZODB/scripts/migrate.py
  U   ZODB/trunk/src/ZODB/tests/TransactionalUndoStorage.py

-=-
Modified: ZODB/trunk/src/BTrees/check.py
===================================================================
--- ZODB/trunk/src/BTrees/check.py	2011-11-17 12:23:48 UTC (rev 123411)
+++ ZODB/trunk/src/BTrees/check.py	2011-11-17 14:06:40 UTC (rev 123412)
@@ -32,8 +32,6 @@
 that doesn't exist in the actual BTree).
 """
 
-from types import TupleType
-
 from BTrees.OOBTree import OOBTree, OOBucket, OOSet, OOTreeSet
 from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
 from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet
@@ -122,10 +120,10 @@
     if state is None:
         return BTREE_EMPTY, [], []
 
-    assert isinstance(state, TupleType)
+    assert isinstance(state, tuple)
     if len(state) == 1:
         state = state[0]
-        assert isinstance(state, TupleType) and len(state) == 1
+        assert isinstance(state, tuple) and len(state) == 1
         state = state[0]
         return BTREE_ONE, state, None
 
@@ -174,7 +172,7 @@
 
 def crack_bucket(b, is_mapping):
     state = b.__getstate__()
-    assert isinstance(state, TupleType)
+    assert isinstance(state, tuple)
     assert 1 <= len(state) <= 2
     data = state[0]
     if not is_mapping:

Modified: ZODB/trunk/src/ZEO/ClientStorage.py
===================================================================
--- ZODB/trunk/src/ZEO/ClientStorage.py	2011-11-17 12:23:48 UTC (rev 123411)
+++ ZODB/trunk/src/ZEO/ClientStorage.py	2011-11-17 14:06:40 UTC (rev 123412)
@@ -40,7 +40,6 @@
 import thread
 import threading
 import time
-import types
 import weakref
 import zc.lockfile
 import ZEO.interfaces
@@ -671,10 +670,10 @@
 
     def set_server_addr(self, addr):
         # Normalize server address and convert to string
-        if isinstance(addr, types.StringType):
+        if isinstance(addr, str):
             self._server_addr = addr
         else:
-            assert isinstance(addr, types.TupleType)
+            assert isinstance(addr, tuple)
             # If the server is on a remote host, we need to guarantee
             # that all clients used the same name for the server.  If
             # they don't, the sortKey() may be different for each client.

Modified: ZODB/trunk/src/ZEO/monitor.py
===================================================================
--- ZODB/trunk/src/ZEO/monitor.py	2011-11-17 12:23:48 UTC (rev 123411)
+++ ZODB/trunk/src/ZEO/monitor.py	2011-11-17 14:06:40 UTC (rev 123412)
@@ -19,7 +19,6 @@
 import asyncore
 import socket
 import time
-import types
 import logging
 
 zeo_version = 'unknown'
@@ -139,7 +138,7 @@
         asyncore.dispatcher.__init__(self)
         self.addr = addr
         self.stats = stats
-        if type(self.addr) == types.TupleType:
+        if type(self.addr) == tuple:
             self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
         else:
             self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM)

Modified: ZODB/trunk/src/ZEO/scripts/cache_stats.py
===================================================================
--- ZODB/trunk/src/ZEO/scripts/cache_stats.py	2011-11-17 12:23:48 UTC (rev 123411)
+++ ZODB/trunk/src/ZEO/scripts/cache_stats.py	2011-11-17 14:06:40 UTC (rev 123412)
@@ -60,7 +60,6 @@
 import time
 import getopt
 import struct
-from types import StringType
 
 # we assign ctime locally to facilitate test replacement!
 from time import ctime
@@ -357,7 +356,7 @@
     return struct.unpack(">Q", s)[0]
 
 def oid_repr(oid):
-    if isinstance(oid, StringType) and len(oid) == 8:
+    if isinstance(oid, str) and len(oid) == 8:
         return '%16x' % U64(oid)
     else:
         return repr(oid)

Modified: ZODB/trunk/src/ZEO/tests/stress.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/stress.py	2011-11-17 12:23:48 UTC (rev 123411)
+++ ZODB/trunk/src/ZEO/tests/stress.py	2011-11-17 14:06:40 UTC (rev 123412)
@@ -27,7 +27,6 @@
 
 import os
 import random
-import types
 
 NUM_TRANSACTIONS_PER_CONN = 10
 NUM_CONNECTIONS = 10
@@ -69,7 +68,7 @@
     root = cn.root()
     obj = random.choice(root.values())
     # walk down to the bottom
-    while not isinstance(obj.value, types.StringType):
+    while not isinstance(obj.value, str):
         obj = obj.value
     obj.value = an_object()
     transaction.commit()

Modified: ZODB/trunk/src/ZEO/zrpc/client.py
===================================================================
--- ZODB/trunk/src/ZEO/zrpc/client.py	2011-11-17 12:23:48 UTC (rev 123411)
+++ ZODB/trunk/src/ZEO/zrpc/client.py	2011-11-17 14:06:40 UTC (rev 123412)
@@ -19,7 +19,6 @@
 import sys
 import threading
 import time
-import types
 import ZEO.zrpc.trigger
 
 
@@ -180,12 +179,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 # also denotes IPv6
 
         # not anything I know about

Modified: ZODB/trunk/src/ZEO/zrpc/server.py
===================================================================
--- ZODB/trunk/src/ZEO/zrpc/server.py	2011-11-17 12:23:48 UTC (rev 123411)
+++ ZODB/trunk/src/ZEO/zrpc/server.py	2011-11-17 14:06:40 UTC (rev 123412)
@@ -13,7 +13,6 @@
 ##############################################################################
 import asyncore
 import socket
-import types
 
 # _has_dualstack: True if the dual-stack sockets are supported
 try:
@@ -51,7 +50,7 @@
         self._open_socket()
 
     def _open_socket(self):
-        if type(self.addr) == types.TupleType:
+        if type(self.addr) == tuple:
             if self.addr[0] == '' and _has_dualstack:
                 # Wildcard listen on all interfaces, both IPv4 and
                 # IPv6 if possible

Modified: ZODB/trunk/src/ZEO/zrpc/smac.py
===================================================================
--- ZODB/trunk/src/ZEO/zrpc/smac.py	2011-11-17 12:23:48 UTC (rev 123411)
+++ ZODB/trunk/src/ZEO/zrpc/smac.py	2011-11-17 14:06:40 UTC (rev 123412)
@@ -34,7 +34,6 @@
 import socket
 import struct
 import threading
-from types import StringType
 
 from ZEO.zrpc.log import log
 from ZEO.zrpc.error import DisconnectedError
@@ -182,7 +181,7 @@
             if msg_size > input_len:
                 if inp is None:
                     self.__inp = d
-                elif type(self.__inp) is StringType:
+                elif type(self.__inp) is str:
                     self.__inp = [self.__inp, d]
                 else:
                     self.__inp.append(d)
@@ -190,7 +189,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

Modified: ZODB/trunk/src/ZODB/scripts/analyze.py
===================================================================
--- ZODB/trunk/src/ZODB/scripts/analyze.py	2011-11-17 12:23:48 UTC (rev 123411)
+++ ZODB/trunk/src/ZODB/scripts/analyze.py	2011-11-17 14:06:40 UTC (rev 123412)
@@ -4,7 +4,6 @@
 
 import pickle
 import sys
-import types
 from ZODB.FileStorage import FileStorage
 from cStringIO import StringIO
 
@@ -103,7 +102,7 @@
     except:
         raise
     classinfo = unpickled[0]
-    if isinstance(classinfo, types.TupleType):
+    if isinstance(classinfo, tuple):
         mod, klass = classinfo
         return "%s.%s" % (mod, klass)
     else:

Modified: ZODB/trunk/src/ZODB/scripts/checkbtrees.py
===================================================================
--- ZODB/trunk/src/ZODB/scripts/checkbtrees.py	2011-11-17 12:23:48 UTC (rev 123411)
+++ ZODB/trunk/src/ZODB/scripts/checkbtrees.py	2011-11-17 14:06:40 UTC (rev 123412)
@@ -8,8 +8,6 @@
 and run them through BTrees.check.check().
 """
 
-from types import IntType
-
 import ZODB
 from ZODB.FileStorage import FileStorage
 from BTrees.check import check
@@ -48,9 +46,9 @@
     except AttributeError:
         items = ()
     for k, v in items:
-        if not isinstance(k, IntType):
+        if not isinstance(k, int):
             sub.append(("<key>", k))
-        if not isinstance(v, IntType):
+        if not isinstance(v, int):
             sub.append(("[%s]" % repr(k), v))
 
     # what if it is a sequence?

Modified: ZODB/trunk/src/ZODB/scripts/fsrefs.py
===================================================================
--- ZODB/trunk/src/ZODB/scripts/fsrefs.py	2011-11-17 12:23:48 UTC (rev 123411)
+++ ZODB/trunk/src/ZODB/scripts/fsrefs.py	2011-11-17 14:06:40 UTC (rev 123412)
@@ -64,7 +64,6 @@
 """
 
 import traceback
-import types
 
 from ZODB.FileStorage import FileStorage
 from ZODB.TimeStamp import TimeStamp
@@ -88,7 +87,7 @@
     print "last updated: %s, tid=%s" % (ts, hex(u64(serial)))
     print "refers to invalid object%s:" % plural
     for oid, info, reason in missing:
-        if isinstance(info, types.TupleType):
+        if isinstance(info, tuple):
             description = "%s.%s" % info
         else:
             description = str(info)

Modified: ZODB/trunk/src/ZODB/scripts/migrate.py
===================================================================
--- ZODB/trunk/src/ZODB/scripts/migrate.py	2011-11-17 12:23:48 UTC (rev 123411)
+++ ZODB/trunk/src/ZODB/scripts/migrate.py	2011-11-17 14:06:40 UTC (rev 123412)
@@ -340,7 +340,6 @@
 
 # helper to deal with differences between old-style store() return and
 # new-style store() return that supports ZEO
-import types
 
 class RevidAccumulator:
 
@@ -349,12 +348,12 @@
 
     def _update_from_list(self, list):
         for oid, serial in list:
-            if not isinstance(serial, types.StringType):
+            if not isinstance(serial, str):
                 raise serial
             self.data[oid] = serial
 
     def store(self, oid, result):
-        if isinstance(result, types.StringType):
+        if isinstance(result, str):
             self.data[oid] = result
         elif result is not None:
             self._update_from_list(result)

Modified: ZODB/trunk/src/ZODB/tests/TransactionalUndoStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/TransactionalUndoStorage.py	2011-11-17 12:23:48 UTC (rev 123411)
+++ ZODB/trunk/src/ZODB/tests/TransactionalUndoStorage.py	2011-11-17 14:06:40 UTC (rev 123412)
@@ -17,7 +17,6 @@
 """
 
 import time
-import types
 
 from persistent import Persistent
 import transaction
@@ -61,7 +60,7 @@
     def _transaction_store(self, oid, rev, data, vers, trans):
         r = self._storage.store(oid, rev, data, vers, trans)
         if r:
-            if type(r) == types.StringType:
+            if type(r) == str:
                 self.__serials[oid] = r
             else:
                 for oid, serial in r:



More information about the Zodb-checkins mailing list