diff options
author | Guido van Rossum <guido@python.org> | 1992-12-21 14:33:18 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1992-12-21 14:33:18 (GMT) |
commit | a3b986ed4ca4bb369e8792e52226ca2a593d5e31 (patch) | |
tree | a1f342d3bc8748458ed8185634fbfafe0936ad83 /Demo/rpc/xdr.py | |
parent | 9ef9c07ed972804dbfef4fec4d739805b64cae95 (diff) | |
download | cpython-a3b986ed4ca4bb369e8792e52226ca2a593d5e31.zip cpython-a3b986ed4ca4bb369e8792e52226ca2a593d5e31.tar.gz cpython-a3b986ed4ca4bb369e8792e52226ca2a593d5e31.tar.bz2 |
Added generic array handlers
Diffstat (limited to 'Demo/rpc/xdr.py')
-rw-r--r-- | Demo/rpc/xdr.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Demo/rpc/xdr.py b/Demo/rpc/xdr.py index 83fde30..17a5f92 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) |