Kaydet (Commit) f715366f authored tarafından Raymond Hettinger's avatar Raymond Hettinger

Reduce the usage of the types module.

üst a1645749
...@@ -12,7 +12,6 @@ modules. ...@@ -12,7 +12,6 @@ modules.
import pydoc import pydoc
import inspect import inspect
import types
import re import re
import sys import sys
...@@ -92,7 +91,7 @@ class ServerHTMLDoc(pydoc.HTMLDoc): ...@@ -92,7 +91,7 @@ class ServerHTMLDoc(pydoc.HTMLDoc):
else: else:
argspec = '(...)' argspec = '(...)'
if isinstance(object, types.TupleType): if isinstance(object, tuple):
argspec = object[0] or argspec argspec = object[0] or argspec
docstring = object[1] or "" docstring = object[1] or ""
else: else:
......
...@@ -26,7 +26,6 @@ are available from http://wwwsearch.sf.net/): ...@@ -26,7 +26,6 @@ are available from http://wwwsearch.sf.net/):
""" """
import sys, re, urlparse, copy, time, urllib, logging import sys, re, urlparse, copy, time, urllib, logging
from types import StringTypes
try: try:
import threading as _threading import threading as _threading
except ImportError: except ImportError:
...@@ -359,7 +358,7 @@ def split_header_words(header_values): ...@@ -359,7 +358,7 @@ def split_header_words(header_values):
[[('Basic', None), ('realm', '"foobar"')]] [[('Basic', None), ('realm', '"foobar"')]]
""" """
assert type(header_values) not in StringTypes assert not isinstance(header_values, basestring)
result = [] result = []
for text in header_values: for text in header_values:
orig_text = text orig_text = text
......
...@@ -99,7 +99,7 @@ _copy_dispatch = d = {} ...@@ -99,7 +99,7 @@ _copy_dispatch = d = {}
def _copy_immutable(x): def _copy_immutable(x):
return 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, frozenset, type, xrange, types.ClassType,
types.BuiltinFunctionType): types.BuiltinFunctionType):
d[t] = _copy_immutable d[t] = _copy_immutable
...@@ -195,26 +195,26 @@ _deepcopy_dispatch = d = {} ...@@ -195,26 +195,26 @@ _deepcopy_dispatch = d = {}
def _deepcopy_atomic(x, memo): def _deepcopy_atomic(x, memo):
return x return x
d[types.NoneType] = _deepcopy_atomic d[type(None)] = _deepcopy_atomic
d[types.IntType] = _deepcopy_atomic d[int] = _deepcopy_atomic
d[types.LongType] = _deepcopy_atomic d[long] = _deepcopy_atomic
d[types.FloatType] = _deepcopy_atomic d[float] = _deepcopy_atomic
d[types.BooleanType] = _deepcopy_atomic d[bool] = _deepcopy_atomic
try: try:
d[types.ComplexType] = _deepcopy_atomic d[complex] = _deepcopy_atomic
except AttributeError: except AttributeError:
pass pass
d[types.StringType] = _deepcopy_atomic d[str] = _deepcopy_atomic
try: try:
d[types.UnicodeType] = _deepcopy_atomic d[unicode] = _deepcopy_atomic
except AttributeError: except AttributeError:
pass pass
try: try:
d[types.CodeType] = _deepcopy_atomic d[types.CodeType] = _deepcopy_atomic
except AttributeError: except AttributeError:
pass pass
d[types.TypeType] = _deepcopy_atomic d[type] = _deepcopy_atomic
d[types.XRangeType] = _deepcopy_atomic d[xrange] = _deepcopy_atomic
d[types.ClassType] = _deepcopy_atomic d[types.ClassType] = _deepcopy_atomic
d[types.BuiltinFunctionType] = _deepcopy_atomic d[types.BuiltinFunctionType] = _deepcopy_atomic
...@@ -224,7 +224,7 @@ def _deepcopy_list(x, memo): ...@@ -224,7 +224,7 @@ def _deepcopy_list(x, memo):
for a in x: for a in x:
y.append(deepcopy(a, memo)) y.append(deepcopy(a, memo))
return y return y
d[types.ListType] = _deepcopy_list d[list] = _deepcopy_list
def _deepcopy_tuple(x, memo): def _deepcopy_tuple(x, memo):
y = [] y = []
...@@ -243,7 +243,7 @@ def _deepcopy_tuple(x, memo): ...@@ -243,7 +243,7 @@ def _deepcopy_tuple(x, memo):
y = x y = x
memo[d] = y memo[d] = y
return y return y
d[types.TupleType] = _deepcopy_tuple d[tuple] = _deepcopy_tuple
def _deepcopy_dict(x, memo): def _deepcopy_dict(x, memo):
y = {} y = {}
...@@ -251,7 +251,7 @@ def _deepcopy_dict(x, memo): ...@@ -251,7 +251,7 @@ def _deepcopy_dict(x, memo):
for key, value in x.iteritems(): for key, value in x.iteritems():
y[deepcopy(key, memo)] = deepcopy(value, memo) y[deepcopy(key, memo)] = deepcopy(value, memo)
return y return y
d[types.DictionaryType] = _deepcopy_dict d[dict] = _deepcopy_dict
if PyStringMap is not None: if PyStringMap is not None:
d[PyStringMap] = _deepcopy_dict d[PyStringMap] = _deepcopy_dict
......
...@@ -67,7 +67,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -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
try: try:
from gettext import gettext as _ from gettext import gettext as _
...@@ -590,7 +589,7 @@ class Option: ...@@ -590,7 +589,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 type(self.choices) not in (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)
...@@ -634,12 +633,12 @@ class Option: ...@@ -634,12 +633,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): type(self.callback_args) is not 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): type(self.callback_kwargs) is not 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)
...@@ -927,7 +926,7 @@ class OptionContainer: ...@@ -927,7 +926,7 @@ class OptionContainer:
"""add_option(Option) """add_option(Option)
add_option(opt_str, ..., kwarg=val, ...) 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) option = self.option_class(*args, **kwargs)
elif len(args) == 1 and not kwargs: elif len(args) == 1 and not kwargs:
option = args[0] option = args[0]
...@@ -1213,7 +1212,7 @@ class OptionParser (OptionContainer): ...@@ -1213,7 +1212,7 @@ class OptionParser (OptionContainer):
def add_option_group(self, *args, **kwargs): def add_option_group(self, *args, **kwargs):
# XXX lots of overlap with OptionContainer.add_option() # 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) group = OptionGroup(self, *args, **kwargs)
elif len(args) == 1 and not kwargs: elif len(args) == 1 and not kwargs:
group = args[0] group = args[0]
......
...@@ -288,7 +288,7 @@ class Pickler: ...@@ -288,7 +288,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,12 +313,12 @@ class Pickler: ...@@ -313,12 +313,12 @@ class Pickler:
(t.__name__, obj)) (t.__name__, obj))
# Check for string returned by reduce(), meaning "save as global" # 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) self.save_global(obj, rv)
return return
# Assert that reduce() returned a tuple # 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) 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
...@@ -347,7 +347,7 @@ class Pickler: ...@@ -347,7 +347,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
...@@ -425,7 +425,7 @@ class Pickler: ...@@ -425,7 +425,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:
...@@ -456,7 +456,7 @@ class Pickler: ...@@ -456,7 +456,7 @@ class Pickler:
return return
# 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 + repr(obj) + '\n') self.write(INT + repr(obj) + '\n')
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.proto >= 2: if self.proto >= 2:
...@@ -468,14 +468,14 @@ class Pickler: ...@@ -468,14 +468,14 @@ class Pickler:
self.write(LONG4 + pack("<i", n) + bytes) self.write(LONG4 + pack("<i", n) + bytes)
return return
self.write(LONG + repr(obj) + '\n') self.write(LONG + repr(obj) + '\n')
dispatch[LongType] = save_long dispatch[long] = 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 + repr(obj) + '\n') self.write(FLOAT + repr(obj) + '\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:
...@@ -487,7 +487,7 @@ class Pickler: ...@@ -487,7 +487,7 @@ class Pickler:
else: else:
self.write(STRING + repr(obj) + '\n') self.write(STRING + repr(obj) + '\n')
self.memoize(obj) self.memoize(obj)
dispatch[StringType] = save_string dispatch[str] = save_string
def save_unicode(self, obj, pack=struct.pack): def save_unicode(self, obj, pack=struct.pack):
if self.bin: if self.bin:
...@@ -501,7 +501,7 @@ class Pickler: ...@@ -501,7 +501,7 @@ class Pickler:
self.memoize(obj) self.memoize(obj)
dispatch[UnicodeType] = save_unicode dispatch[UnicodeType] = save_unicode
if StringType == UnicodeType: if str == UnicodeType:
# This is true for Jython # This is true for Jython
def save_string(self, obj, pack=struct.pack): def save_string(self, obj, pack=struct.pack):
unicode = obj.isunicode() unicode = obj.isunicode()
...@@ -527,7 +527,7 @@ class Pickler: ...@@ -527,7 +527,7 @@ class Pickler:
else: else:
self.write(STRING + repr(obj) + '\n') self.write(STRING + repr(obj) + '\n')
self.memoize(obj) self.memoize(obj)
dispatch[StringType] = save_string dispatch[str] = save_string
def save_tuple(self, obj): def save_tuple(self, obj):
write = self.write write = self.write
...@@ -580,7 +580,7 @@ class Pickler: ...@@ -580,7 +580,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
...@@ -599,7 +599,7 @@ class Pickler: ...@@ -599,7 +599,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.
...@@ -648,7 +648,7 @@ class Pickler: ...@@ -648,7 +648,7 @@ class Pickler:
self.memoize(obj) self.memoize(obj)
self._batch_setitems(obj.iteritems()) self._batch_setitems(obj.iteritems())
dispatch[DictionaryType] = save_dict dispatch[dict] = save_dict
if not PyStringMap is None: if not PyStringMap is None:
dispatch[PyStringMap] = save_dict dispatch[PyStringMap] = save_dict
...@@ -770,7 +770,7 @@ class Pickler: ...@@ -770,7 +770,7 @@ class Pickler:
dispatch[ClassType] = save_global 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
......
...@@ -372,7 +372,6 @@ import sys ...@@ -372,7 +372,6 @@ import sys
mswindows = (sys.platform == "win32") mswindows = (sys.platform == "win32")
import os import os
import types
import traceback import traceback
# Exception classes used by this module. # Exception classes used by this module.
...@@ -638,7 +637,7 @@ class Popen(object): ...@@ -638,7 +637,7 @@ class Popen(object):
# Detach and turn into fd # Detach and turn into fd
p2cwrite = p2cwrite.Detach() p2cwrite = p2cwrite.Detach()
p2cwrite = msvcrt.open_osfhandle(p2cwrite, 0) p2cwrite = msvcrt.open_osfhandle(p2cwrite, 0)
elif type(stdin) == types.IntType: elif type(stdin) == int:
p2cread = msvcrt.get_osfhandle(stdin) p2cread = msvcrt.get_osfhandle(stdin)
else: else:
# Assuming file-like object # Assuming file-like object
...@@ -652,7 +651,7 @@ class Popen(object): ...@@ -652,7 +651,7 @@ class Popen(object):
# Detach and turn into fd # Detach and turn into fd
c2pread = c2pread.Detach() c2pread = c2pread.Detach()
c2pread = msvcrt.open_osfhandle(c2pread, 0) c2pread = msvcrt.open_osfhandle(c2pread, 0)
elif type(stdout) == types.IntType: elif type(stdout) == int:
c2pwrite = msvcrt.get_osfhandle(stdout) c2pwrite = msvcrt.get_osfhandle(stdout)
else: else:
# Assuming file-like object # Assuming file-like object
...@@ -668,7 +667,7 @@ class Popen(object): ...@@ -668,7 +667,7 @@ class Popen(object):
errread = msvcrt.open_osfhandle(errread, 0) errread = msvcrt.open_osfhandle(errread, 0)
elif stderr == STDOUT: elif stderr == STDOUT:
errwrite = c2pwrite errwrite = c2pwrite
elif type(stderr) == types.IntType: elif type(stderr) == int:
errwrite = msvcrt.get_osfhandle(stderr) errwrite = msvcrt.get_osfhandle(stderr)
else: else:
# Assuming file-like object # Assuming file-like object
...@@ -711,7 +710,7 @@ class Popen(object): ...@@ -711,7 +710,7 @@ class Popen(object):
errread, errwrite): errread, errwrite):
"""Execute program (MS Windows version)""" """Execute program (MS Windows version)"""
if not isinstance(args, types.StringTypes): if not isinstance(args, basestring):
args = list2cmdline(args) args = list2cmdline(args)
# Process startup details # Process startup details
...@@ -876,7 +875,7 @@ class Popen(object): ...@@ -876,7 +875,7 @@ class Popen(object):
pass pass
elif stdin == PIPE: elif stdin == PIPE:
p2cread, p2cwrite = os.pipe() p2cread, p2cwrite = os.pipe()
elif type(stdin) == types.IntType: elif type(stdin) == int:
p2cread = stdin p2cread = stdin
else: else:
# Assuming file-like object # Assuming file-like object
...@@ -886,7 +885,7 @@ class Popen(object): ...@@ -886,7 +885,7 @@ class Popen(object):
pass pass
elif stdout == PIPE: elif stdout == PIPE:
c2pread, c2pwrite = os.pipe() c2pread, c2pwrite = os.pipe()
elif type(stdout) == types.IntType: elif type(stdout) == int:
c2pwrite = stdout c2pwrite = stdout
else: else:
# Assuming file-like object # Assuming file-like object
...@@ -898,7 +897,7 @@ class Popen(object): ...@@ -898,7 +897,7 @@ class Popen(object):
errread, errwrite = os.pipe() errread, errwrite = os.pipe()
elif stderr == STDOUT: elif stderr == STDOUT:
errwrite = c2pwrite errwrite = c2pwrite
elif type(stderr) == types.IntType: elif type(stderr) == int:
errwrite = stderr errwrite = stderr
else: else:
# Assuming file-like object # Assuming file-like object
...@@ -937,7 +936,7 @@ class Popen(object): ...@@ -937,7 +936,7 @@ class Popen(object):
errread, errwrite): errread, errwrite):
"""Execute program (POSIX version)""" """Execute program (POSIX version)"""
if isinstance(args, types.StringTypes): if isinstance(args, basestring):
args = [args] args = [args]
if shell: if shell:
......
...@@ -71,7 +71,7 @@ if sys.version_info[:2] < (2, 2): ...@@ -71,7 +71,7 @@ if sys.version_info[:2] < (2, 2):
False, True = 0, 1 False, True = 0, 1
def isinstance(obj, clsinfo): def isinstance(obj, clsinfo):
import __builtin__ import __builtin__
if type(clsinfo) in (types.TupleType, types.ListType): if type(clsinfo) in (tuple, list):
for cls in clsinfo: for cls in clsinfo:
if cls is type: cls = types.ClassType if cls is type: cls = types.ClassType
if __builtin__.isinstance(obj, cls): if __builtin__.isinstance(obj, cls):
......
...@@ -138,7 +138,7 @@ Exported functions: ...@@ -138,7 +138,7 @@ Exported functions:
import re, string, time, operator import re, string, time, operator
from types import * from types import InstanceType
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Internal stuff # Internal stuff
...@@ -348,8 +348,8 @@ class DateTime: ...@@ -348,8 +348,8 @@ class DateTime:
""" """
def __init__(self, value=0): def __init__(self, value=0):
if not isinstance(value, StringType): if not isinstance(value, str):
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)
...@@ -618,7 +618,7 @@ class Marshaller: ...@@ -618,7 +618,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
...@@ -627,7 +627,7 @@ class Marshaller: ...@@ -627,7 +627,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):
...@@ -642,19 +642,19 @@ class Marshaller: ...@@ -642,19 +642,19 @@ 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[long] = 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>")
write(escape(value)) write(escape(value))
write("</string></value>\n") write("</string></value>\n")
dispatch[StringType] = dump_string dispatch[str] = dump_string
if unicode: if unicode:
def dump_unicode(self, value, write, escape=escape): def dump_unicode(self, value, write, escape=escape):
...@@ -662,7 +662,7 @@ class Marshaller: ...@@ -662,7 +662,7 @@ class Marshaller:
write("<value><string>") write("<value><string>")
write(escape(value)) write(escape(value))
write("</string></value>\n") write("</string></value>\n")
dispatch[UnicodeType] = dump_unicode dispatch[unicode] = dump_unicode
def dump_array(self, value, write): def dump_array(self, value, write):
i = id(value) i = id(value)
...@@ -675,8 +675,8 @@ class Marshaller: ...@@ -675,8 +675,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)
...@@ -687,8 +687,8 @@ class Marshaller: ...@@ -687,8 +687,8 @@ class Marshaller:
write("<value><struct>\n") write("<value><struct>\n")
for k, v in value.items(): for k, v in value.items():
write("<member>\n") write("<member>\n")
if type(k) is not StringType: if type(k) is not str:
if unicode and type(k) is UnicodeType: if unicode and type(k) is unicode:
k = k.encode(self.encoding) k = k.encode(self.encoding)
else: else:
raise TypeError, "dictionary key must be string" raise TypeError, "dictionary key must be string"
...@@ -697,7 +697,7 @@ class Marshaller: ...@@ -697,7 +697,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
def dump_instance(self, value, write): def dump_instance(self, value, write):
# check for special wrappers # check for special wrappers
...@@ -1010,12 +1010,12 @@ def dumps(params, methodname=None, methodresponse=None, encoding=None, ...@@ -1010,12 +1010,12 @@ 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) or isinstance(params, 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:
...@@ -1036,7 +1036,7 @@ def dumps(params, methodname=None, methodresponse=None, encoding=None, ...@@ -1036,7 +1036,7 @@ def dumps(params, methodname=None, methodresponse=None, encoding=None,
# standard XML-RPC wrappings # standard XML-RPC wrappings
if methodname: if methodname:
# a method call # a method call
if not isinstance(methodname, StringType): if not isinstance(methodname, str):
methodname = methodname.encode(encoding) methodname = methodname.encode(encoding)
data = ( data = (
xmlheader, xmlheader,
...@@ -1168,7 +1168,7 @@ class Transport: ...@@ -1168,7 +1168,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
...@@ -1218,7 +1218,7 @@ class Transport: ...@@ -1218,7 +1218,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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment