Commit 936c9540 authored by Jim Fulton's avatar Jim Fulton

Modernized type introspection

parent af40f33f
......@@ -32,8 +32,6 @@ addresses and/or object identity (the synthesized bucket has an address
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 @@ def crack_btree(t, is_mapping):
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_btree(t, is_mapping):
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:
......
......@@ -40,7 +40,6 @@ import tempfile
import thread
import threading
import time
import types
import weakref
import zc.lockfile
import ZEO.interfaces
......@@ -671,10 +670,10 @@ class ClientStorage(object):
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.
......
......@@ -19,7 +19,6 @@ $Id$
import asyncore
import socket
import time
import types
import logging
zeo_version = 'unknown'
......@@ -139,7 +138,7 @@ class StatsServer(asyncore.dispatcher):
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)
......
......@@ -60,7 +60,6 @@ import sys
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 @@ def U64(s):
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)
......
......@@ -27,7 +27,6 @@ from ZEO.tests import forker
import os
import random
import types
NUM_TRANSACTIONS_PER_CONN = 10
NUM_CONNECTIONS = 10
......@@ -69,7 +68,7 @@ def work(cn):
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()
......
......@@ -19,7 +19,6 @@ import socket
import sys
import threading
import time
import types
import ZEO.zrpc.trigger
......@@ -180,12 +179,12 @@ class ConnectionManager(object):
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
......
......@@ -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 @@ class Dispatcher(asyncore.dispatcher):
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
......
......@@ -34,7 +34,6 @@ except ImportError:
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 @@ class SizedMessageAsyncConnection(asyncore.dispatcher):
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 @@ class SizedMessageAsyncConnection(asyncore.dispatcher):
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
......
......@@ -4,7 +4,6 @@
import pickle
import sys
import types
from ZODB.FileStorage import FileStorage
from cStringIO import StringIO
......@@ -103,7 +102,7 @@ def get_type(record):
except:
raise
classinfo = unpickled[0]
if isinstance(classinfo, types.TupleType):
if isinstance(classinfo, tuple):
mod, klass = classinfo
return "%s.%s" % (mod, klass)
else:
......
......@@ -8,8 +8,6 @@ Try to find all the BTrees in a Data.fs, call their _check() methods,
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 @@ def get_subobjects(obj):
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?
......
......@@ -64,7 +64,6 @@ in non-current revisions.
"""
import traceback
import types
from ZODB.FileStorage import FileStorage
from ZODB.TimeStamp import TimeStamp
......@@ -88,7 +87,7 @@ def report(oid, data, serial, missing):
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)
......
......@@ -340,7 +340,6 @@ def doit(srcdb, dstdb, options):
# 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 @@ class RevidAccumulator:
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)
......
......@@ -17,7 +17,6 @@ Any storage that supports undo() must pass these tests.
"""
import time
import types
from persistent import Persistent
import transaction
......@@ -61,7 +60,7 @@ class TransactionalUndoStorage:
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:
......
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