Commit 7e84d9b4 authored by Jim Fulton's avatar Jim Fulton

Modernized type introspection

parent 2a96309c
...@@ -32,8 +32,6 @@ addresses and/or object identity (the synthesized bucket has an address ...@@ -32,8 +32,6 @@ addresses and/or object identity (the synthesized bucket has an address
that doesn't exist in the actual BTree). that doesn't exist in the actual BTree).
""" """
from types import TupleType
from BTrees.OOBTree import OOBTree, OOBucket, OOSet, OOTreeSet from BTrees.OOBTree import OOBTree, OOBucket, OOSet, OOTreeSet
from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet
...@@ -122,10 +120,10 @@ def crack_btree(t, is_mapping): ...@@ -122,10 +120,10 @@ def crack_btree(t, is_mapping):
if state is None: if state is None:
return BTREE_EMPTY, [], [] return BTREE_EMPTY, [], []
assert isinstance(state, TupleType) assert isinstance(state, tuple)
if len(state) == 1: if len(state) == 1:
state = state[0] state = state[0]
assert isinstance(state, TupleType) and len(state) == 1 assert isinstance(state, tuple) and len(state) == 1
state = state[0] state = state[0]
return BTREE_ONE, state, None return BTREE_ONE, state, None
...@@ -174,7 +172,7 @@ def crack_btree(t, is_mapping): ...@@ -174,7 +172,7 @@ def crack_btree(t, is_mapping):
def crack_bucket(b, is_mapping): def crack_bucket(b, is_mapping):
state = b.__getstate__() state = b.__getstate__()
assert isinstance(state, TupleType) assert isinstance(state, tuple)
assert 1 <= len(state) <= 2 assert 1 <= len(state) <= 2
data = state[0] data = state[0]
if not is_mapping: if not is_mapping:
......
...@@ -40,7 +40,6 @@ import tempfile ...@@ -40,7 +40,6 @@ import tempfile
import thread import thread
import threading import threading
import time import time
import types
import weakref import weakref
import zc.lockfile import zc.lockfile
import ZEO.interfaces import ZEO.interfaces
...@@ -671,10 +670,10 @@ class ClientStorage(object): ...@@ -671,10 +670,10 @@ class ClientStorage(object):
def set_server_addr(self, addr): def set_server_addr(self, addr):
# Normalize server address and convert to string # Normalize server address and convert to string
if isinstance(addr, types.StringType): if isinstance(addr, str):
self._server_addr = addr self._server_addr = addr
else: else:
assert isinstance(addr, types.TupleType) assert isinstance(addr, tuple)
# If the server is on a remote host, we need to guarantee # If the server is on a remote host, we need to guarantee
# that all clients used the same name for the server. If # that all clients used the same name for the server. If
# they don't, the sortKey() may be different for each client. # they don't, the sortKey() may be different for each client.
......
...@@ -19,7 +19,6 @@ $Id$ ...@@ -19,7 +19,6 @@ $Id$
import asyncore import asyncore
import socket import socket
import time import time
import types
import logging import logging
zeo_version = 'unknown' zeo_version = 'unknown'
...@@ -139,7 +138,7 @@ class StatsServer(asyncore.dispatcher): ...@@ -139,7 +138,7 @@ class StatsServer(asyncore.dispatcher):
asyncore.dispatcher.__init__(self) asyncore.dispatcher.__init__(self)
self.addr = addr self.addr = addr
self.stats = stats self.stats = stats
if type(self.addr) == types.TupleType: if type(self.addr) == tuple:
self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
else: else:
self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM) self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM)
......
...@@ -60,7 +60,6 @@ import sys ...@@ -60,7 +60,6 @@ import sys
import time import time
import getopt import getopt
import struct import struct
from types import StringType
# we assign ctime locally to facilitate test replacement! # we assign ctime locally to facilitate test replacement!
from time import ctime from time import ctime
...@@ -357,7 +356,7 @@ def U64(s): ...@@ -357,7 +356,7 @@ def U64(s):
return struct.unpack(">Q", s)[0] return struct.unpack(">Q", s)[0]
def oid_repr(oid): def oid_repr(oid):
if isinstance(oid, StringType) and len(oid) == 8: if isinstance(oid, str) and len(oid) == 8:
return '%16x' % U64(oid) return '%16x' % U64(oid)
else: else:
return repr(oid) return repr(oid)
......
...@@ -27,7 +27,6 @@ from ZEO.tests import forker ...@@ -27,7 +27,6 @@ from ZEO.tests import forker
import os import os
import random import random
import types
NUM_TRANSACTIONS_PER_CONN = 10 NUM_TRANSACTIONS_PER_CONN = 10
NUM_CONNECTIONS = 10 NUM_CONNECTIONS = 10
...@@ -69,7 +68,7 @@ def work(cn): ...@@ -69,7 +68,7 @@ def work(cn):
root = cn.root() root = cn.root()
obj = random.choice(root.values()) obj = random.choice(root.values())
# walk down to the bottom # walk down to the bottom
while not isinstance(obj.value, types.StringType): while not isinstance(obj.value, str):
obj = obj.value obj = obj.value
obj.value = an_object() obj.value = an_object()
transaction.commit() transaction.commit()
......
...@@ -19,7 +19,6 @@ import socket ...@@ -19,7 +19,6 @@ import socket
import sys import sys
import threading import threading
import time import time
import types
import ZEO.zrpc.trigger import ZEO.zrpc.trigger
...@@ -180,12 +179,12 @@ class ConnectionManager(object): ...@@ -180,12 +179,12 @@ class ConnectionManager(object):
return addrlist return addrlist
def _guess_type(self, addr): def _guess_type(self, addr):
if isinstance(addr, types.StringType): if isinstance(addr, str):
return socket.AF_UNIX return socket.AF_UNIX
if (len(addr) == 2 if (len(addr) == 2
and isinstance(addr[0], types.StringType) and isinstance(addr[0], str)
and isinstance(addr[1], types.IntType)): and isinstance(addr[1], int)):
return socket.AF_INET # also denotes IPv6 return socket.AF_INET # also denotes IPv6
# not anything I know about # not anything I know about
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
############################################################################## ##############################################################################
import asyncore import asyncore
import socket import socket
import types
# _has_dualstack: True if the dual-stack sockets are supported # _has_dualstack: True if the dual-stack sockets are supported
try: try:
...@@ -51,7 +50,7 @@ class Dispatcher(asyncore.dispatcher): ...@@ -51,7 +50,7 @@ class Dispatcher(asyncore.dispatcher):
self._open_socket() self._open_socket()
def _open_socket(self): def _open_socket(self):
if type(self.addr) == types.TupleType: if type(self.addr) == tuple:
if self.addr[0] == '' and _has_dualstack: if self.addr[0] == '' and _has_dualstack:
# Wildcard listen on all interfaces, both IPv4 and # Wildcard listen on all interfaces, both IPv4 and
# IPv6 if possible # IPv6 if possible
......
...@@ -34,7 +34,6 @@ except ImportError: ...@@ -34,7 +34,6 @@ except ImportError:
import socket import socket
import struct import struct
import threading import threading
from types import StringType
from ZEO.zrpc.log import log from ZEO.zrpc.log import log
from ZEO.zrpc.error import DisconnectedError from ZEO.zrpc.error import DisconnectedError
...@@ -182,7 +181,7 @@ class SizedMessageAsyncConnection(asyncore.dispatcher): ...@@ -182,7 +181,7 @@ class SizedMessageAsyncConnection(asyncore.dispatcher):
if msg_size > input_len: if msg_size > input_len:
if inp is None: if inp is None:
self.__inp = d self.__inp = d
elif type(self.__inp) is StringType: elif type(self.__inp) is str:
self.__inp = [self.__inp, d] self.__inp = [self.__inp, d]
else: else:
self.__inp.append(d) self.__inp.append(d)
...@@ -190,7 +189,7 @@ class SizedMessageAsyncConnection(asyncore.dispatcher): ...@@ -190,7 +189,7 @@ class SizedMessageAsyncConnection(asyncore.dispatcher):
return # keep waiting for more input return # keep waiting for more input
# load all previous input and d into single string inp # load all previous input and d into single string inp
if isinstance(inp, StringType): if isinstance(inp, str):
inp = inp + d inp = inp + d
elif inp is None: elif inp is None:
inp = d inp = d
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
import pickle import pickle
import sys import sys
import types
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from cStringIO import StringIO from cStringIO import StringIO
...@@ -103,7 +102,7 @@ def get_type(record): ...@@ -103,7 +102,7 @@ def get_type(record):
except: except:
raise raise
classinfo = unpickled[0] classinfo = unpickled[0]
if isinstance(classinfo, types.TupleType): if isinstance(classinfo, tuple):
mod, klass = classinfo mod, klass = classinfo
return "%s.%s" % (mod, klass) return "%s.%s" % (mod, klass)
else: else:
......
...@@ -8,8 +8,6 @@ Try to find all the BTrees in a Data.fs, call their _check() methods, ...@@ -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(). and run them through BTrees.check.check().
""" """
from types import IntType
import ZODB import ZODB
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from BTrees.check import check from BTrees.check import check
...@@ -48,9 +46,9 @@ def get_subobjects(obj): ...@@ -48,9 +46,9 @@ def get_subobjects(obj):
except AttributeError: except AttributeError:
items = () items = ()
for k, v in items: for k, v in items:
if not isinstance(k, IntType): if not isinstance(k, int):
sub.append(("<key>", k)) sub.append(("<key>", k))
if not isinstance(v, IntType): if not isinstance(v, int):
sub.append(("[%s]" % repr(k), v)) sub.append(("[%s]" % repr(k), v))
# what if it is a sequence? # what if it is a sequence?
......
...@@ -64,7 +64,6 @@ in non-current revisions. ...@@ -64,7 +64,6 @@ in non-current revisions.
""" """
import traceback import traceback
import types
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from ZODB.TimeStamp import TimeStamp from ZODB.TimeStamp import TimeStamp
...@@ -88,7 +87,7 @@ def report(oid, data, serial, missing): ...@@ -88,7 +87,7 @@ def report(oid, data, serial, missing):
print "last updated: %s, tid=%s" % (ts, hex(u64(serial))) print "last updated: %s, tid=%s" % (ts, hex(u64(serial)))
print "refers to invalid object%s:" % plural print "refers to invalid object%s:" % plural
for oid, info, reason in missing: for oid, info, reason in missing:
if isinstance(info, types.TupleType): if isinstance(info, tuple):
description = "%s.%s" % info description = "%s.%s" % info
else: else:
description = str(info) description = str(info)
......
...@@ -340,7 +340,6 @@ def doit(srcdb, dstdb, options): ...@@ -340,7 +340,6 @@ def doit(srcdb, dstdb, options):
# helper to deal with differences between old-style store() return and # helper to deal with differences between old-style store() return and
# new-style store() return that supports ZEO # new-style store() return that supports ZEO
import types
class RevidAccumulator: class RevidAccumulator:
...@@ -349,12 +348,12 @@ class RevidAccumulator: ...@@ -349,12 +348,12 @@ class RevidAccumulator:
def _update_from_list(self, list): def _update_from_list(self, list):
for oid, serial in list: for oid, serial in list:
if not isinstance(serial, types.StringType): if not isinstance(serial, str):
raise serial raise serial
self.data[oid] = serial self.data[oid] = serial
def store(self, oid, result): def store(self, oid, result):
if isinstance(result, types.StringType): if isinstance(result, str):
self.data[oid] = result self.data[oid] = result
elif result is not None: elif result is not None:
self._update_from_list(result) self._update_from_list(result)
......
...@@ -17,7 +17,6 @@ Any storage that supports undo() must pass these tests. ...@@ -17,7 +17,6 @@ Any storage that supports undo() must pass these tests.
""" """
import time import time
import types
from persistent import Persistent from persistent import Persistent
import transaction import transaction
...@@ -61,7 +60,7 @@ class TransactionalUndoStorage: ...@@ -61,7 +60,7 @@ class TransactionalUndoStorage:
def _transaction_store(self, oid, rev, data, vers, trans): def _transaction_store(self, oid, rev, data, vers, trans):
r = self._storage.store(oid, rev, data, vers, trans) r = self._storage.store(oid, rev, data, vers, trans)
if r: if r:
if type(r) == types.StringType: if type(r) == str:
self.__serials[oid] = r self.__serials[oid] = r
else: else:
for oid, serial in r: 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