mirror of https://github.com/python/cpython
add support for Python's bool type to xmlrpclib - patch # 559288
This commit is contained in:
parent
32417e7dc1
commit
9a7c96a2bc
|
@ -142,6 +142,11 @@ try:
|
||||||
except NameError:
|
except NameError:
|
||||||
unicode = None # unicode support not available
|
unicode = None # unicode support not available
|
||||||
|
|
||||||
|
try:
|
||||||
|
_bool_is_builtin = False.__class__.__name__ == "bool"
|
||||||
|
except NameError:
|
||||||
|
_bool_is_builtin = 0
|
||||||
|
|
||||||
def _decode(data, encoding, is8bit=re.compile("[\x80-\xff]").search):
|
def _decode(data, encoding, is8bit=re.compile("[\x80-\xff]").search):
|
||||||
# decode non-ascii string (if possible)
|
# decode non-ascii string (if possible)
|
||||||
if unicode and encoding and is8bit(data):
|
if unicode and encoding and is8bit(data):
|
||||||
|
@ -266,6 +271,11 @@ class Fault(Error):
|
||||||
# @param value A boolean value. Any true value is interpreted as True,
|
# @param value A boolean value. Any true value is interpreted as True,
|
||||||
# all other values are interpreted as False.
|
# all other values are interpreted as False.
|
||||||
|
|
||||||
|
if _bool_is_builtin:
|
||||||
|
boolean = Boolean = bool
|
||||||
|
# to avoid breaking code which references xmlrpclib.{True,False}
|
||||||
|
True, False = True, False
|
||||||
|
else:
|
||||||
class Boolean:
|
class Boolean:
|
||||||
"""Boolean-value wrapper.
|
"""Boolean-value wrapper.
|
||||||
|
|
||||||
|
@ -411,7 +421,9 @@ def _binary(data):
|
||||||
value.decode(data)
|
value.decode(data)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
WRAPPERS = DateTime, Binary, Boolean
|
WRAPPERS = (DateTime, Binary)
|
||||||
|
if not _bool_is_builtin:
|
||||||
|
WRAPPERS = WRAPPERS + (Boolean,)
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# XML parsers
|
# XML parsers
|
||||||
|
@ -599,6 +611,13 @@ class Marshaller:
|
||||||
write("</int></value>\n")
|
write("</int></value>\n")
|
||||||
dispatch[IntType] = dump_int
|
dispatch[IntType] = dump_int
|
||||||
|
|
||||||
|
if _bool_is_builtin:
|
||||||
|
def dump_bool(self, value, write):
|
||||||
|
write("<value><boolean>")
|
||||||
|
write(value and "1" or "0")
|
||||||
|
write("</boolean></value>\n")
|
||||||
|
dispatch[bool] = dump_bool
|
||||||
|
|
||||||
def dump_long(self, value, write):
|
def dump_long(self, value, write):
|
||||||
if value > MAXINT or value < MININT:
|
if value > MAXINT or value < MININT:
|
||||||
raise OverflowError, "long int exceeds XML-RPC limits"
|
raise OverflowError, "long int exceeds XML-RPC limits"
|
||||||
|
|
Loading…
Reference in New Issue