]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Added generic array handlers
authorGuido van Rossum <guido@python.org>
Mon, 21 Dec 1992 14:33:18 +0000 (14:33 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 21 Dec 1992 14:33:18 +0000 (14:33 +0000)
Demo/rpc/xdr.py

index 83fde30c762a90d31c79bd98d3d82f69eb5d24c9..17a5f92cc3be634b6dc040a5fe80ed2fcf49c51e 100644 (file)
@@ -70,6 +70,17 @@ class Packer:
                        pack_item(list)
                self.pack_uint(0)
 
+       def pack_farray(self, n, list, pack_item):
+               if len(list) <> n:
+                       raise ValueError, 'wrong array size'
+               for item in list:
+                       pack_item(item)
+
+       def pack_array(self, list, pack_item):
+               n = len(list)
+               self.pack_uint(n)
+               self.pack_farray(n, list)
+
 
 class Unpacker:
 
@@ -153,3 +164,13 @@ class Unpacker:
                                        '0 or 1 expected, got ' + `x`
                        list.append(unpack_item())
                return list
+
+       def unpack_farray(self, n, unpack_item):
+               list = []
+               for i in range(n):
+                       list.append(unpack_item())
+               return list
+
+       def unpack_array(self, unpack_item):
+               n = self.unpack_uint()
+               return self.unpack_farray(n, unpack_item)