def write_vuint(port, x):
if x < 0:
- raise Exception("vuints must not be negative")
+ raise Exception("vuint's must not be negative")
elif x == 0:
port.write('\0')
else:
def read_vuint(port):
c = port.read(1)
if c == '':
- raise EOFError('encountered EOF while reading vuint');
+ raise EOFError('Encountered EOF while reading vuint');
result = 0
offset = 0
while c:
def read_vint(port):
c = port.read(1)
if c == '':
- raise EOFError('encountered EOF while reading vint');
+ raise EOFError('Encountered EOF while reading vint');
negative = False
result = 0
offset = 0
if b & 0x80:
offset += 6
c = port.read(1)
+ elif negative:
+ return -result
else:
- return -result if negative else result
+ return result
while c:
b = ord(c)
if b & 0x80:
else:
result |= (b << offset)
break
- return -result if negative else result
+ if negative:
+ return -result
+ else:
+ return result
def write_bvec(port, x):
def pack(types, *args):
if len(types) != len(args):
- raise Exception('number of arguments does not match format string')
+ raise Exception('Number of arguments does not match format string')
port = StringIO()
for (type, value) in zip(types, args):
if type == 'V':
elif type == 's':
write_bvec(port, value)
else:
- raise Exception('unknown xpack format string item "' + type + '"')
+ raise Exception('Unknown xpack format string item "' + type + '"')
return port.getvalue()
elif type == 's':
result.append(read_bvec(port))
else:
- raise Exception('unknown xunpack format string item "' + type + '"')
+ raise Exception('Unknown xunpack format string item "' + type + '"')
return result