import pydoc
import inspect
-import types
import re
import sys
else:
argspec = '(...)'
- if isinstance(object, types.TupleType):
+ if isinstance(object, tuple):
argspec = object[0] or argspec
docstring = object[1] or ""
else:
"""
import sys, re, urlparse, copy, time, urllib, logging
-from types import StringTypes
try:
import threading as _threading
except ImportError:
[[('Basic', None), ('realm', '"foobar"')]]
"""
- assert type(header_values) not in StringTypes
+ assert not isinstance(header_values, basestring)
result = []
for text in header_values:
orig_text = text
def _copy_immutable(x):
return x
-for t in (types.NoneType, int, long, float, bool, str, tuple,
+for t in (type(None), int, long, float, bool, str, tuple,
frozenset, type, xrange, types.ClassType,
types.BuiltinFunctionType):
d[t] = _copy_immutable
def _deepcopy_atomic(x, memo):
return x
-d[types.NoneType] = _deepcopy_atomic
-d[types.IntType] = _deepcopy_atomic
-d[types.LongType] = _deepcopy_atomic
-d[types.FloatType] = _deepcopy_atomic
-d[types.BooleanType] = _deepcopy_atomic
+d[type(None)] = _deepcopy_atomic
+d[int] = _deepcopy_atomic
+d[long] = _deepcopy_atomic
+d[float] = _deepcopy_atomic
+d[bool] = _deepcopy_atomic
try:
- d[types.ComplexType] = _deepcopy_atomic
+ d[complex] = _deepcopy_atomic
except AttributeError:
pass
-d[types.StringType] = _deepcopy_atomic
+d[str] = _deepcopy_atomic
try:
- d[types.UnicodeType] = _deepcopy_atomic
+ d[unicode] = _deepcopy_atomic
except AttributeError:
pass
try:
d[types.CodeType] = _deepcopy_atomic
except AttributeError:
pass
-d[types.TypeType] = _deepcopy_atomic
-d[types.XRangeType] = _deepcopy_atomic
+d[type] = _deepcopy_atomic
+d[xrange] = _deepcopy_atomic
d[types.ClassType] = _deepcopy_atomic
d[types.BuiltinFunctionType] = _deepcopy_atomic
for a in x:
y.append(deepcopy(a, memo))
return y
-d[types.ListType] = _deepcopy_list
+d[list] = _deepcopy_list
def _deepcopy_tuple(x, memo):
y = []
y = x
memo[d] = y
return y
-d[types.TupleType] = _deepcopy_tuple
+d[tuple] = _deepcopy_tuple
def _deepcopy_dict(x, memo):
y = {}
for key, value in x.iteritems():
y[deepcopy(key, memo)] = deepcopy(value, memo)
return y
-d[types.DictionaryType] = _deepcopy_dict
+d[dict] = _deepcopy_dict
if PyStringMap is not None:
d[PyStringMap] = _deepcopy_dict
"""
import sys, os
-import types
import textwrap
try:
from gettext import gettext as _
if self.choices is None:
raise OptionError(
"must supply a list of choices for type 'choice'", self)
- elif type(self.choices) not in (types.TupleType, types.ListType):
+ elif type(self.choices) not in (tuple, list):
raise OptionError(
"choices must be a list of strings ('%s' supplied)"
% str(type(self.choices)).split("'")[1], self)
raise OptionError(
"callback not callable: %r" % self.callback, self)
if (self.callback_args is not None and
- type(self.callback_args) is not types.TupleType):
+ type(self.callback_args) is not tuple):
raise OptionError(
"callback_args, if supplied, must be a tuple: not %r"
% self.callback_args, self)
if (self.callback_kwargs is not None and
- type(self.callback_kwargs) is not types.DictType):
+ type(self.callback_kwargs) is not dict):
raise OptionError(
"callback_kwargs, if supplied, must be a dict: not %r"
% self.callback_kwargs, self)
"""add_option(Option)
add_option(opt_str, ..., kwarg=val, ...)
"""
- if type(args[0]) is types.StringType:
+ if type(args[0]) is str:
option = self.option_class(*args, **kwargs)
elif len(args) == 1 and not kwargs:
option = args[0]
def add_option_group(self, *args, **kwargs):
# XXX lots of overlap with OptionContainer.add_option()
- if type(args[0]) is types.StringType:
+ if type(args[0]) is str:
group = OptionGroup(self, *args, **kwargs)
elif len(args) == 1 and not kwargs:
group = args[0]
# Check for a class with a custom metaclass; treat as regular class
try:
- issc = issubclass(t, TypeType)
+ issc = issubclass(t, type)
except TypeError: # t is not a class (old Boost; see SF #502085)
issc = 0
if issc:
(t.__name__, obj))
# Check for string returned by reduce(), meaning "save as global"
- if type(rv) is StringType:
+ if type(rv) is str:
self.save_global(obj, rv)
return
# Assert that reduce() returned a tuple
- if type(rv) is not TupleType:
+ if type(rv) is not tuple:
raise PicklingError("%s must return string or tuple" % reduce)
# Assert that it returned an appropriately sized tuple
# This API is called by some subclasses
# 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")
# Assert that func is callable
def save_none(self, obj):
self.write(NONE)
- dispatch[NoneType] = save_none
+ dispatch[type(None)] = save_none
def save_bool(self, obj):
if self.proto >= 2:
return
# Text pickle, or int too big to fit in signed 4-byte format.
self.write(INT + repr(obj) + '\n')
- dispatch[IntType] = save_int
+ dispatch[int] = save_int
def save_long(self, obj, pack=struct.pack):
if self.proto >= 2:
self.write(LONG4 + pack("<i", n) + bytes)
return
self.write(LONG + repr(obj) + '\n')
- dispatch[LongType] = save_long
+ dispatch[long] = save_long
def save_float(self, obj, pack=struct.pack):
if self.bin:
self.write(BINFLOAT + pack('>d', obj))
else:
self.write(FLOAT + repr(obj) + '\n')
- dispatch[FloatType] = save_float
+ dispatch[float] = save_float
def save_string(self, obj, pack=struct.pack):
if self.bin:
else:
self.write(STRING + repr(obj) + '\n')
self.memoize(obj)
- dispatch[StringType] = save_string
+ dispatch[str] = save_string
def save_unicode(self, obj, pack=struct.pack):
if self.bin:
self.memoize(obj)
dispatch[UnicodeType] = save_unicode
- if StringType == UnicodeType:
+ if str == UnicodeType:
# This is true for Jython
def save_string(self, obj, pack=struct.pack):
unicode = obj.isunicode()
else:
self.write(STRING + repr(obj) + '\n')
self.memoize(obj)
- dispatch[StringType] = save_string
+ dispatch[str] = save_string
def save_tuple(self, obj):
write = self.write
self.write(TUPLE)
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
# found a Pickler subclass in Zope3 that calls it, so it's not harmless
self.memoize(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
# out of synch, though.
self.memoize(obj)
self._batch_setitems(obj.iteritems())
- dispatch[DictionaryType] = save_dict
+ dispatch[dict] = save_dict
if not PyStringMap is None:
dispatch[PyStringMap] = save_dict
dispatch[ClassType] = save_global
dispatch[FunctionType] = save_global
dispatch[BuiltinFunctionType] = save_global
- dispatch[TypeType] = save_global
+ dispatch[type] = save_global
# Pickling helpers
mswindows = (sys.platform == "win32")
import os
-import types
import traceback
# Exception classes used by this module.
# Detach and turn into fd
p2cwrite = p2cwrite.Detach()
p2cwrite = msvcrt.open_osfhandle(p2cwrite, 0)
- elif type(stdin) == types.IntType:
+ elif type(stdin) == int:
p2cread = msvcrt.get_osfhandle(stdin)
else:
# Assuming file-like object
# Detach and turn into fd
c2pread = c2pread.Detach()
c2pread = msvcrt.open_osfhandle(c2pread, 0)
- elif type(stdout) == types.IntType:
+ elif type(stdout) == int:
c2pwrite = msvcrt.get_osfhandle(stdout)
else:
# Assuming file-like object
errread = msvcrt.open_osfhandle(errread, 0)
elif stderr == STDOUT:
errwrite = c2pwrite
- elif type(stderr) == types.IntType:
+ elif type(stderr) == int:
errwrite = msvcrt.get_osfhandle(stderr)
else:
# Assuming file-like object
errread, errwrite):
"""Execute program (MS Windows version)"""
- if not isinstance(args, types.StringTypes):
+ if not isinstance(args, basestring):
args = list2cmdline(args)
# Process startup details
pass
elif stdin == PIPE:
p2cread, p2cwrite = os.pipe()
- elif type(stdin) == types.IntType:
+ elif type(stdin) == int:
p2cread = stdin
else:
# Assuming file-like object
pass
elif stdout == PIPE:
c2pread, c2pwrite = os.pipe()
- elif type(stdout) == types.IntType:
+ elif type(stdout) == int:
c2pwrite = stdout
else:
# Assuming file-like object
errread, errwrite = os.pipe()
elif stderr == STDOUT:
errwrite = c2pwrite
- elif type(stderr) == types.IntType:
+ elif type(stderr) == int:
errwrite = stderr
else:
# Assuming file-like object
errread, errwrite):
"""Execute program (POSIX version)"""
- if isinstance(args, types.StringTypes):
+ if isinstance(args, basestring):
args = [args]
if shell:
False, True = 0, 1
def isinstance(obj, clsinfo):
import __builtin__
- if type(clsinfo) in (types.TupleType, types.ListType):
+ if type(clsinfo) in (tuple, list):
for cls in clsinfo:
if cls is type: cls = types.ClassType
if __builtin__.isinstance(obj, cls):
import re, string, time, operator
-from types import *
+from types import InstanceType
# --------------------------------------------------------------------
# Internal stuff
"""
def __init__(self, value=0):
- if not isinstance(value, StringType):
- if not isinstance(value, (TupleType, time.struct_time)):
+ if not isinstance(value, str):
+ if not isinstance(value, (tuple, time.struct_time)):
if value == 0:
value = time.time()
value = time.localtime(value)
if not self.allow_none:
raise TypeError, "cannot marshal None unless allow_none is enabled"
write("<value><nil/></value>")
- dispatch[NoneType] = dump_nil
+ dispatch[type(None)] = dump_nil
def dump_int(self, value, write):
# in case ints are > 32 bits
write("<value><int>")
write(str(value))
write("</int></value>\n")
- dispatch[IntType] = dump_int
+ dispatch[int] = dump_int
if _bool_is_builtin:
def dump_bool(self, value, write):
write("<value><int>")
write(str(int(value)))
write("</int></value>\n")
- dispatch[LongType] = dump_long
+ dispatch[long] = dump_long
def dump_double(self, value, write):
write("<value><double>")
write(repr(value))
write("</double></value>\n")
- dispatch[FloatType] = dump_double
+ dispatch[float] = dump_double
def dump_string(self, value, write, escape=escape):
write("<value><string>")
write(escape(value))
write("</string></value>\n")
- dispatch[StringType] = dump_string
+ dispatch[str] = dump_string
if unicode:
def dump_unicode(self, value, write, escape=escape):
write("<value><string>")
write(escape(value))
write("</string></value>\n")
- dispatch[UnicodeType] = dump_unicode
+ dispatch[unicode] = dump_unicode
def dump_array(self, value, write):
i = id(value)
dump(v, write)
write("</data></array></value>\n")
del self.memo[i]
- dispatch[TupleType] = dump_array
- dispatch[ListType] = dump_array
+ dispatch[tuple] = dump_array
+ dispatch[list] = dump_array
def dump_struct(self, value, write, escape=escape):
i = id(value)
write("<value><struct>\n")
for k, v in value.items():
write("<member>\n")
- if type(k) is not StringType:
- if unicode and type(k) is UnicodeType:
+ if type(k) is not str:
+ if unicode and type(k) is unicode:
k = k.encode(self.encoding)
else:
raise TypeError, "dictionary key must be string"
write("</member>\n")
write("</struct></value>\n")
del self.memo[i]
- dispatch[DictType] = dump_struct
+ dispatch[dict] = dump_struct
def dump_instance(self, value, write):
# check for special wrappers
where necessary.
"""
- assert isinstance(params, TupleType) or isinstance(params, Fault),\
+ assert isinstance(params, tuple) or isinstance(params, Fault),\
"argument must be tuple or Fault instance"
if isinstance(params, Fault):
methodresponse = 1
- elif methodresponse and isinstance(params, TupleType):
+ elif methodresponse and isinstance(params, tuple):
assert len(params) == 1, "response tuple must be a singleton"
if not encoding:
# standard XML-RPC wrappings
if methodname:
# a method call
- if not isinstance(methodname, StringType):
+ if not isinstance(methodname, str):
methodname = methodname.encode(encoding)
data = (
xmlheader,
def get_host_info(self, host):
x509 = {}
- if isinstance(host, TupleType):
+ if isinstance(host, tuple):
host, x509 = host
import urllib
host, extra_headers, x509 = self.get_host_info(host)
connection.putheader("Host", host)
if extra_headers:
- if isinstance(extra_headers, DictType):
+ if isinstance(extra_headers, dict):
extra_headers = extra_headers.items()
for key, value in extra_headers:
connection.putheader(key, value)