summaryrefslogtreecommitdiffstats
path: root/Lib/xdrlib.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2005-02-24 20:22:10 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2005-02-24 20:22:10 (GMT)
commitc2a0ac20b7ba3c740f21607c4c8bc706f5d7b7c5 (patch)
tree589f8ff427b01e7e1685f8515cdd0c83503d2d0e /Lib/xdrlib.py
parentbc2c21ea521cf6ec2a8cd1fd3229226c157a5100 (diff)
downloadcpython-c2a0ac20b7ba3c740f21607c4c8bc706f5d7b7c5.zip
cpython-c2a0ac20b7ba3c740f21607c4c8bc706f5d7b7c5.tar.gz
cpython-c2a0ac20b7ba3c740f21607c4c8bc706f5d7b7c5.tar.bz2
Patch #1049151: adding bool support to xdrlib.py.
Also add xdrlib._test into the test suite.
Diffstat (limited to 'Lib/xdrlib.py')
-rw-r--r--Lib/xdrlib.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/xdrlib.py b/Lib/xdrlib.py
index 1123090..d9d2120 100644
--- a/Lib/xdrlib.py
+++ b/Lib/xdrlib.py
@@ -157,7 +157,9 @@ class Unpacker:
return struct.unpack('>l', data)[0]
unpack_enum = unpack_int
- unpack_bool = unpack_int
+
+ def unpack_bool(self):
+ return bool(self.unpack_int())
def unpack_uhyper(self):
hi = self.unpack_uint()
@@ -232,8 +234,8 @@ def _test():
p = Packer()
packtest = [
(p.pack_uint, (9,)),
- (p.pack_bool, (None,)),
- (p.pack_bool, ('hello',)),
+ (p.pack_bool, (True,)),
+ (p.pack_bool, (False,)),
(p.pack_uhyper, (45L,)),
(p.pack_float, (1.9,)),
(p.pack_double, (1.9,)),
@@ -257,8 +259,8 @@ def _test():
up = Unpacker(data)
unpacktest = [
(up.unpack_uint, (), lambda x: x == 9),
- (up.unpack_bool, (), lambda x: not x),
- (up.unpack_bool, (), lambda x: x),
+ (up.unpack_bool, (), lambda x: x is True),
+ (up.unpack_bool, (), lambda x: x is False),
(up.unpack_uhyper, (), lambda x: x == 45L),
(up.unpack_float, (), lambda x: 1.89 < x < 1.91),
(up.unpack_double, (), lambda x: 1.89 < x < 1.91),