Merged revisions 55795-55816 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55797 | neal.norwitz | 2007-06-07 00:00:57 -0700 (Thu, 07 Jun 2007) | 3 lines Get rid of some remnants of classic classes. types.ClassType == type. Also get rid of almost all uses of the types module and use the builtin name. ........ r55798 | neal.norwitz | 2007-06-07 00:12:36 -0700 (Thu, 07 Jun 2007) | 1 line Remove a use of types, verify commit hook works ........ r55809 | guido.van.rossum | 2007-06-07 11:11:29 -0700 (Thu, 07 Jun 2007) | 2 lines Fix syntax error introduced by Neal in last checkin. ........
This commit is contained in:
parent
7b955bd125
commit
1325790b93
|
@ -22,7 +22,6 @@ import sys
|
||||||
import copy
|
import copy
|
||||||
import xdrlib
|
import xdrlib
|
||||||
import random
|
import random
|
||||||
from types import ListType, StringType
|
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -229,7 +228,7 @@ class bsdTableDB :
|
||||||
|
|
||||||
raises TableDBError if it already exists or for other DB errors.
|
raises TableDBError if it already exists or for other DB errors.
|
||||||
"""
|
"""
|
||||||
assert isinstance(columns, ListType)
|
assert isinstance(columns, list)
|
||||||
txn = None
|
txn = None
|
||||||
try:
|
try:
|
||||||
# checking sanity of the table and column names here on
|
# checking sanity of the table and column names here on
|
||||||
|
@ -270,7 +269,7 @@ class bsdTableDB :
|
||||||
"""Return a list of columns in the given table.
|
"""Return a list of columns in the given table.
|
||||||
[] if the table doesn't exist.
|
[] if the table doesn't exist.
|
||||||
"""
|
"""
|
||||||
assert isinstance(table, StringType)
|
assert isinstance(table, str)
|
||||||
if contains_metastrings(table):
|
if contains_metastrings(table):
|
||||||
raise ValueError, "bad table name: contains reserved metastrings"
|
raise ValueError, "bad table name: contains reserved metastrings"
|
||||||
|
|
||||||
|
@ -300,7 +299,7 @@ class bsdTableDB :
|
||||||
additional columns present in the given list as well as
|
additional columns present in the given list as well as
|
||||||
all of its current columns.
|
all of its current columns.
|
||||||
"""
|
"""
|
||||||
assert isinstance(columns, ListType)
|
assert isinstance(columns, list)
|
||||||
try:
|
try:
|
||||||
self.CreateTable(table, columns)
|
self.CreateTable(table, columns)
|
||||||
except TableAlreadyExists:
|
except TableAlreadyExists:
|
||||||
|
|
|
@ -96,10 +96,10 @@ def scanvars(reader, frame, locals):
|
||||||
|
|
||||||
def html(einfo, context=5):
|
def html(einfo, context=5):
|
||||||
"""Return a nice HTML document describing a given traceback."""
|
"""Return a nice HTML document describing a given traceback."""
|
||||||
import os, types, time, traceback, linecache, inspect, pydoc
|
import os, time, traceback, linecache, inspect, pydoc
|
||||||
|
|
||||||
etype, evalue, etb = einfo
|
etype, evalue, etb = einfo
|
||||||
if type(etype) is types.ClassType:
|
if isinstance(etype, type):
|
||||||
etype = etype.__name__
|
etype = etype.__name__
|
||||||
pyver = 'Python ' + sys.version.split()[0] + ': ' + sys.executable
|
pyver = 'Python ' + sys.version.split()[0] + ': ' + sys.executable
|
||||||
date = time.ctime(time.time())
|
date = time.ctime(time.time())
|
||||||
|
@ -188,10 +188,10 @@ function calls leading up to the error, in the order they occurred.</p>'''
|
||||||
|
|
||||||
def text(einfo, context=5):
|
def text(einfo, context=5):
|
||||||
"""Return a plain text document describing a given traceback."""
|
"""Return a plain text document describing a given traceback."""
|
||||||
import os, types, time, traceback, linecache, inspect, pydoc
|
import os, time, traceback, linecache, inspect, pydoc
|
||||||
|
|
||||||
etype, evalue, etb = einfo
|
etype, evalue, etb = einfo
|
||||||
if type(etype) is types.ClassType:
|
if isinstance(etype, type):
|
||||||
etype = etype.__name__
|
etype = etype.__name__
|
||||||
pyver = 'Python ' + sys.version.split()[0] + ': ' + sys.executable
|
pyver = 'Python ' + sys.version.split()[0] + ': ' + sys.executable
|
||||||
date = time.ctime(time.time())
|
date = time.ctime(time.time())
|
||||||
|
|
10
Lib/copy.py
10
Lib/copy.py
|
@ -100,12 +100,15 @@ _copy_dispatch = d = {}
|
||||||
def _copy_immutable(x):
|
def _copy_immutable(x):
|
||||||
return x
|
return x
|
||||||
for t in (type(None), int, float, bool, str, tuple,
|
for t in (type(None), int, float, bool, str, tuple,
|
||||||
frozenset, type, range, types.ClassType,
|
frozenset, type, range,
|
||||||
types.BuiltinFunctionType,
|
types.BuiltinFunctionType,
|
||||||
types.FunctionType):
|
types.FunctionType):
|
||||||
d[t] = _copy_immutable
|
d[t] = _copy_immutable
|
||||||
for name in ("ComplexType", "UnicodeType", "CodeType"):
|
t = getattr(types, "CodeType", None)
|
||||||
t = getattr(types, name, None)
|
if t is not None:
|
||||||
|
d[t] = _copy_immutable
|
||||||
|
for name in ("complex", "unicode"):
|
||||||
|
t = globals()['__builtins__'].get(name)
|
||||||
if t is not None:
|
if t is not None:
|
||||||
d[t] = _copy_immutable
|
d[t] = _copy_immutable
|
||||||
|
|
||||||
|
@ -192,7 +195,6 @@ except AttributeError:
|
||||||
pass
|
pass
|
||||||
d[type] = _deepcopy_atomic
|
d[type] = _deepcopy_atomic
|
||||||
d[range] = _deepcopy_atomic
|
d[range] = _deepcopy_atomic
|
||||||
d[types.ClassType] = _deepcopy_atomic
|
|
||||||
d[types.BuiltinFunctionType] = _deepcopy_atomic
|
d[types.BuiltinFunctionType] = _deepcopy_atomic
|
||||||
d[types.FunctionType] = _deepcopy_atomic
|
d[types.FunctionType] = _deepcopy_atomic
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ def dis(x=None):
|
||||||
items = sorted(x.__dict__.items())
|
items = sorted(x.__dict__.items())
|
||||||
for name, x1 in items:
|
for name, x1 in items:
|
||||||
if isinstance(x1, (types.MethodType, types.FunctionType,
|
if isinstance(x1, (types.MethodType, types.FunctionType,
|
||||||
types.CodeType, types.ClassType, type)):
|
types.CodeType, type)):
|
||||||
print("Disassembly of %s:" % name)
|
print("Disassembly of %s:" % name)
|
||||||
try:
|
try:
|
||||||
dis(x1)
|
dis(x1)
|
||||||
|
|
|
@ -9,7 +9,6 @@ in the distutils.command package.
|
||||||
__revision__ = "$Id$"
|
__revision__ = "$Id$"
|
||||||
|
|
||||||
import sys, os, re
|
import sys, os, re
|
||||||
from types import *
|
|
||||||
from distutils.errors import *
|
from distutils.errors import *
|
||||||
from distutils import util, dir_util, file_util, archive_util, dep_util
|
from distutils import util, dir_util, file_util, archive_util, dep_util
|
||||||
from distutils import log
|
from distutils import log
|
||||||
|
@ -245,7 +244,7 @@ class Command:
|
||||||
elif isinstance(val, basestring):
|
elif isinstance(val, basestring):
|
||||||
setattr(self, option, re.split(r',\s*|\s+', val))
|
setattr(self, option, re.split(r',\s*|\s+', val))
|
||||||
else:
|
else:
|
||||||
if type(val) is ListType:
|
if isinstance(val, list):
|
||||||
ok = all(isinstance(v, basestring) for v in val)
|
ok = all(isinstance(v, basestring) for v in val)
|
||||||
else:
|
else:
|
||||||
ok = 0
|
ok = 0
|
||||||
|
@ -422,7 +421,7 @@ class Command:
|
||||||
# Allow 'infiles' to be a single string
|
# Allow 'infiles' to be a single string
|
||||||
if isinstance(infiles, basestring):
|
if isinstance(infiles, basestring):
|
||||||
infiles = (infiles,)
|
infiles = (infiles,)
|
||||||
elif type(infiles) not in (ListType, TupleType):
|
elif not isinstance(infiles, (list, tuple)):
|
||||||
raise TypeError, \
|
raise TypeError, \
|
||||||
"'infiles' must be a string, or a list or tuple of strings"
|
"'infiles' must be a string, or a list or tuple of strings"
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ being built/installed/distributed.
|
||||||
__revision__ = "$Id$"
|
__revision__ = "$Id$"
|
||||||
|
|
||||||
import sys, os, re
|
import sys, os, re
|
||||||
from types import *
|
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -527,7 +526,7 @@ Common commands: (see '--help-commands' for more)
|
||||||
# Also make sure that the command object provides a list of its
|
# Also make sure that the command object provides a list of its
|
||||||
# known options.
|
# known options.
|
||||||
if not (hasattr(cmd_class, 'user_options') and
|
if not (hasattr(cmd_class, 'user_options') and
|
||||||
type(cmd_class.user_options) is ListType):
|
isinstance(cmd_class.user_options, list)):
|
||||||
raise DistutilsClassError, \
|
raise DistutilsClassError, \
|
||||||
("command class %s must provide " +
|
("command class %s must provide " +
|
||||||
"'user_options' attribute (a list of tuples)") % \
|
"'user_options' attribute (a list of tuples)") % \
|
||||||
|
@ -543,7 +542,7 @@ Common commands: (see '--help-commands' for more)
|
||||||
# Check for help_options in command class. They have a different
|
# Check for help_options in command class. They have a different
|
||||||
# format (tuple of four) so we need to preprocess them here.
|
# format (tuple of four) so we need to preprocess them here.
|
||||||
if (hasattr(cmd_class, 'help_options') and
|
if (hasattr(cmd_class, 'help_options') and
|
||||||
type(cmd_class.help_options) is ListType):
|
isinstance(cmd_class.help_options, list)):
|
||||||
help_options = fix_help_options(cmd_class.help_options)
|
help_options = fix_help_options(cmd_class.help_options)
|
||||||
else:
|
else:
|
||||||
help_options = []
|
help_options = []
|
||||||
|
@ -561,7 +560,7 @@ Common commands: (see '--help-commands' for more)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (hasattr(cmd_class, 'help_options') and
|
if (hasattr(cmd_class, 'help_options') and
|
||||||
type(cmd_class.help_options) is ListType):
|
isinstance(cmd_class.help_options, list)):
|
||||||
help_option_found=0
|
help_option_found=0
|
||||||
for (help_option, short, desc, func) in cmd_class.help_options:
|
for (help_option, short, desc, func) in cmd_class.help_options:
|
||||||
if hasattr(opts, parser.get_attr_name(help_option)):
|
if hasattr(opts, parser.get_attr_name(help_option)):
|
||||||
|
@ -646,12 +645,12 @@ Common commands: (see '--help-commands' for more)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
for command in self.commands:
|
for command in self.commands:
|
||||||
if type(command) is ClassType and issubclass(command, Command):
|
if isinstance(command, type) and issubclass(command, Command):
|
||||||
klass = command
|
klass = command
|
||||||
else:
|
else:
|
||||||
klass = self.get_command_class(command)
|
klass = self.get_command_class(command)
|
||||||
if (hasattr(klass, 'help_options') and
|
if (hasattr(klass, 'help_options') and
|
||||||
type(klass.help_options) is ListType):
|
isinstance(klass.help_options, list)):
|
||||||
parser.set_option_table(klass.user_options +
|
parser.set_option_table(klass.user_options +
|
||||||
fix_help_options(klass.help_options))
|
fix_help_options(klass.help_options))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -6,7 +6,6 @@ modules in setup scripts."""
|
||||||
__revision__ = "$Id$"
|
__revision__ = "$Id$"
|
||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
from types import *
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import warnings
|
import warnings
|
||||||
|
@ -104,7 +103,7 @@ class Extension:
|
||||||
**kw # To catch unknown keywords
|
**kw # To catch unknown keywords
|
||||||
):
|
):
|
||||||
assert isinstance(name, basestring), "'name' must be a string"
|
assert isinstance(name, basestring), "'name' must be a string"
|
||||||
assert (type(sources) is ListType and
|
assert (isinstance(sources, list) and
|
||||||
all(isinstance(v, basestring) for v in sources)), \
|
all(isinstance(v, basestring) for v in sources)), \
|
||||||
"'sources' must be a list of strings"
|
"'sources' must be a list of strings"
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ lines, and joining lines with backslashes."""
|
||||||
|
|
||||||
__revision__ = "$Id$"
|
__revision__ = "$Id$"
|
||||||
|
|
||||||
from types import *
|
|
||||||
import sys, os, io
|
import sys, os, io
|
||||||
|
|
||||||
|
|
||||||
|
@ -137,7 +136,7 @@ class TextFile:
|
||||||
if line is None:
|
if line is None:
|
||||||
line = self.current_line
|
line = self.current_line
|
||||||
outmsg.append(self.filename + ", ")
|
outmsg.append(self.filename + ", ")
|
||||||
if type (line) in (ListType, TupleType):
|
if isinstance (line, (list, tuple)):
|
||||||
outmsg.append("lines %d-%d: " % tuple (line))
|
outmsg.append("lines %d-%d: " % tuple (line))
|
||||||
else:
|
else:
|
||||||
outmsg.append("line %d: " % line)
|
outmsg.append("line %d: " % line)
|
||||||
|
@ -239,7 +238,7 @@ class TextFile:
|
||||||
line = buildup_line + line
|
line = buildup_line + line
|
||||||
|
|
||||||
# careful: pay attention to line number when incrementing it
|
# careful: pay attention to line number when incrementing it
|
||||||
if type (self.current_line) is ListType:
|
if isinstance (self.current_line, list):
|
||||||
self.current_line[1] = self.current_line[1] + 1
|
self.current_line[1] = self.current_line[1] + 1
|
||||||
else:
|
else:
|
||||||
self.current_line = [self.current_line,
|
self.current_line = [self.current_line,
|
||||||
|
@ -250,7 +249,7 @@ class TextFile:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# still have to be careful about incrementing the line number!
|
# still have to be careful about incrementing the line number!
|
||||||
if type (self.current_line) is ListType:
|
if isinstance (self.current_line, list):
|
||||||
self.current_line = self.current_line[1] + 1
|
self.current_line = self.current_line[1] + 1
|
||||||
else:
|
else:
|
||||||
self.current_line = self.current_line + 1
|
self.current_line = self.current_line + 1
|
||||||
|
|
|
@ -16,7 +16,6 @@ the "typical" Unix-style command-line C compiler:
|
||||||
__revision__ = "$Id$"
|
__revision__ = "$Id$"
|
||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
from types import NoneType
|
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
|
||||||
from distutils import sysconfig
|
from distutils import sysconfig
|
||||||
|
@ -212,7 +211,7 @@ class UnixCCompiler(CCompiler):
|
||||||
|
|
||||||
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
|
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
|
||||||
libraries)
|
libraries)
|
||||||
if not isinstance(output_dir, (basestring, NoneType)):
|
if not isinstance(output_dir, (basestring, type(None))):
|
||||||
raise TypeError, "'output_dir' must be a string or None"
|
raise TypeError, "'output_dir' must be a string or None"
|
||||||
if output_dir is not None:
|
if output_dir is not None:
|
||||||
output_filename = os.path.join(output_dir, output_filename)
|
output_filename = os.path.join(output_dir, output_filename)
|
||||||
|
|
|
@ -131,14 +131,14 @@ def get_arg_text(ob):
|
||||||
arg_text = ""
|
arg_text = ""
|
||||||
if ob is not None:
|
if ob is not None:
|
||||||
arg_offset = 0
|
arg_offset = 0
|
||||||
if type(ob) in (types.ClassType, types.TypeType):
|
if isinstance(ob, type):
|
||||||
# Look for the highest __init__ in the class chain.
|
# Look for the highest __init__ in the class chain.
|
||||||
fob = _find_constructor(ob)
|
fob = _find_constructor(ob)
|
||||||
if fob is None:
|
if fob is None:
|
||||||
fob = lambda: None
|
fob = lambda: None
|
||||||
else:
|
else:
|
||||||
arg_offset = 1
|
arg_offset = 1
|
||||||
elif type(ob)==types.MethodType:
|
elif isinstace(ob, types.MethodType):
|
||||||
# bit of a hack for methods - turn it into a function
|
# bit of a hack for methods - turn it into a function
|
||||||
# but we drop the "self" param.
|
# but we drop the "self" param.
|
||||||
fob = ob.im_func
|
fob = ob.im_func
|
||||||
|
@ -146,7 +146,7 @@ def get_arg_text(ob):
|
||||||
else:
|
else:
|
||||||
fob = ob
|
fob = ob
|
||||||
# Try to build one for Python defined functions
|
# Try to build one for Python defined functions
|
||||||
if type(fob) in [types.FunctionType, types.LambdaType]:
|
if isinstance(fob, (types.FunctionType, types.LambdaType)):
|
||||||
argcount = fob.__code__.co_argcount
|
argcount = fob.__code__.co_argcount
|
||||||
real_args = fob.__code__.co_varnames[arg_offset:argcount]
|
real_args = fob.__code__.co_varnames[arg_offset:argcount]
|
||||||
defaults = fob.__defaults__ or []
|
defaults = fob.__defaults__ or []
|
||||||
|
|
|
@ -101,17 +101,14 @@ class DictTreeItem(SequenceTreeItem):
|
||||||
pass
|
pass
|
||||||
return keys
|
return keys
|
||||||
|
|
||||||
from types import *
|
|
||||||
|
|
||||||
dispatch = {
|
dispatch = {
|
||||||
IntType: AtomicObjectTreeItem,
|
int: AtomicObjectTreeItem,
|
||||||
LongType: AtomicObjectTreeItem,
|
float: AtomicObjectTreeItem,
|
||||||
FloatType: AtomicObjectTreeItem,
|
str: AtomicObjectTreeItem,
|
||||||
StringType: AtomicObjectTreeItem,
|
tuple: SequenceTreeItem,
|
||||||
TupleType: SequenceTreeItem,
|
list: SequenceTreeItem,
|
||||||
ListType: SequenceTreeItem,
|
dict: DictTreeItem,
|
||||||
DictType: DictTreeItem,
|
type: ClassTreeItem,
|
||||||
ClassType: ClassTreeItem,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def make_objecttreeitem(labeltext, object, setfunction=None):
|
def make_objecttreeitem(labeltext, object, setfunction=None):
|
||||||
|
|
|
@ -287,7 +287,7 @@ class SocketIO(object):
|
||||||
def _proxify(self, obj):
|
def _proxify(self, obj):
|
||||||
if isinstance(obj, RemoteProxy):
|
if isinstance(obj, RemoteProxy):
|
||||||
return RPCProxy(self, obj.oid)
|
return RPCProxy(self, obj.oid)
|
||||||
if isinstance(obj, types.ListType):
|
if isinstance(obj, list):
|
||||||
return map(self._proxify, obj)
|
return map(self._proxify, obj)
|
||||||
# XXX Check for other types -- not currently needed
|
# XXX Check for other types -- not currently needed
|
||||||
return obj
|
return obj
|
||||||
|
@ -574,7 +574,7 @@ def _getmethods(obj, methods):
|
||||||
attr = getattr(obj, name)
|
attr = getattr(obj, name)
|
||||||
if hasattr(attr, '__call__'):
|
if hasattr(attr, '__call__'):
|
||||||
methods[name] = 1
|
methods[name] = 1
|
||||||
if type(obj) == types.ClassType:
|
if isinstance(obj, type):
|
||||||
for super in obj.__bases__:
|
for super in obj.__bases__:
|
||||||
_getmethods(super, methods)
|
_getmethods(super, methods)
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ def isclass(object):
|
||||||
Class objects provide these attributes:
|
Class objects provide these attributes:
|
||||||
__doc__ documentation string
|
__doc__ documentation string
|
||||||
__module__ name of module in which this class was defined"""
|
__module__ name of module in which this class was defined"""
|
||||||
return isinstance(object, types.ClassType) or hasattr(object, '__bases__')
|
return isinstance(object, type) or hasattr(object, '__bases__')
|
||||||
|
|
||||||
def ismethod(object):
|
def ismethod(object):
|
||||||
"""Return true if the object is an instance method.
|
"""Return true if the object is an instance method.
|
||||||
|
|
|
@ -21,7 +21,7 @@ class ScrolledText(Text):
|
||||||
cnf = _cnfmerge((cnf, kw))
|
cnf = _cnfmerge((cnf, kw))
|
||||||
fcnf = {}
|
fcnf = {}
|
||||||
for k in cnf.keys():
|
for k in cnf.keys():
|
||||||
if type(k) == ClassType or k == 'name':
|
if isinstace(k, type) or k == 'name':
|
||||||
fcnf[k] = cnf[k]
|
fcnf[k] = cnf[k]
|
||||||
del cnf[k]
|
del cnf[k]
|
||||||
self.frame = Frame(master, **fcnf)
|
self.frame = Frame(master, **fcnf)
|
||||||
|
|
|
@ -38,7 +38,6 @@ if sys.platform == "win32":
|
||||||
import _tkinter # If this fails your Python may not be configured for Tk
|
import _tkinter # If this fails your Python may not be configured for Tk
|
||||||
tkinter = _tkinter # b/w compat for export
|
tkinter = _tkinter # b/w compat for export
|
||||||
TclError = _tkinter.TclError
|
TclError = _tkinter.TclError
|
||||||
from types import *
|
|
||||||
from Tkconstants import *
|
from Tkconstants import *
|
||||||
try:
|
try:
|
||||||
import MacOS; _MacOS = MacOS; del MacOS
|
import MacOS; _MacOS = MacOS; del MacOS
|
||||||
|
@ -61,11 +60,11 @@ try: _tkinter.deletefilehandler
|
||||||
except AttributeError: _tkinter.deletefilehandler = None
|
except AttributeError: _tkinter.deletefilehandler = None
|
||||||
|
|
||||||
|
|
||||||
def _flatten(tuple):
|
def _flatten(seq):
|
||||||
"""Internal function."""
|
"""Internal function."""
|
||||||
res = ()
|
res = ()
|
||||||
for item in tuple:
|
for item in seq:
|
||||||
if type(item) in (TupleType, ListType):
|
if isinstance(item, (tuple, list)):
|
||||||
res = res + _flatten(item)
|
res = res + _flatten(item)
|
||||||
elif item is not None:
|
elif item is not None:
|
||||||
res = res + (item,)
|
res = res + (item,)
|
||||||
|
@ -76,9 +75,9 @@ except AttributeError: pass
|
||||||
|
|
||||||
def _cnfmerge(cnfs):
|
def _cnfmerge(cnfs):
|
||||||
"""Internal function."""
|
"""Internal function."""
|
||||||
if type(cnfs) is DictionaryType:
|
if isinstance(cnfs, dict):
|
||||||
return cnfs
|
return cnfs
|
||||||
elif type(cnfs) in (NoneType, StringType):
|
elif isinstance(cnfs, (type(None), str)):
|
||||||
return cnfs
|
return cnfs
|
||||||
else:
|
else:
|
||||||
cnf = {}
|
cnf = {}
|
||||||
|
@ -867,7 +866,7 @@ class Misc:
|
||||||
data = self.tk.split(
|
data = self.tk.split(
|
||||||
self.tk.call('winfo', 'visualsavailable', self._w,
|
self.tk.call('winfo', 'visualsavailable', self._w,
|
||||||
includeids and 'includeids' or None))
|
includeids and 'includeids' or None))
|
||||||
if type(data) is StringType:
|
if isinstance(data, str):
|
||||||
data = [self.tk.split(data)]
|
data = [self.tk.split(data)]
|
||||||
return map(self.__winfo_parseitem, data)
|
return map(self.__winfo_parseitem, data)
|
||||||
def __winfo_parseitem(self, t):
|
def __winfo_parseitem(self, t):
|
||||||
|
@ -934,7 +933,7 @@ class Misc:
|
||||||
self.tk.call('bindtags', self._w, tagList)
|
self.tk.call('bindtags', self._w, tagList)
|
||||||
def _bind(self, what, sequence, func, add, needcleanup=1):
|
def _bind(self, what, sequence, func, add, needcleanup=1):
|
||||||
"""Internal function."""
|
"""Internal function."""
|
||||||
if type(func) is StringType:
|
if isinstance(func, str):
|
||||||
self.tk.call(what + (sequence, func))
|
self.tk.call(what + (sequence, func))
|
||||||
elif func:
|
elif func:
|
||||||
funcid = self._register(func, self._substitute,
|
funcid = self._register(func, self._substitute,
|
||||||
|
@ -1181,7 +1180,7 @@ class Misc:
|
||||||
self.tk.call(_flatten((self._w, cmd)))):
|
self.tk.call(_flatten((self._w, cmd)))):
|
||||||
cnf[x[0][1:]] = (x[0][1:],) + x[1:]
|
cnf[x[0][1:]] = (x[0][1:],) + x[1:]
|
||||||
return cnf
|
return cnf
|
||||||
if type(cnf) is StringType:
|
if isinstance(cnf, str):
|
||||||
x = self.tk.split(
|
x = self.tk.split(
|
||||||
self.tk.call(_flatten((self._w, cmd, '-'+cnf))))
|
self.tk.call(_flatten((self._w, cmd, '-'+cnf))))
|
||||||
return (x[0][1:],) + x[1:]
|
return (x[0][1:],) + x[1:]
|
||||||
|
@ -1262,7 +1261,7 @@ class Misc:
|
||||||
bbox = grid_bbox
|
bbox = grid_bbox
|
||||||
def _grid_configure(self, command, index, cnf, kw):
|
def _grid_configure(self, command, index, cnf, kw):
|
||||||
"""Internal function."""
|
"""Internal function."""
|
||||||
if type(cnf) is StringType and not kw:
|
if isinstance(cnf, str) and not kw:
|
||||||
if cnf[-1:] == '_':
|
if cnf[-1:] == '_':
|
||||||
cnf = cnf[:-1]
|
cnf = cnf[:-1]
|
||||||
if cnf[:1] != '-':
|
if cnf[:1] != '-':
|
||||||
|
@ -1923,7 +1922,7 @@ class BaseWidget(Misc):
|
||||||
BaseWidget._setup(self, master, cnf)
|
BaseWidget._setup(self, master, cnf)
|
||||||
classes = []
|
classes = []
|
||||||
for k in cnf.keys():
|
for k in cnf.keys():
|
||||||
if type(k) is ClassType:
|
if isinstance(k, type):
|
||||||
classes.append((k, cnf[k]))
|
classes.append((k, cnf[k]))
|
||||||
del cnf[k]
|
del cnf[k]
|
||||||
self.tk.call(
|
self.tk.call(
|
||||||
|
@ -2136,7 +2135,7 @@ class Canvas(Widget):
|
||||||
"""Internal function."""
|
"""Internal function."""
|
||||||
args = _flatten(args)
|
args = _flatten(args)
|
||||||
cnf = args[-1]
|
cnf = args[-1]
|
||||||
if type(cnf) in (DictionaryType, TupleType):
|
if isinstance(cnf, (dict, tuple)):
|
||||||
args = args[:-1]
|
args = args[:-1]
|
||||||
else:
|
else:
|
||||||
cnf = {}
|
cnf = {}
|
||||||
|
@ -3695,7 +3694,7 @@ class PanedWindow(Widget):
|
||||||
'paneconfigure', tagOrId)):
|
'paneconfigure', tagOrId)):
|
||||||
cnf[x[0][1:]] = (x[0][1:],) + x[1:]
|
cnf[x[0][1:]] = (x[0][1:],) + x[1:]
|
||||||
return cnf
|
return cnf
|
||||||
if type(cnf) == StringType and not kw:
|
if isinstance(cnf, str) and not kw:
|
||||||
x = self.tk.split(self.tk.call(
|
x = self.tk.split(self.tk.call(
|
||||||
self._w, 'paneconfigure', tagOrId, '-'+cnf))
|
self._w, 'paneconfigure', tagOrId, '-'+cnf))
|
||||||
return (x[0][1:],) + x[1:]
|
return (x[0][1:],) + x[1:]
|
||||||
|
|
|
@ -26,7 +26,7 @@ Copyright (C) 2001-2007 Vinay Sajip. All Rights Reserved.
|
||||||
To use, simply 'import logging' and log away!
|
To use, simply 'import logging' and log away!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os, types, time, cStringIO, traceback
|
import sys, os, time, cStringIO, traceback
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import codecs
|
import codecs
|
||||||
|
@ -48,6 +48,8 @@ __date__ = "16 February 2007"
|
||||||
# Miscellaneous module data
|
# Miscellaneous module data
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
_unicode = 'unicode' in dir(__builtins__)
|
||||||
|
|
||||||
#
|
#
|
||||||
# _srcfile is used when walking the stack to check when we've got the first
|
# _srcfile is used when walking the stack to check when we've got the first
|
||||||
# caller stack frame.
|
# caller stack frame.
|
||||||
|
@ -234,7 +236,7 @@ class LogRecord:
|
||||||
# 'Value is %d' instead of 'Value is 0'.
|
# 'Value is %d' instead of 'Value is 0'.
|
||||||
# For the use case of passing a dictionary, this should not be a
|
# For the use case of passing a dictionary, this should not be a
|
||||||
# problem.
|
# problem.
|
||||||
if args and (len(args) == 1) and args[0] and (type(args[0]) == types.DictType):
|
if args and (len(args) == 1) and args[0] and isinstance(args[0], dict):
|
||||||
args = args[0]
|
args = args[0]
|
||||||
self.args = args
|
self.args = args
|
||||||
self.levelname = getLevelName(level)
|
self.levelname = getLevelName(level)
|
||||||
|
@ -275,11 +277,11 @@ class LogRecord:
|
||||||
Return the message for this LogRecord after merging any user-supplied
|
Return the message for this LogRecord after merging any user-supplied
|
||||||
arguments with the message.
|
arguments with the message.
|
||||||
"""
|
"""
|
||||||
if not hasattr(types, "UnicodeType"): #if no unicode support...
|
if not _unicode: #if no unicode support...
|
||||||
msg = str(self.msg)
|
msg = str(self.msg)
|
||||||
else:
|
else:
|
||||||
msg = self.msg
|
msg = self.msg
|
||||||
if type(msg) not in (types.UnicodeType, types.StringType):
|
if not isinstance(msg, basestring):
|
||||||
try:
|
try:
|
||||||
msg = str(self.msg)
|
msg = str(self.msg)
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
|
@ -743,7 +745,7 @@ class StreamHandler(Handler):
|
||||||
try:
|
try:
|
||||||
msg = self.format(record)
|
msg = self.format(record)
|
||||||
fs = "%s\n"
|
fs = "%s\n"
|
||||||
if not hasattr(types, "UnicodeType"): #if no unicode support...
|
if not _unicode: #if no unicode support...
|
||||||
self.stream.write(fs % msg)
|
self.stream.write(fs % msg)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
@ -1053,7 +1055,7 @@ class Logger(Filterer):
|
||||||
|
|
||||||
logger.log(level, "We have a %s", "mysterious problem", exc_info=1)
|
logger.log(level, "We have a %s", "mysterious problem", exc_info=1)
|
||||||
"""
|
"""
|
||||||
if type(level) != types.IntType:
|
if not isinstance(level, int):
|
||||||
if raiseExceptions:
|
if raiseExceptions:
|
||||||
raise TypeError, "level must be an integer"
|
raise TypeError, "level must be an integer"
|
||||||
else:
|
else:
|
||||||
|
@ -1103,7 +1105,7 @@ class Logger(Filterer):
|
||||||
else:
|
else:
|
||||||
fn, lno, func = "(unknown file)", 0, "(unknown function)"
|
fn, lno, func = "(unknown file)", 0, "(unknown function)"
|
||||||
if exc_info:
|
if exc_info:
|
||||||
if type(exc_info) != types.TupleType:
|
if not isinstance(exc_info, tuple):
|
||||||
exc_info = sys.exc_info()
|
exc_info = sys.exc_info()
|
||||||
record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
|
record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
|
||||||
self.handle(record)
|
self.handle(record)
|
||||||
|
|
|
@ -27,7 +27,7 @@ Copyright (C) 2001-2004 Vinay Sajip. All Rights Reserved.
|
||||||
To use, simply 'import logging' and log away!
|
To use, simply 'import logging' and log away!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, logging, logging.handlers, socket, struct, os, traceback, types
|
import sys, logging, logging.handlers, socket, struct, os, traceback
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import thread
|
import thread
|
||||||
|
@ -289,7 +289,7 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT):
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
if type(e.args) != types.TupleType:
|
if not isinstancetype(e.args, tuple):
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
errcode = e.args[0]
|
errcode = e.args[0]
|
||||||
|
|
|
@ -27,7 +27,7 @@ Copyright (C) 2001-2007 Vinay Sajip. All Rights Reserved.
|
||||||
To use, simply 'import logging' and log away!
|
To use, simply 'import logging' and log away!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, logging, socket, types, os, struct, time, glob
|
import sys, logging, socket, os, struct, time, glob
|
||||||
try:
|
try:
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -637,7 +637,7 @@ class SysLogHandler(logging.Handler):
|
||||||
|
|
||||||
self.address = address
|
self.address = address
|
||||||
self.facility = facility
|
self.facility = facility
|
||||||
if type(address) == types.StringType:
|
if isinstance(address, str):
|
||||||
self.unixsocket = 1
|
self.unixsocket = 1
|
||||||
self._connect_unixsocket(address)
|
self._connect_unixsocket(address)
|
||||||
else:
|
else:
|
||||||
|
@ -669,9 +669,9 @@ class SysLogHandler(logging.Handler):
|
||||||
priority_names mapping dictionaries are used to convert them to
|
priority_names mapping dictionaries are used to convert them to
|
||||||
integers.
|
integers.
|
||||||
"""
|
"""
|
||||||
if type(facility) == types.StringType:
|
if isinstance(facility, str):
|
||||||
facility = self.facility_names[facility]
|
facility = self.facility_names[facility]
|
||||||
if type(priority) == types.StringType:
|
if isinstance(priority, str):
|
||||||
priority = self.priority_names[priority]
|
priority = self.priority_names[priority]
|
||||||
return (facility << 3) | priority
|
return (facility << 3) | priority
|
||||||
|
|
||||||
|
@ -738,16 +738,16 @@ class SMTPHandler(logging.Handler):
|
||||||
for the credentials argument.
|
for the credentials argument.
|
||||||
"""
|
"""
|
||||||
logging.Handler.__init__(self)
|
logging.Handler.__init__(self)
|
||||||
if type(mailhost) == types.TupleType:
|
if isinstance(mailhost, tuple):
|
||||||
self.mailhost, self.mailport = mailhost
|
self.mailhost, self.mailport = mailhost
|
||||||
else:
|
else:
|
||||||
self.mailhost, self.mailport = mailhost, None
|
self.mailhost, self.mailport = mailhost, None
|
||||||
if type(credentials) == types.TupleType:
|
if isinstance(credentials, tuple):
|
||||||
self.username, self.password = credentials
|
self.username, self.password = credentials
|
||||||
else:
|
else:
|
||||||
self.username = None
|
self.username = None
|
||||||
self.fromaddr = fromaddr
|
self.fromaddr = fromaddr
|
||||||
if type(toaddrs) == types.StringType:
|
if isinstance(toaddrs, str):
|
||||||
toaddrs = [toaddrs]
|
toaddrs = [toaddrs]
|
||||||
self.toaddrs = toaddrs
|
self.toaddrs = toaddrs
|
||||||
self.subject = subject
|
self.subject = subject
|
||||||
|
|
|
@ -4,7 +4,7 @@ This module is no longer required except for backward compatibility.
|
||||||
Objects of most types can now be created by calling the type object.
|
Objects of most types can now be created by calling the type object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from types import ClassType as classobj
|
classobj = type
|
||||||
from types import FunctionType as function
|
from types import FunctionType as function
|
||||||
from types import MethodType as instancemethod
|
from types import MethodType as instancemethod
|
||||||
from types import ModuleType as module
|
from types import ModuleType as module
|
||||||
|
|
|
@ -67,7 +67,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os
|
import sys, os
|
||||||
import types
|
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
def _repr(self):
|
def _repr(self):
|
||||||
|
@ -641,7 +640,7 @@ class Option:
|
||||||
# Python 2.1 and earlier, and is short-circuited by the
|
# Python 2.1 and earlier, and is short-circuited by the
|
||||||
# first check on modern Pythons.)
|
# first check on modern Pythons.)
|
||||||
import __builtin__
|
import __builtin__
|
||||||
if ( type(self.type) is types.TypeType or
|
if ( isinstance(self.type, type) or
|
||||||
(hasattr(self.type, "__name__") and
|
(hasattr(self.type, "__name__") and
|
||||||
getattr(__builtin__, self.type.__name__, None) is self.type) ):
|
getattr(__builtin__, self.type.__name__, None) is self.type) ):
|
||||||
self.type = self.type.__name__
|
self.type = self.type.__name__
|
||||||
|
@ -660,7 +659,7 @@ class Option:
|
||||||
if self.choices is None:
|
if self.choices is None:
|
||||||
raise OptionError(
|
raise OptionError(
|
||||||
"must supply a list of choices for type 'choice'", self)
|
"must supply a list of choices for type 'choice'", self)
|
||||||
elif type(self.choices) not in (types.TupleType, types.ListType):
|
elif not isinstance(self.choices, (tuple, list)):
|
||||||
raise OptionError(
|
raise OptionError(
|
||||||
"choices must be a list of strings ('%s' supplied)"
|
"choices must be a list of strings ('%s' supplied)"
|
||||||
% str(type(self.choices)).split("'")[1], self)
|
% str(type(self.choices)).split("'")[1], self)
|
||||||
|
@ -704,12 +703,12 @@ class Option:
|
||||||
raise OptionError(
|
raise OptionError(
|
||||||
"callback not callable: %r" % self.callback, self)
|
"callback not callable: %r" % self.callback, self)
|
||||||
if (self.callback_args is not None and
|
if (self.callback_args is not None and
|
||||||
type(self.callback_args) is not types.TupleType):
|
not isinstance(self.callback_args, tuple)):
|
||||||
raise OptionError(
|
raise OptionError(
|
||||||
"callback_args, if supplied, must be a tuple: not %r"
|
"callback_args, if supplied, must be a tuple: not %r"
|
||||||
% self.callback_args, self)
|
% self.callback_args, self)
|
||||||
if (self.callback_kwargs is not None and
|
if (self.callback_kwargs is not None and
|
||||||
type(self.callback_kwargs) is not types.DictType):
|
not isinstance(self.callback_kwargs, dict)):
|
||||||
raise OptionError(
|
raise OptionError(
|
||||||
"callback_kwargs, if supplied, must be a dict: not %r"
|
"callback_kwargs, if supplied, must be a dict: not %r"
|
||||||
% self.callback_kwargs, self)
|
% self.callback_kwargs, self)
|
||||||
|
@ -834,7 +833,7 @@ class Values:
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if isinstance(other, Values):
|
if isinstance(other, Values):
|
||||||
return self.__dict__ == other.__dict__
|
return self.__dict__ == other.__dict__
|
||||||
elif isinstance(other, types.DictType):
|
elif isinstance(other, dict):
|
||||||
return self.__dict__ == other
|
return self.__dict__ == other
|
||||||
else:
|
else:
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
|
@ -26,7 +26,7 @@ Misc variables:
|
||||||
|
|
||||||
__version__ = "$Revision$" # Code version
|
__version__ = "$Revision$" # Code version
|
||||||
|
|
||||||
from types import *
|
from types import FunctionType, BuiltinFunctionType
|
||||||
from copy_reg import dispatch_table
|
from copy_reg import dispatch_table
|
||||||
from copy_reg import _extension_registry, _inverted_registry, _extension_cache
|
from copy_reg import _extension_registry, _inverted_registry, _extension_cache
|
||||||
import marshal
|
import marshal
|
||||||
|
@ -283,7 +283,7 @@ class Pickler:
|
||||||
|
|
||||||
# Check for a class with a custom metaclass; treat as regular class
|
# Check for a class with a custom metaclass; treat as regular class
|
||||||
try:
|
try:
|
||||||
issc = issubclass(t, TypeType)
|
issc = issubclass(t, type)
|
||||||
except TypeError: # t is not a class (old Boost; see SF #502085)
|
except TypeError: # t is not a class (old Boost; see SF #502085)
|
||||||
issc = 0
|
issc = 0
|
||||||
if issc:
|
if issc:
|
||||||
|
@ -313,7 +313,7 @@ class Pickler:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Assert that reduce() returned a tuple
|
# Assert that reduce() returned a tuple
|
||||||
if type(rv) is not TupleType:
|
if not isinstance(rv, tuple):
|
||||||
raise PicklingError("%s must return string or tuple" % reduce)
|
raise PicklingError("%s must return string or tuple" % reduce)
|
||||||
|
|
||||||
# Assert that it returned an appropriately sized tuple
|
# Assert that it returned an appropriately sized tuple
|
||||||
|
@ -342,7 +342,7 @@ class Pickler:
|
||||||
# This API is called by some subclasses
|
# This API is called by some subclasses
|
||||||
|
|
||||||
# Assert that args is a tuple or None
|
# Assert that args is a tuple or None
|
||||||
if not isinstance(args, TupleType):
|
if not isinstance(args, tuple):
|
||||||
raise PicklingError("args from reduce() should be a tuple")
|
raise PicklingError("args from reduce() should be a tuple")
|
||||||
|
|
||||||
# Assert that func is callable
|
# Assert that func is callable
|
||||||
|
@ -420,7 +420,7 @@ class Pickler:
|
||||||
|
|
||||||
def save_none(self, obj):
|
def save_none(self, obj):
|
||||||
self.write(NONE)
|
self.write(NONE)
|
||||||
dispatch[NoneType] = save_none
|
dispatch[type(None)] = save_none
|
||||||
|
|
||||||
def save_bool(self, obj):
|
def save_bool(self, obj):
|
||||||
if self.proto >= 2:
|
if self.proto >= 2:
|
||||||
|
@ -452,7 +452,7 @@ class Pickler:
|
||||||
# Text pickle, or int too big to fit in signed 4-byte format.
|
# Text pickle, or int too big to fit in signed 4-byte format.
|
||||||
self.write(INT + bytes(repr(obj)) + b'\n')
|
self.write(INT + bytes(repr(obj)) + b'\n')
|
||||||
# XXX save_int is merged into save_long
|
# XXX save_int is merged into save_long
|
||||||
# dispatch[IntType] = save_int
|
# dispatch[int] = save_int
|
||||||
|
|
||||||
def save_long(self, obj, pack=struct.pack):
|
def save_long(self, obj, pack=struct.pack):
|
||||||
if self.bin:
|
if self.bin:
|
||||||
|
@ -483,14 +483,14 @@ class Pickler:
|
||||||
self.write(LONG4 + pack("<i", n) + encoded)
|
self.write(LONG4 + pack("<i", n) + encoded)
|
||||||
return
|
return
|
||||||
self.write(LONG + bytes(repr(obj)) + b'\n')
|
self.write(LONG + bytes(repr(obj)) + b'\n')
|
||||||
dispatch[LongType] = save_long
|
dispatch[int] = save_long
|
||||||
|
|
||||||
def save_float(self, obj, pack=struct.pack):
|
def save_float(self, obj, pack=struct.pack):
|
||||||
if self.bin:
|
if self.bin:
|
||||||
self.write(BINFLOAT + pack('>d', obj))
|
self.write(BINFLOAT + pack('>d', obj))
|
||||||
else:
|
else:
|
||||||
self.write(FLOAT + bytes(repr(obj)) + b'\n')
|
self.write(FLOAT + bytes(repr(obj)) + b'\n')
|
||||||
dispatch[FloatType] = save_float
|
dispatch[float] = save_float
|
||||||
|
|
||||||
def save_string(self, obj, pack=struct.pack):
|
def save_string(self, obj, pack=struct.pack):
|
||||||
if self.bin:
|
if self.bin:
|
||||||
|
@ -568,7 +568,7 @@ class Pickler:
|
||||||
self.write(TUPLE)
|
self.write(TUPLE)
|
||||||
self.memoize(obj)
|
self.memoize(obj)
|
||||||
|
|
||||||
dispatch[TupleType] = save_tuple
|
dispatch[tuple] = save_tuple
|
||||||
|
|
||||||
# save_empty_tuple() isn't used by anything in Python 2.3. However, I
|
# save_empty_tuple() isn't used by anything in Python 2.3. However, I
|
||||||
# found a Pickler subclass in Zope3 that calls it, so it's not harmless
|
# found a Pickler subclass in Zope3 that calls it, so it's not harmless
|
||||||
|
@ -587,7 +587,7 @@ class Pickler:
|
||||||
self.memoize(obj)
|
self.memoize(obj)
|
||||||
self._batch_appends(iter(obj))
|
self._batch_appends(iter(obj))
|
||||||
|
|
||||||
dispatch[ListType] = save_list
|
dispatch[list] = save_list
|
||||||
|
|
||||||
# Keep in synch with cPickle's BATCHSIZE. Nothing will break if it gets
|
# Keep in synch with cPickle's BATCHSIZE. Nothing will break if it gets
|
||||||
# out of synch, though.
|
# out of synch, though.
|
||||||
|
@ -636,8 +636,8 @@ class Pickler:
|
||||||
self.memoize(obj)
|
self.memoize(obj)
|
||||||
self._batch_setitems(iter(obj.items()))
|
self._batch_setitems(iter(obj.items()))
|
||||||
|
|
||||||
dispatch[DictionaryType] = save_dict
|
dispatch[dict] = save_dict
|
||||||
if not PyStringMap is None:
|
if PyStringMap is not None:
|
||||||
dispatch[PyStringMap] = save_dict
|
dispatch[PyStringMap] = save_dict
|
||||||
|
|
||||||
def _batch_setitems(self, items):
|
def _batch_setitems(self, items):
|
||||||
|
@ -715,10 +715,9 @@ class Pickler:
|
||||||
write(GLOBAL + bytes(module) + b'\n' + bytes(name) + b'\n')
|
write(GLOBAL + bytes(module) + b'\n' + bytes(name) + b'\n')
|
||||||
self.memoize(obj)
|
self.memoize(obj)
|
||||||
|
|
||||||
dispatch[ClassType] = save_global
|
|
||||||
dispatch[FunctionType] = save_global
|
dispatch[FunctionType] = save_global
|
||||||
dispatch[BuiltinFunctionType] = save_global
|
dispatch[BuiltinFunctionType] = save_global
|
||||||
dispatch[TypeType] = save_global
|
dispatch[type] = save_global
|
||||||
|
|
||||||
# Pickling helpers
|
# Pickling helpers
|
||||||
|
|
||||||
|
@ -1007,7 +1006,7 @@ class Unpickler:
|
||||||
del self.stack[k:]
|
del self.stack[k:]
|
||||||
instantiated = 0
|
instantiated = 0
|
||||||
if (not args and
|
if (not args and
|
||||||
type(klass) is ClassType and
|
isinstance(klass, type) and
|
||||||
not hasattr(klass, "__getinitargs__")):
|
not hasattr(klass, "__getinitargs__")):
|
||||||
value = _EmptyClass()
|
value = _EmptyClass()
|
||||||
value.__class__ = klass
|
value.__class__ = klass
|
||||||
|
|
|
@ -1531,7 +1531,7 @@ opcodes = [
|
||||||
opcode is followed by code to create setstate's argument, and then a
|
opcode is followed by code to create setstate's argument, and then a
|
||||||
BUILD opcode to apply __setstate__ to that argument.
|
BUILD opcode to apply __setstate__ to that argument.
|
||||||
|
|
||||||
If type(callable) is not ClassType, REDUCE complains unless the
|
If not isinstance(callable, type), REDUCE complains unless the
|
||||||
callable has been registered with the copy_reg module's
|
callable has been registered with the copy_reg module's
|
||||||
safe_constructors dict, or the callable has a magic
|
safe_constructors dict, or the callable has a magic
|
||||||
'__safe_for_unpickling__' attribute with a true value. I'm not sure
|
'__safe_for_unpickling__' attribute with a true value. I'm not sure
|
||||||
|
@ -1587,9 +1587,6 @@ opcodes = [
|
||||||
+ The argtuple is empty (markobject was at the top of the stack
|
+ The argtuple is empty (markobject was at the top of the stack
|
||||||
at the start).
|
at the start).
|
||||||
|
|
||||||
+ It's an old-style class object (the type of the class object is
|
|
||||||
ClassType).
|
|
||||||
|
|
||||||
+ The class object does not have a __getinitargs__ attribute.
|
+ The class object does not have a __getinitargs__ attribute.
|
||||||
|
|
||||||
then we want to create an old-style class instance without invoking
|
then we want to create an old-style class instance without invoking
|
||||||
|
|
|
@ -13,8 +13,6 @@ coerce(x, wanted_sample) coerces a python object to another python object
|
||||||
#
|
#
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
import types
|
|
||||||
from types import *
|
|
||||||
from Carbon import AE
|
from Carbon import AE
|
||||||
from Carbon.AppleEvents import *
|
from Carbon.AppleEvents import *
|
||||||
import MacOS
|
import MacOS
|
||||||
|
@ -74,7 +72,7 @@ def pack(x, forcetype = None):
|
||||||
"""Pack a python object into an AE descriptor"""
|
"""Pack a python object into an AE descriptor"""
|
||||||
|
|
||||||
if forcetype:
|
if forcetype:
|
||||||
if type(x) is StringType:
|
if isinstance(x, str):
|
||||||
return AE.AECreateDesc(forcetype, x)
|
return AE.AECreateDesc(forcetype, x)
|
||||||
else:
|
else:
|
||||||
return pack(x).AECoerceDesc(forcetype)
|
return pack(x).AECoerceDesc(forcetype)
|
||||||
|
@ -90,29 +88,29 @@ def pack(x, forcetype = None):
|
||||||
return AE.AECreateDesc('fsrf', x.data)
|
return AE.AECreateDesc('fsrf', x.data)
|
||||||
if isinstance(x, AliasType):
|
if isinstance(x, AliasType):
|
||||||
return AE.AECreateDesc('alis', x.data)
|
return AE.AECreateDesc('alis', x.data)
|
||||||
if isinstance(x, IntType):
|
if isinstance(x, int):
|
||||||
return AE.AECreateDesc('long', struct.pack('l', x))
|
return AE.AECreateDesc('long', struct.pack('l', x))
|
||||||
if isinstance(x, FloatType):
|
if isinstance(x, float):
|
||||||
return AE.AECreateDesc('doub', struct.pack('d', x))
|
return AE.AECreateDesc('doub', struct.pack('d', x))
|
||||||
if isinstance(x, StringType):
|
if isinstance(x, str):
|
||||||
return AE.AECreateDesc('TEXT', x)
|
return AE.AECreateDesc('TEXT', x)
|
||||||
if isinstance(x, UnicodeType):
|
if isinstance(x, unicode):
|
||||||
data = x.encode('utf16')
|
data = x.encode('utf16')
|
||||||
if data[:2] == '\xfe\xff':
|
if data[:2] == '\xfe\xff':
|
||||||
data = data[2:]
|
data = data[2:]
|
||||||
return AE.AECreateDesc('utxt', data)
|
return AE.AECreateDesc('utxt', data)
|
||||||
if isinstance(x, ListType):
|
if isinstance(x, list):
|
||||||
list = AE.AECreateList('', 0)
|
list = AE.AECreateList('', 0)
|
||||||
for item in x:
|
for item in x:
|
||||||
list.AEPutDesc(0, pack(item))
|
list.AEPutDesc(0, pack(item))
|
||||||
return list
|
return list
|
||||||
if isinstance(x, DictionaryType):
|
if isinstance(x, dict):
|
||||||
record = AE.AECreateList('', 1)
|
record = AE.AECreateList('', 1)
|
||||||
for key, value in x.items():
|
for key, value in x.items():
|
||||||
packkey(record, key, value)
|
packkey(record, key, value)
|
||||||
#record.AEPutParamDesc(key, pack(value))
|
#record.AEPutParamDesc(key, pack(value))
|
||||||
return record
|
return record
|
||||||
if type(x) == types.ClassType and issubclass(x, ObjectSpecifier):
|
if isinstance(x, type) and issubclass(x, ObjectSpecifier):
|
||||||
# Note: we are getting a class object here, not an instance
|
# Note: we are getting a class object here, not an instance
|
||||||
return AE.AECreateDesc('type', x.want)
|
return AE.AECreateDesc('type', x.want)
|
||||||
if hasattr(x, '__aepack__'):
|
if hasattr(x, '__aepack__'):
|
||||||
|
@ -340,7 +338,7 @@ def mkobject(dict):
|
||||||
# to __class__ is safe. Moreover, shouldn't there be a better
|
# to __class__ is safe. Moreover, shouldn't there be a better
|
||||||
# initializer for the classes in the suites?
|
# initializer for the classes in the suites?
|
||||||
def mkobjectfrommodule(dict, modulename):
|
def mkobjectfrommodule(dict, modulename):
|
||||||
if type(dict['want']) == types.ClassType and issubclass(dict['want'], ObjectSpecifier):
|
if isinstance(dict['want'], type) and issubclass(dict['want'], ObjectSpecifier):
|
||||||
# The type has already been converted to Python. Convert back:-(
|
# The type has already been converted to Python. Convert back:-(
|
||||||
classtype = dict['want']
|
classtype = dict['want']
|
||||||
dict['want'] = aetypes.mktype(classtype.want)
|
dict['want'] = aetypes.mktype(classtype.want)
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
from Carbon.AppleEvents import *
|
from Carbon.AppleEvents import *
|
||||||
import struct
|
import struct
|
||||||
from types import *
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# convoluted, since there are cyclic dependencies between this file and
|
# convoluted, since there are cyclic dependencies between this file and
|
||||||
|
@ -14,7 +13,7 @@ def pack(*args, **kwargs):
|
||||||
|
|
||||||
def nice(s):
|
def nice(s):
|
||||||
"""'nice' representation of an object"""
|
"""'nice' representation of an object"""
|
||||||
if type(s) is StringType: return repr(s)
|
if isinstance(s, str): return repr(s)
|
||||||
else: return str(s)
|
else: return str(s)
|
||||||
|
|
||||||
class Unknown:
|
class Unknown:
|
||||||
|
@ -222,7 +221,7 @@ class Logical:
|
||||||
return "Logical(%r, %r)" % (self.logc, self.term)
|
return "Logical(%r, %r)" % (self.logc, self.term)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if type(self.term) == ListType and len(self.term) == 2:
|
if isinstance(self.term, list) and len(self.term) == 2:
|
||||||
return "%s %s %s" % (nice(self.term[0]),
|
return "%s %s %s" % (nice(self.term[0]),
|
||||||
self.logc.strip(),
|
self.logc.strip(),
|
||||||
nice(self.term[1]))
|
nice(self.term[1]))
|
||||||
|
@ -481,13 +480,13 @@ class SelectableItem(ObjectSpecifier):
|
||||||
|
|
||||||
def __init__(self, want, seld, fr = None):
|
def __init__(self, want, seld, fr = None):
|
||||||
t = type(seld)
|
t = type(seld)
|
||||||
if t == StringType:
|
if isinstance(t, str):
|
||||||
form = 'name'
|
form = 'name'
|
||||||
elif IsRange(seld):
|
elif IsRange(seld):
|
||||||
form = 'rang'
|
form = 'rang'
|
||||||
elif IsComparison(seld) or IsLogical(seld):
|
elif IsComparison(seld) or IsLogical(seld):
|
||||||
form = 'test'
|
form = 'test'
|
||||||
elif t == TupleType:
|
elif isinstance(t, tuple):
|
||||||
# Breakout: specify both form and seld in a tuple
|
# Breakout: specify both form and seld in a tuple
|
||||||
# (if you want ID or rele or somesuch)
|
# (if you want ID or rele or somesuch)
|
||||||
form, seld = seld
|
form, seld = seld
|
||||||
|
@ -513,7 +512,7 @@ class ComponentItem(SelectableItem):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
seld = self.seld
|
seld = self.seld
|
||||||
if type(seld) == StringType:
|
if isinstance(seld, str):
|
||||||
ss = repr(seld)
|
ss = repr(seld)
|
||||||
elif IsRange(seld):
|
elif IsRange(seld):
|
||||||
start, stop = seld.start, seld.stop
|
start, stop = seld.start, seld.stop
|
||||||
|
|
|
@ -279,9 +279,9 @@ def decode(data, verbose=None):
|
||||||
|
|
||||||
def simplify(item):
|
def simplify(item):
|
||||||
"""Recursively replace singleton tuples by their constituent item"""
|
"""Recursively replace singleton tuples by their constituent item"""
|
||||||
if type(item) is types.ListType:
|
if isinstance(item, list):
|
||||||
return map(simplify, item)
|
return map(simplify, item)
|
||||||
elif type(item) == types.TupleType and len(item) == 2:
|
elif isinstance(item, tuple) and len(item) == 2:
|
||||||
return simplify(item[1])
|
return simplify(item[1])
|
||||||
else:
|
else:
|
||||||
return item
|
return item
|
||||||
|
@ -352,7 +352,7 @@ def alt_generic(what, f, *args):
|
||||||
def generic(what, f, *args):
|
def generic(what, f, *args):
|
||||||
if type(what) == types.FunctionType:
|
if type(what) == types.FunctionType:
|
||||||
return what(f, *args)
|
return what(f, *args)
|
||||||
if type(what) == types.ListType:
|
if isinstance(what, list):
|
||||||
record = []
|
record = []
|
||||||
for thing in what:
|
for thing in what:
|
||||||
item = generic(thing[:1], f, *thing[1:])
|
item = generic(thing[:1], f, *thing[1:])
|
||||||
|
|
|
@ -101,7 +101,7 @@ class SubPattern:
|
||||||
self.width = None
|
self.width = None
|
||||||
def dump(self, level=0):
|
def dump(self, level=0):
|
||||||
nl = 1
|
nl = 1
|
||||||
seqtypes = type(()), type([])
|
seqtypes = (tuple, list)
|
||||||
for op, av in self.data:
|
for op, av in self.data:
|
||||||
print(level*" " + op, end=' '); nl = 0
|
print(level*" " + op, end=' '); nl = 0
|
||||||
if op == "in":
|
if op == "in":
|
||||||
|
@ -117,7 +117,7 @@ class SubPattern:
|
||||||
print(level*" " + "or")
|
print(level*" " + "or")
|
||||||
a.dump(level+1); nl = 1
|
a.dump(level+1); nl = 1
|
||||||
i = i + 1
|
i = i + 1
|
||||||
elif type(av) in seqtypes:
|
elif isinstance(av, seqtypes):
|
||||||
for a in av:
|
for a in av:
|
||||||
if isinstance(a, SubPattern):
|
if isinstance(a, SubPattern):
|
||||||
if not nl: print()
|
if not nl: print()
|
||||||
|
@ -709,7 +709,7 @@ def parse_template(source, pattern):
|
||||||
else:
|
else:
|
||||||
pappend((LITERAL, literal))
|
pappend((LITERAL, literal))
|
||||||
sep = source[:0]
|
sep = source[:0]
|
||||||
if type(sep) is type(""):
|
if isinstance(sep, str):
|
||||||
makechar = chr
|
makechar = chr
|
||||||
else:
|
else:
|
||||||
makechar = chr
|
makechar = chr
|
||||||
|
|
|
@ -4103,7 +4103,8 @@ def notimplemented():
|
||||||
N1 = sys.maxint + 1 # might trigger OverflowErrors instead of TypeErrors
|
N1 = sys.maxint + 1 # might trigger OverflowErrors instead of TypeErrors
|
||||||
N2 = sys.maxint # if sizeof(int) < sizeof(long), might trigger
|
N2 = sys.maxint # if sizeof(int) < sizeof(long), might trigger
|
||||||
# ValueErrors instead of TypeErrors
|
# ValueErrors instead of TypeErrors
|
||||||
for metaclass in [type, types.ClassType]:
|
if 1:
|
||||||
|
metaclass = type
|
||||||
for name, expr, iexpr in [
|
for name, expr, iexpr in [
|
||||||
('__add__', 'x + y', 'x += y'),
|
('__add__', 'x + y', 'x += y'),
|
||||||
('__sub__', 'x - y', 'x -= y'),
|
('__sub__', 'x - y', 'x -= y'),
|
||||||
|
|
|
@ -15,7 +15,7 @@ class TestIsInstanceExceptions(unittest.TestCase):
|
||||||
# (leading to an "undetected error" in the debug build). Set up is,
|
# (leading to an "undetected error" in the debug build). Set up is,
|
||||||
# isinstance(inst, cls) where:
|
# isinstance(inst, cls) where:
|
||||||
#
|
#
|
||||||
# - cls isn't a ClassType, a TypeType, or a TupleType
|
# - cls isn't a a type, or a tuple
|
||||||
# - cls has a __bases__ attribute
|
# - cls has a __bases__ attribute
|
||||||
# - inst has a __class__ attribute
|
# - inst has a __class__ attribute
|
||||||
# - inst.__class__ as no __bases__ attribute
|
# - inst.__class__ as no __bases__ attribute
|
||||||
|
|
|
@ -25,7 +25,7 @@ Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import select
|
import select
|
||||||
import os, sys, struct, types, pickle, cStringIO
|
import os, sys, struct, pickle, cStringIO
|
||||||
import socket, tempfile, threading, time
|
import socket, tempfile, threading, time
|
||||||
import logging, logging.handlers, logging.config
|
import logging, logging.handlers, logging.config
|
||||||
from test.test_support import run_with_locale
|
from test.test_support import run_with_locale
|
||||||
|
|
|
@ -12,7 +12,6 @@ import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import copy
|
import copy
|
||||||
import types
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
@ -171,7 +170,7 @@ and kwargs %(kwargs)r
|
||||||
|
|
||||||
except InterceptedError as err:
|
except InterceptedError as err:
|
||||||
self.assert_(
|
self.assert_(
|
||||||
type(output) is types.StringType,
|
isinstance(output, str),
|
||||||
"expected output to be an ordinary string, not %r"
|
"expected output to be an ordinary string, not %r"
|
||||||
% type(output))
|
% type(output))
|
||||||
|
|
||||||
|
@ -432,18 +431,12 @@ class TestTypeAliases(BaseTest):
|
||||||
self.parser.add_option("-s", type="str")
|
self.parser.add_option("-s", type="str")
|
||||||
self.assertEquals(self.parser.get_option("-s").type, "string")
|
self.assertEquals(self.parser.get_option("-s").type, "string")
|
||||||
|
|
||||||
def test_new_type_object(self):
|
def test_type_object(self):
|
||||||
self.parser.add_option("-s", type=str)
|
self.parser.add_option("-s", type=str)
|
||||||
self.assertEquals(self.parser.get_option("-s").type, "string")
|
self.assertEquals(self.parser.get_option("-s").type, "string")
|
||||||
self.parser.add_option("-x", type=int)
|
self.parser.add_option("-x", type=int)
|
||||||
self.assertEquals(self.parser.get_option("-x").type, "int")
|
self.assertEquals(self.parser.get_option("-x").type, "int")
|
||||||
|
|
||||||
def test_old_type_object(self):
|
|
||||||
self.parser.add_option("-s", type=types.StringType)
|
|
||||||
self.assertEquals(self.parser.get_option("-s").type, "string")
|
|
||||||
self.parser.add_option("-x", type=types.IntType)
|
|
||||||
self.assertEquals(self.parser.get_option("-x").type, "int")
|
|
||||||
|
|
||||||
|
|
||||||
# Custom type for testing processing of default values.
|
# Custom type for testing processing of default values.
|
||||||
_time_units = { 's' : 1, 'm' : 60, 'h' : 60*60, 'd' : 60*60*24 }
|
_time_units = { 's' : 1, 'm' : 60, 'h' : 60*60, 'd' : 60*60*24 }
|
||||||
|
@ -1470,7 +1463,7 @@ class TestHelp(BaseTest):
|
||||||
os.environ['COLUMNS'] = orig_columns
|
os.environ['COLUMNS'] = orig_columns
|
||||||
|
|
||||||
def assertHelpEquals(self, expected_output):
|
def assertHelpEquals(self, expected_output):
|
||||||
if type(expected_output) is types.UnicodeType:
|
if isinstance(expected_output, unicode):
|
||||||
encoding = self.parser._get_encoding(sys.stdout)
|
encoding = self.parser._get_encoding(sys.stdout)
|
||||||
expected_output = expected_output.encode(encoding, "replace")
|
expected_output = expected_output.encode(encoding, "replace")
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
'''
|
'''
|
||||||
from test.test_support import run_unittest
|
from test.test_support import run_unittest
|
||||||
import unittest, sys
|
import unittest, sys
|
||||||
from types import ClassType, FunctionType, MethodType, BuiltinFunctionType
|
from types import FunctionType, MethodType, BuiltinFunctionType
|
||||||
import pyclbr
|
import pyclbr
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ class PyclbrTest(TestCase):
|
||||||
continue # skip functions that came from somewhere else
|
continue # skip functions that came from somewhere else
|
||||||
self.assertEquals(py_item.__module__, value.module)
|
self.assertEquals(py_item.__module__, value.module)
|
||||||
else:
|
else:
|
||||||
self.failUnless(isinstance(py_item, (ClassType, type)))
|
self.failUnless(isinstance(py_item, type))
|
||||||
if py_item.__module__ != moduleName:
|
if py_item.__module__ != moduleName:
|
||||||
continue # skip classes that came from somewhere else
|
continue # skip classes that came from somewhere else
|
||||||
|
|
||||||
|
@ -133,14 +133,14 @@ class PyclbrTest(TestCase):
|
||||||
|
|
||||||
# Now check for missing stuff.
|
# Now check for missing stuff.
|
||||||
def defined_in(item, module):
|
def defined_in(item, module):
|
||||||
if isinstance(item, ClassType):
|
if isinstance(item, type):
|
||||||
return item.__module__ == module.__name__
|
return item.__module__ == module.__name__
|
||||||
if isinstance(item, FunctionType):
|
if isinstance(item, FunctionType):
|
||||||
return item.__globals__ is module.__dict__
|
return item.__globals__ is module.__dict__
|
||||||
return False
|
return False
|
||||||
for name in dir(module):
|
for name in dir(module):
|
||||||
item = getattr(module, name)
|
item = getattr(module, name)
|
||||||
if isinstance(item, (ClassType, FunctionType)):
|
if isinstance(item, (type, FunctionType)):
|
||||||
if defined_in(item, module):
|
if defined_in(item, module):
|
||||||
self.assertHaskey(dict, name, ignore)
|
self.assertHaskey(dict, name, ignore)
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ GeneratorType = type(_g())
|
||||||
|
|
||||||
class _C:
|
class _C:
|
||||||
def _m(self): pass
|
def _m(self): pass
|
||||||
ClassType = type(_C)
|
ClassType = type
|
||||||
UnboundMethodType = type(_C._m) # Same as MethodType
|
UnboundMethodType = type(_C._m) # Same as MethodType
|
||||||
MethodType = type(_C()._m)
|
MethodType = type(_C()._m)
|
||||||
|
|
||||||
|
|
|
@ -412,8 +412,7 @@ class TestSuite:
|
||||||
# sanity checks
|
# sanity checks
|
||||||
if not hasattr(test, '__call__'):
|
if not hasattr(test, '__call__'):
|
||||||
raise TypeError("the test to add must be callable")
|
raise TypeError("the test to add must be callable")
|
||||||
if (isinstance(test, (type, types.ClassType)) and
|
if isinstance(test, type) and issubclass(test, (TestCase, TestSuite)):
|
||||||
issubclass(test, (TestCase, TestSuite))):
|
|
||||||
raise TypeError("TestCases and TestSuites must be instantiated "
|
raise TypeError("TestCases and TestSuites must be instantiated "
|
||||||
"before passing them to addTest()")
|
"before passing them to addTest()")
|
||||||
self._tests.append(test)
|
self._tests.append(test)
|
||||||
|
@ -525,8 +524,7 @@ class TestLoader:
|
||||||
tests = []
|
tests = []
|
||||||
for name in dir(module):
|
for name in dir(module):
|
||||||
obj = getattr(module, name)
|
obj = getattr(module, name)
|
||||||
if (isinstance(obj, (type, types.ClassType)) and
|
if isinstance(obj, type) and issubclass(obj, TestCase):
|
||||||
issubclass(obj, TestCase)):
|
|
||||||
tests.append(self.loadTestsFromTestCase(obj))
|
tests.append(self.loadTestsFromTestCase(obj))
|
||||||
return self.suiteClass(tests)
|
return self.suiteClass(tests)
|
||||||
|
|
||||||
|
@ -556,11 +554,10 @@ class TestLoader:
|
||||||
|
|
||||||
if type(obj) == types.ModuleType:
|
if type(obj) == types.ModuleType:
|
||||||
return self.loadTestsFromModule(obj)
|
return self.loadTestsFromModule(obj)
|
||||||
elif (isinstance(obj, (type, types.ClassType)) and
|
elif isinstance(obj, type) and issubclass(obj, TestCase):
|
||||||
issubclass(obj, TestCase)):
|
|
||||||
return self.loadTestsFromTestCase(obj)
|
return self.loadTestsFromTestCase(obj)
|
||||||
elif (type(obj) == types.UnboundMethodType and
|
elif (isinstance(obj, types.UnboundMethodType) and
|
||||||
isinstance(parent, (type, types.ClassType)) and
|
isinstance(parent, type) and
|
||||||
issubclass(parent, TestCase)):
|
issubclass(parent, TestCase)):
|
||||||
return TestSuite([parent(obj.__name__)])
|
return TestSuite([parent(obj.__name__)])
|
||||||
elif isinstance(obj, TestSuite):
|
elif isinstance(obj, TestSuite):
|
||||||
|
@ -816,7 +813,7 @@ Examples:
|
||||||
self.module)
|
self.module)
|
||||||
|
|
||||||
def runTests(self):
|
def runTests(self):
|
||||||
if isinstance(self.testRunner, (type, types.ClassType)):
|
if isinstance(self.testRunner, type):
|
||||||
try:
|
try:
|
||||||
testRunner = self.testRunner(verbosity=self.verbosity)
|
testRunner = self.testRunner(verbosity=self.verbosity)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
|
|
@ -428,9 +428,8 @@ def build_opener(*handlers):
|
||||||
If any of the handlers passed as arguments are subclasses of the
|
If any of the handlers passed as arguments are subclasses of the
|
||||||
default handlers, the default handlers will not be used.
|
default handlers, the default handlers will not be used.
|
||||||
"""
|
"""
|
||||||
import types
|
|
||||||
def isclass(obj):
|
def isclass(obj):
|
||||||
return isinstance(obj, types.ClassType) or hasattr(obj, "__bases__")
|
return isinstance(obj, type) or hasattr(obj, "__bases__")
|
||||||
|
|
||||||
opener = OpenerDirector()
|
opener = OpenerDirector()
|
||||||
default_classes = [ProxyHandler, UnknownHandler, HTTPHandler,
|
default_classes = [ProxyHandler, UnknownHandler, HTTPHandler,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# Note: function level imports should *not* be used
|
# Note: function level imports should *not* be used
|
||||||
# in this module as it may cause import lock deadlock.
|
# in this module as it may cause import lock deadlock.
|
||||||
# See bug 683658.
|
# See bug 683658.
|
||||||
import sys, types
|
import sys
|
||||||
import linecache
|
import linecache
|
||||||
|
|
||||||
__all__ = ["warn", "showwarning", "formatwarning", "filterwarnings",
|
__all__ = ["warn", "showwarning", "formatwarning", "filterwarnings",
|
||||||
|
@ -151,8 +151,7 @@ def filterwarnings(action, message="", category=Warning, module="", lineno=0,
|
||||||
assert action in ("error", "ignore", "always", "default", "module",
|
assert action in ("error", "ignore", "always", "default", "module",
|
||||||
"once"), "invalid action: %r" % (action,)
|
"once"), "invalid action: %r" % (action,)
|
||||||
assert isinstance(message, basestring), "message must be a string"
|
assert isinstance(message, basestring), "message must be a string"
|
||||||
assert isinstance(category, (type, types.ClassType)), \
|
assert isinstance(category, type), "category must be a class"
|
||||||
"category must be a class"
|
|
||||||
assert issubclass(category, Warning), "category must be a Warning subclass"
|
assert issubclass(category, Warning), "category must be a Warning subclass"
|
||||||
assert isinstance(module, basestring), "module must be a string"
|
assert isinstance(module, basestring), "module must be a string"
|
||||||
assert isinstance(lineno, int) and lineno >= 0, \
|
assert isinstance(lineno, int) and lineno >= 0, \
|
||||||
|
|
|
@ -5,8 +5,6 @@ so portions are Copyright (C) 2001,2002 Python Software Foundation, and were
|
||||||
written by Barry Warsaw.
|
written by Barry Warsaw.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from types import ListType, TupleType
|
|
||||||
|
|
||||||
# Regular expression that matches `special' characters in parameters, the
|
# Regular expression that matches `special' characters in parameters, the
|
||||||
# existance of which force quoting of the parameter value.
|
# existance of which force quoting of the parameter value.
|
||||||
import re
|
import re
|
||||||
|
@ -44,7 +42,7 @@ class Headers:
|
||||||
"""Manage a collection of HTTP response headers"""
|
"""Manage a collection of HTTP response headers"""
|
||||||
|
|
||||||
def __init__(self,headers):
|
def __init__(self,headers):
|
||||||
if type(headers) is not ListType:
|
if not isinstance(headers, list):
|
||||||
raise TypeError("Headers must be a list of name/value tuples")
|
raise TypeError("Headers must be a list of name/value tuples")
|
||||||
self._headers = headers
|
self._headers = headers
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,6 @@ __all__ = ['validator']
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from types import DictType, StringType, TupleType, ListType
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
header_re = re.compile(r'^[a-zA-Z][a-zA-Z0-9\-_]*$')
|
header_re = re.compile(r'^[a-zA-Z][a-zA-Z0-9\-_]*$')
|
||||||
|
@ -191,20 +190,20 @@ class InputWrapper:
|
||||||
def read(self, *args):
|
def read(self, *args):
|
||||||
assert_(len(args) <= 1)
|
assert_(len(args) <= 1)
|
||||||
v = self.input.read(*args)
|
v = self.input.read(*args)
|
||||||
assert_(type(v) is type(""))
|
assert_(isinstance(v, str))
|
||||||
return v
|
return v
|
||||||
|
|
||||||
def readline(self):
|
def readline(self):
|
||||||
v = self.input.readline()
|
v = self.input.readline()
|
||||||
assert_(type(v) is type(""))
|
assert_(isinstance(v, str))
|
||||||
return v
|
return v
|
||||||
|
|
||||||
def readlines(self, *args):
|
def readlines(self, *args):
|
||||||
assert_(len(args) <= 1)
|
assert_(len(args) <= 1)
|
||||||
lines = self.input.readlines(*args)
|
lines = self.input.readlines(*args)
|
||||||
assert_(type(lines) is type([]))
|
assert_(isinstance(lines, list))
|
||||||
for line in lines:
|
for line in lines:
|
||||||
assert_(type(line) is type(""))
|
assert_(isinstance(line, str))
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
|
@ -223,7 +222,7 @@ class ErrorWrapper:
|
||||||
self.errors = wsgi_errors
|
self.errors = wsgi_errors
|
||||||
|
|
||||||
def write(self, s):
|
def write(self, s):
|
||||||
assert_(type(s) is type(""))
|
assert_(isinstance(s, str))
|
||||||
self.errors.write(s)
|
self.errors.write(s)
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
|
@ -242,7 +241,7 @@ class WriteWrapper:
|
||||||
self.writer = wsgi_writer
|
self.writer = wsgi_writer
|
||||||
|
|
||||||
def __call__(self, s):
|
def __call__(self, s):
|
||||||
assert_(type(s) is type(""))
|
assert_(isinstance(s, str))
|
||||||
self.writer(s)
|
self.writer(s)
|
||||||
|
|
||||||
class PartialIteratorWrapper:
|
class PartialIteratorWrapper:
|
||||||
|
@ -288,7 +287,7 @@ class IteratorWrapper:
|
||||||
"Iterator garbage collected without being closed")
|
"Iterator garbage collected without being closed")
|
||||||
|
|
||||||
def check_environ(environ):
|
def check_environ(environ):
|
||||||
assert_(type(environ) is DictType,
|
assert_(isinstance(environ, dict),
|
||||||
"Environment is not of the right type: %r (environment: %r)"
|
"Environment is not of the right type: %r (environment: %r)"
|
||||||
% (type(environ), environ))
|
% (type(environ), environ))
|
||||||
|
|
||||||
|
@ -315,11 +314,11 @@ def check_environ(environ):
|
||||||
if '.' in key:
|
if '.' in key:
|
||||||
# Extension, we don't care about its type
|
# Extension, we don't care about its type
|
||||||
continue
|
continue
|
||||||
assert_(type(environ[key]) is StringType,
|
assert_(isinstance(environ[key], str),
|
||||||
"Environmental variable %s is not a string: %r (value: %r)"
|
"Environmental variable %s is not a string: %r (value: %r)"
|
||||||
% (key, type(environ[key]), environ[key]))
|
% (key, type(environ[key]), environ[key]))
|
||||||
|
|
||||||
assert_(type(environ['wsgi.version']) is TupleType,
|
assert_(isinstance(environ['wsgi.version'], tuple),
|
||||||
"wsgi.version should be a tuple (%r)" % (environ['wsgi.version'],))
|
"wsgi.version should be a tuple (%r)" % (environ['wsgi.version'],))
|
||||||
assert_(environ['wsgi.url_scheme'] in ('http', 'https'),
|
assert_(environ['wsgi.url_scheme'] in ('http', 'https'),
|
||||||
"wsgi.url_scheme unknown: %r" % environ['wsgi.url_scheme'])
|
"wsgi.url_scheme unknown: %r" % environ['wsgi.url_scheme'])
|
||||||
|
@ -365,7 +364,7 @@ def check_errors(wsgi_errors):
|
||||||
% (wsgi_errors, attr))
|
% (wsgi_errors, attr))
|
||||||
|
|
||||||
def check_status(status):
|
def check_status(status):
|
||||||
assert_(type(status) is StringType,
|
assert_(isinstance(status, str),
|
||||||
"Status must be a string (not %r)" % status)
|
"Status must be a string (not %r)" % status)
|
||||||
# Implicitly check that we can turn it into an integer:
|
# Implicitly check that we can turn it into an integer:
|
||||||
status_code = status.split(None, 1)[0]
|
status_code = status.split(None, 1)[0]
|
||||||
|
@ -380,12 +379,12 @@ def check_status(status):
|
||||||
% status, WSGIWarning)
|
% status, WSGIWarning)
|
||||||
|
|
||||||
def check_headers(headers):
|
def check_headers(headers):
|
||||||
assert_(type(headers) is ListType,
|
assert_(isinstance(headers, list),
|
||||||
"Headers (%r) must be of type list: %r"
|
"Headers (%r) must be of type list: %r"
|
||||||
% (headers, type(headers)))
|
% (headers, type(headers)))
|
||||||
header_names = {}
|
header_names = {}
|
||||||
for item in headers:
|
for item in headers:
|
||||||
assert_(type(item) is TupleType,
|
assert_(isinstance(item, tuple),
|
||||||
"Individual headers (%r) must be of type tuple: %r"
|
"Individual headers (%r) must be of type tuple: %r"
|
||||||
% (item, type(item)))
|
% (item, type(item)))
|
||||||
assert_(len(item) == 2)
|
assert_(len(item) == 2)
|
||||||
|
@ -419,7 +418,7 @@ def check_content_type(status, headers):
|
||||||
assert_(0, "No Content-Type header found in headers (%s)" % headers)
|
assert_(0, "No Content-Type header found in headers (%s)" % headers)
|
||||||
|
|
||||||
def check_exc_info(exc_info):
|
def check_exc_info(exc_info):
|
||||||
assert_(exc_info is None or type(exc_info) is type(()),
|
assert_(exc_info is None or isinstance(exc_info, tuple),
|
||||||
"exc_info (%r) is not a tuple: %r" % (exc_info, type(exc_info)))
|
"exc_info (%r) is not a tuple: %r" % (exc_info, type(exc_info)))
|
||||||
# More exc_info checks?
|
# More exc_info checks?
|
||||||
|
|
||||||
|
|
|
@ -3,18 +3,10 @@ A library of useful helper classes to the SAX classes, for the
|
||||||
convenience of application and driver writers.
|
convenience of application and driver writers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os, urlparse, urllib, types
|
import os, urlparse, urllib
|
||||||
from . import handler
|
from . import handler
|
||||||
from . import xmlreader
|
from . import xmlreader
|
||||||
|
|
||||||
try:
|
|
||||||
_StringTypes = [types.StringType, types.UnicodeType]
|
|
||||||
except AttributeError:
|
|
||||||
try:
|
|
||||||
_StringTypes = [types.StringType]
|
|
||||||
except AttributeError:
|
|
||||||
_StringTypes = [str]
|
|
||||||
|
|
||||||
# See whether the xmlcharrefreplace error handler is
|
# See whether the xmlcharrefreplace error handler is
|
||||||
# supported
|
# supported
|
||||||
try:
|
try:
|
||||||
|
@ -280,7 +272,7 @@ def prepare_input_source(source, base = ""):
|
||||||
"""This function takes an InputSource and an optional base URL and
|
"""This function takes an InputSource and an optional base URL and
|
||||||
returns a fully resolved InputSource object ready for reading."""
|
returns a fully resolved InputSource object ready for reading."""
|
||||||
|
|
||||||
if type(source) in _StringTypes:
|
if isinstance(source, basestring):
|
||||||
source = xmlreader.InputSource(source)
|
source = xmlreader.InputSource(source)
|
||||||
elif hasattr(source, "read"):
|
elif hasattr(source, "read"):
|
||||||
f = source
|
f = source
|
||||||
|
|
|
@ -138,8 +138,6 @@ Exported functions:
|
||||||
|
|
||||||
import re, time, operator
|
import re, time, operator
|
||||||
|
|
||||||
from types import *
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Internal stuff
|
# Internal stuff
|
||||||
|
|
||||||
|
@ -306,7 +304,7 @@ class DateTime:
|
||||||
today = datetime.datetime.now().strftime("%Y%m%d")
|
today = datetime.datetime.now().strftime("%Y%m%d")
|
||||||
self.value = value.strftime(today+"T%H:%M:%S")
|
self.value = value.strftime(today+"T%H:%M:%S")
|
||||||
return
|
return
|
||||||
if not isinstance(value, (TupleType, time.struct_time)):
|
if not isinstance(value, (tuple, time.struct_time)):
|
||||||
if value == 0:
|
if value == 0:
|
||||||
value = time.time()
|
value = time.time()
|
||||||
value = time.localtime(value)
|
value = time.localtime(value)
|
||||||
|
@ -580,7 +578,7 @@ class Marshaller:
|
||||||
if not self.allow_none:
|
if not self.allow_none:
|
||||||
raise TypeError, "cannot marshal None unless allow_none is enabled"
|
raise TypeError, "cannot marshal None unless allow_none is enabled"
|
||||||
write("<value><nil/></value>")
|
write("<value><nil/></value>")
|
||||||
dispatch[NoneType] = dump_nil
|
dispatch[type(None)] = dump_nil
|
||||||
|
|
||||||
def dump_int(self, value, write):
|
def dump_int(self, value, write):
|
||||||
# in case ints are > 32 bits
|
# in case ints are > 32 bits
|
||||||
|
@ -589,7 +587,7 @@ class Marshaller:
|
||||||
write("<value><int>")
|
write("<value><int>")
|
||||||
write(str(value))
|
write(str(value))
|
||||||
write("</int></value>\n")
|
write("</int></value>\n")
|
||||||
dispatch[IntType] = dump_int
|
#dispatch[int] = dump_int
|
||||||
|
|
||||||
if _bool_is_builtin:
|
if _bool_is_builtin:
|
||||||
def dump_bool(self, value, write):
|
def dump_bool(self, value, write):
|
||||||
|
@ -604,13 +602,13 @@ class Marshaller:
|
||||||
write("<value><int>")
|
write("<value><int>")
|
||||||
write(str(int(value)))
|
write(str(int(value)))
|
||||||
write("</int></value>\n")
|
write("</int></value>\n")
|
||||||
dispatch[LongType] = dump_long
|
dispatch[int] = dump_long
|
||||||
|
|
||||||
def dump_double(self, value, write):
|
def dump_double(self, value, write):
|
||||||
write("<value><double>")
|
write("<value><double>")
|
||||||
write(repr(value))
|
write(repr(value))
|
||||||
write("</double></value>\n")
|
write("</double></value>\n")
|
||||||
dispatch[FloatType] = dump_double
|
dispatch[float] = dump_double
|
||||||
|
|
||||||
def dump_string(self, value, write, escape=escape):
|
def dump_string(self, value, write, escape=escape):
|
||||||
write("<value><string>")
|
write("<value><string>")
|
||||||
|
@ -636,8 +634,8 @@ class Marshaller:
|
||||||
dump(v, write)
|
dump(v, write)
|
||||||
write("</data></array></value>\n")
|
write("</data></array></value>\n")
|
||||||
del self.memo[i]
|
del self.memo[i]
|
||||||
dispatch[TupleType] = dump_array
|
dispatch[tuple] = dump_array
|
||||||
dispatch[ListType] = dump_array
|
dispatch[list] = dump_array
|
||||||
|
|
||||||
def dump_struct(self, value, write, escape=escape):
|
def dump_struct(self, value, write, escape=escape):
|
||||||
i = id(value)
|
i = id(value)
|
||||||
|
@ -657,7 +655,7 @@ class Marshaller:
|
||||||
write("</member>\n")
|
write("</member>\n")
|
||||||
write("</struct></value>\n")
|
write("</struct></value>\n")
|
||||||
del self.memo[i]
|
del self.memo[i]
|
||||||
dispatch[DictType] = dump_struct
|
dispatch[dict] = dump_struct
|
||||||
|
|
||||||
if datetime:
|
if datetime:
|
||||||
def dump_datetime(self, value, write):
|
def dump_datetime(self, value, write):
|
||||||
|
@ -1005,12 +1003,10 @@ def dumps(params, methodname=None, methodresponse=None, encoding=None,
|
||||||
where necessary.
|
where necessary.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert isinstance(params, TupleType) or isinstance(params, Fault),\
|
assert isinstance(params, (tuple, Fault)), "argument must be tuple or Fault instance"
|
||||||
"argument must be tuple or Fault instance"
|
|
||||||
|
|
||||||
if isinstance(params, Fault):
|
if isinstance(params, Fault):
|
||||||
methodresponse = 1
|
methodresponse = 1
|
||||||
elif methodresponse and isinstance(params, TupleType):
|
elif methodresponse and isinstance(params, tuple):
|
||||||
assert len(params) == 1, "response tuple must be a singleton"
|
assert len(params) == 1, "response tuple must be a singleton"
|
||||||
|
|
||||||
if not encoding:
|
if not encoding:
|
||||||
|
@ -1166,7 +1162,7 @@ class Transport:
|
||||||
def get_host_info(self, host):
|
def get_host_info(self, host):
|
||||||
|
|
||||||
x509 = {}
|
x509 = {}
|
||||||
if isinstance(host, TupleType):
|
if isinstance(host, tuple):
|
||||||
host, x509 = host
|
host, x509 = host
|
||||||
|
|
||||||
import urllib
|
import urllib
|
||||||
|
@ -1216,7 +1212,7 @@ class Transport:
|
||||||
host, extra_headers, x509 = self.get_host_info(host)
|
host, extra_headers, x509 = self.get_host_info(host)
|
||||||
connection.putheader("Host", host)
|
connection.putheader("Host", host)
|
||||||
if extra_headers:
|
if extra_headers:
|
||||||
if isinstance(extra_headers, DictType):
|
if isinstance(extra_headers, dict):
|
||||||
extra_headers = extra_headers.items()
|
extra_headers = extra_headers.items()
|
||||||
for key, value in extra_headers:
|
for key, value in extra_headers:
|
||||||
connection.putheader(key, value)
|
connection.putheader(key, value)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""pyversioncheck - Module to help with checking versions"""
|
"""pyversioncheck - Module to help with checking versions"""
|
||||||
import types
|
|
||||||
import rfc822
|
import rfc822
|
||||||
import urllib
|
import urllib
|
||||||
import sys
|
import sys
|
||||||
|
@ -35,7 +34,7 @@ def versioncheck(package, url, version, verbose=0):
|
||||||
def checkonly(package, url, version, verbose=0):
|
def checkonly(package, url, version, verbose=0):
|
||||||
if verbose >= VERBOSE_EACHFILE:
|
if verbose >= VERBOSE_EACHFILE:
|
||||||
print '%s:'%package
|
print '%s:'%package
|
||||||
if type(url) == types.StringType:
|
if isinstance(url, str):
|
||||||
ok, newversion, fp = _check1version(package, url, version, verbose)
|
ok, newversion, fp = _check1version(package, url, version, verbose)
|
||||||
else:
|
else:
|
||||||
for u in url:
|
for u in url:
|
||||||
|
|
Loading…
Reference in New Issue