Revert previous checkin.

This commit is contained in:
Raymond Hettinger 2005-02-07 15:28:45 +00:00
parent f715366f23
commit fe59dc1bd8
2 changed files with 34 additions and 34 deletions

View File

@ -288,7 +288,7 @@ class Pickler:
# Check for a class with a custom metaclass; treat as regular class
try:
issc = issubclass(t, type)
issc = issubclass(t, TypeType)
except TypeError: # t is not a class (old Boost; see SF #502085)
issc = 0
if issc:
@ -313,12 +313,12 @@ class Pickler:
(t.__name__, obj))
# Check for string returned by reduce(), meaning "save as global"
if type(rv) is str:
if type(rv) is StringType:
self.save_global(obj, rv)
return
# Assert that reduce() returned a tuple
if type(rv) is not tuple:
if type(rv) is not TupleType:
raise PicklingError("%s must return string or tuple" % reduce)
# Assert that it returned an appropriately sized tuple
@ -347,7 +347,7 @@ class Pickler:
# This API is called by some subclasses
# Assert that args is a tuple or None
if not isinstance(args, tuple):
if not isinstance(args, TupleType):
raise PicklingError("args from reduce() should be a tuple")
# Assert that func is callable
@ -425,7 +425,7 @@ class Pickler:
def save_none(self, obj):
self.write(NONE)
dispatch[type(None)] = save_none
dispatch[NoneType] = save_none
def save_bool(self, obj):
if self.proto >= 2:
@ -456,7 +456,7 @@ class Pickler:
return
# Text pickle, or int too big to fit in signed 4-byte format.
self.write(INT + repr(obj) + '\n')
dispatch[int] = save_int
dispatch[IntType] = save_int
def save_long(self, obj, pack=struct.pack):
if self.proto >= 2:
@ -468,14 +468,14 @@ class Pickler:
self.write(LONG4 + pack("<i", n) + bytes)
return
self.write(LONG + repr(obj) + '\n')
dispatch[long] = save_long
dispatch[LongType] = 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[float] = save_float
dispatch[FloatType] = save_float
def save_string(self, obj, pack=struct.pack):
if self.bin:
@ -487,7 +487,7 @@ class Pickler:
else:
self.write(STRING + repr(obj) + '\n')
self.memoize(obj)
dispatch[str] = save_string
dispatch[StringType] = save_string
def save_unicode(self, obj, pack=struct.pack):
if self.bin:
@ -501,7 +501,7 @@ class Pickler:
self.memoize(obj)
dispatch[UnicodeType] = save_unicode
if str == UnicodeType:
if StringType == UnicodeType:
# This is true for Jython
def save_string(self, obj, pack=struct.pack):
unicode = obj.isunicode()
@ -527,7 +527,7 @@ class Pickler:
else:
self.write(STRING + repr(obj) + '\n')
self.memoize(obj)
dispatch[str] = save_string
dispatch[StringType] = save_string
def save_tuple(self, obj):
write = self.write
@ -580,7 +580,7 @@ class Pickler:
self.write(TUPLE)
self.memoize(obj)
dispatch[tuple] = save_tuple
dispatch[TupleType] = 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
@ -599,7 +599,7 @@ class Pickler:
self.memoize(obj)
self._batch_appends(iter(obj))
dispatch[list] = save_list
dispatch[ListType] = save_list
# Keep in synch with cPickle's BATCHSIZE. Nothing will break if it gets
# out of synch, though.
@ -648,7 +648,7 @@ class Pickler:
self.memoize(obj)
self._batch_setitems(obj.iteritems())
dispatch[dict] = save_dict
dispatch[DictionaryType] = save_dict
if not PyStringMap is None:
dispatch[PyStringMap] = save_dict
@ -770,7 +770,7 @@ class Pickler:
dispatch[ClassType] = save_global
dispatch[FunctionType] = save_global
dispatch[BuiltinFunctionType] = save_global
dispatch[type] = save_global
dispatch[TypeType] = save_global
# Pickling helpers

View File

