]> granicus.if.org Git - python/commitdiff
Patch #1049151: adding bool support to xdrlib.py.
authorMartin v. Löwis <martin@v.loewis.de>
Thu, 24 Feb 2005 20:22:10 +0000 (20:22 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Thu, 24 Feb 2005 20:22:10 +0000 (20:22 +0000)
Also add xdrlib._test into the test suite.

Lib/test/output/test_xdrlib [new file with mode: 0644]
Lib/test/test_sundry.py
Lib/test/test_xdrlib.py [new file with mode: 0644]
Lib/xdrlib.py
Misc/NEWS

diff --git a/Lib/test/output/test_xdrlib b/Lib/test/output/test_xdrlib
new file mode 100644 (file)
index 0000000..d86caa9
--- /dev/null
@@ -0,0 +1,19 @@
+test_xdrlib
+pack test 0 succeeded
+pack test 1 succeeded
+pack test 2 succeeded
+pack test 3 succeeded
+pack test 4 succeeded
+pack test 5 succeeded
+pack test 6 succeeded
+pack test 7 succeeded
+pack test 8 succeeded
+unpack test 0 succeeded : 9
+unpack test 1 succeeded : True
+unpack test 2 succeeded : False
+unpack test 3 succeeded : 45
+unpack test 4 succeeded : 1.89999997616
+unpack test 5 succeeded : 1.9
+unpack test 6 succeeded : hello world
+unpack test 7 succeeded : [0, 1, 2, 3, 4]
+unpack test 8 succeeded : ['what', 'is', 'hapnin', 'doctor']
index be1a1e774da1a64562838bc280f2412860ba121f..394d966db02a0c19f17679276c8fa2e4cfc9c68e 100644 (file)
@@ -93,5 +93,4 @@ import urllib2
 #import user
 import webbrowser
 import whichdb
-import xdrlib
 import xml
diff --git a/Lib/test/test_xdrlib.py b/Lib/test/test_xdrlib.py
new file mode 100644 (file)
index 0000000..afa6afe
--- /dev/null
@@ -0,0 +1,4 @@
+import xdrlib
+
+xdrlib._test()
+
index 112309036dcfa0b09d2f4de690e52eb0f0e41638..d9d2120a60c1156e47f99e8b4cdb21c603f7d801 100644 (file)
@@ -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),
index 71e7b82440dee3322e5d33fd11707aef457a76d5..7d6a9e6e1aa1253cf6619be125473e650577cbcb 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -54,6 +54,8 @@ Extension Modules
 Library
 -------
 
+- Patch #1049151: xdrlib now unpacks booleans as True or False.
+
 - Fixed bug in a NameError bug in cookielib.  Patch #1116583.
 
 - Applied a security fix to SimpleXMLRPCserver (PSF-2005-001).  This