From: Guido van Rossum Date: Mon, 21 Dec 1992 14:33:18 +0000 (+0000) Subject: Added generic array handlers X-Git-Tag: v0.9.8~19 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a3b986ed4ca4bb369e8792e52226ca2a593d5e31;p=thirdparty%2FPython%2Fcpython.git Added generic array handlers --- diff --git a/Demo/rpc/xdr.py b/Demo/rpc/xdr.py index 83fde30c762a..17a5f92cc3be 100644 --- a/Demo/rpc/xdr.py +++ b/Demo/rpc/xdr.py @@ -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)