Skip to content

Commit 7271bab

Browse files
committed
Compatibility hack with Python 0.9.6.
1 parent 2f5dd88 commit 7271bab

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Demo/rpc/xdr.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Implement (a subset of) Sun XDR -- RFC1014.
22

33

4-
import struct
4+
try:
5+
import struct
6+
except ImportError:
7+
struct = None
58

69

710
Long = type(0L)
@@ -23,7 +26,7 @@ def pack_uint(self, x):
2326
self.buf = self.buf + \
2427
(chr(int(x>>24 & 0xff)) + chr(int(x>>16 & 0xff)) + \
2528
chr(int(x>>8 & 0xff)) + chr(int(x & 0xff)))
26-
if struct.pack('l', 1) == '\0\0\0\1':
29+
if struct and struct.pack('l', 1) == '\0\0\0\1':
2730
def pack_uint(self, x):
2831
if type(x) == Long:
2932
x = int((x + 0x80000000L) % 0x100000000L \
@@ -92,7 +95,7 @@ def unpack_uint(self):
9295
# as a nonnegative Python int
9396
if x < 0x80000000L: x = int(x)
9497
return x
95-
if struct.unpack('l', '\0\0\0\1') == 1:
98+
if struct and struct.unpack('l', '\0\0\0\1') == 1:
9699
def unpack_uint(self):
97100
i = self.pos
98101
self.pos = j = i+4

0 commit comments

Comments
 (0)