Reads a packed integer from string <s>

def unpack_int(s):
    """ Reads a packed integer from string <s> """
    ret = 0
    i = 0
    while True:
        b = ord(s[i])
        ret |= (b & 127) << (i * 7)
        i += 1
        if b & 128 == 0:
            break
    return ret