@ -138,7 +138,7 @@ Exported functions:
import re, string, time, operator
from types import InstanceType
from types import *
# --------------------------------------------------------------------
# Internal stuff
@ -348,8 +348,8 @@ class DateTime:
"""
def __init__(self, value=0):
if not isinstance(value, str):
if not isinstance(value, (tuple, time.struct_time)):
if not isinstance(value, StringType):
if not isinstance(value, (TupleType, time.struct_time)):
if value == 0:
value = time.time()
value = time.localtime(value)
@ -618,7 +618,7 @@ class Marshaller:
if not self.allow_none:
raise TypeError, "cannot marshal None unless allow_none is enabled"
write("<value><nil/></value>")
dispatch[type(None)] = dump_nil
dispatch[NoneType] = dump_nil
def dump_int(self, value, write):
# in case ints are > 32 bits
@ -627,7 +627,7 @@ class Marshaller:
write("<value><int>")
write(str(value))
write("</int></value>\n")
dispatch[int] = dump_int
dispatch[IntType] = dump_int
if _bool_is_builtin:
def dump_bool(self, value, write):
@ -642,19 +642,19 @@ class Marshaller:
write("<value><int>")
write(str(int(value)))
write("</int></value>\n")
dispatch[long] = dump_long
dispatch[LongType] = dump_long
def dump_double(self, value, write):
write("<value><double>")
write(repr(value))
write("</double></value>\n")
dispatch[float] = dump_double
dispatch[FloatType] = dump_double
def dump_string(self, value, write, escape=escape):
write("<value><string>")
write(escape(value))
write("</string></value>\n")
dispatch[str] = dump_string
dispatch[StringType] = dump_string
if unicode:
def dump_unicode(self, value, write, escape=escape):
@ -662,7 +662,7 @@ class Marshaller:
write("<value><string>")
write(escape(value))
write("</string></value>\n")
dispatch[unicode] = dump_unicode
dispatch[UnicodeType] = dump_unicode
def dump_array(self, value, write):
i = id(value)
@ -675,8 +675,8 @@ class Marshaller:
dump(v, write)
write("</data></array></value>\n")
del self.memo[i]
dispatch[tuple] = dump_array
dispatch[list] = dump_array
dispatch[TupleType] = dump_array
dispatch[ListType] = dump_array
def dump_struct(self, value, write, escape=escape):
i = id(value)
@ -687,8 +687,8 @@ class Marshaller:
write("<value><struct>\n")
for k, v in value.items():
write("<member>\n")
if type(k) is not str:
if unicode and type(k) is unicode:
if type(k) is not StringType:
if unicode and type(k) is UnicodeType:
k = k.encode(self.encoding)
else:
raise TypeError, "dictionary key must be string"
@ -697,7 +697,7 @@ class Marshaller:
write("</member>\n")
write("</struct></value>\n")
del self.memo[i]
dispatch[dict] = dump_struct
dispatch[DictType] = dump_struct
def dump_instance(self, value, write):
# check for special wrappers
@ -1010,12 +1010,12 @@ def dumps(params, methodname=None, methodresponse=None, encoding=None,
where necessary.
"""
assert isinstance(params, tuple) or isinstance(params, Fault),\
assert isinstance(params, TupleType) or isinstance(params, Fault),\
"argument must be tuple or Fault instance"
if isinstance(params, Fault):
methodresponse = 1
elif methodresponse and isinstance(params, tuple):
elif methodresponse and isinstance(params, TupleType):
assert len(params) == 1, "response tuple must be a singleton"
if not encoding:
@ -1036,7 +1036,7 @@ def dumps(params, methodname=None, methodresponse=None, encoding=None,
# standard XML-RPC wrappings
if methodname:
# a method call
if not isinstance(methodname, str):
if not isinstance(methodname, StringType):
methodname = methodname.encode(encoding)
data = (
xmlheader,
@ -1168,7 +1168,7 @@ class Transport:
def get_host_info(self, host):
x509 = {}
if isinstance(host, tuple):
if isinstance(host, TupleType):
host, x509 = host
import urllib
@ -1218,7 +1218,7 @@ class Transport:
host, extra_headers, x509 = self.get_host_info(host)
connection.putheader("Host", host)
if extra_headers:
if isinstance(extra_headers, dict):
if isinstance(extra_headers, DictType):
extra_headers = extra_headers.items()
for key, value in extra_headers:
connection.putheader(key, value)