summaryrefslogtreecommitdiffstats
path: root/Demo
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-12-15 21:43:59 (GMT)
committerGuido van Rossum <guido@python.org>1992-12-15 21:43:59 (GMT)
commit38625352bb50002614c160039d09ea5e3d9cc279 (patch)
tree1d7a8b0b60d94ab6fe4f8084d3ee62651f616b43 /Demo
parentad5f862125fec14b11e76628430d2b4722195400 (diff)
downloadcpython-38625352bb50002614c160039d09ea5e3d9cc279.zip
cpython-38625352bb50002614c160039d09ea5e3d9cc279.tar.gz
cpython-38625352bb50002614c160039d09ea5e3d9cc279.tar.bz2
Support packing longs.
Diffstat (limited to 'Demo')
-rw-r--r--Demo/rpc/xdr.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/Demo/rpc/xdr.py b/Demo/rpc/xdr.py
index b189b45..b3e514a 100644
--- a/Demo/rpc/xdr.py
+++ b/Demo/rpc/xdr.py
@@ -4,6 +4,9 @@
import struct
+Long = type(0L)
+
+
class Packer:
def init(self):
@@ -20,9 +23,12 @@ class Packer:
self.buf = self.buf + \
(chr(int(x>>24 & 0xff)) + chr(int(x>>16 & 0xff)) + \
chr(int(x>>8 & 0xff)) + chr(int(x & 0xff)))
- if struct.pack('i', 1) == '\0\0\0\1':
+ if struct.pack('l', 1) == '\0\0\0\1':
def pack_uint(self, x):
- self.buf = self.buf + struct.pack('i', x)
+ if type(x) == Long:
+ x = int((x + 0x80000000L) % 0x100000000L \
+ - 0x80000000L)
+ self.buf = self.buf + struct.pack('l', x)
pack_int = pack_uint
@@ -33,8 +39,8 @@ class Packer:
else: self.buf = self.buf + '\0\0\0\0'
def pack_uhyper(self, x):
- self.pack_uint(x>>32 & 0xffffffff)
- self.pack_uint(x & 0xffffffff)
+ self.pack_uint(int(x>>32 & 0xffffffff))
+ self.pack_uint(int(x & 0xffffffff))
pack_hyper = pack_uhyper