def unpack(fmt, data):
formatdef, endianness, i = getmode(fmt)<EOL>j = <NUM_LIT:0><EOL>num = <NUM_LIT:0><EOL>result = []<EOL>length = calcsize(fmt)<EOL>if length != len(data):<EOL><INDENT>raise StructError("<STR_LIT>")<EOL><DEDENT>while i < len(fmt):<EOL><INDENT>num, i = getNum(fmt, i)<EOL>cur = fmt[i]<EOL>i += <NUM_LIT:1><EOL>try:<EOL><INDENT>format = formatdef[cur]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise StructError("<STR_LIT>" % cur)<EOL><DEDENT>if not num:<EOL><INDENT>num = <NUM_LIT:1><EOL><DEDENT>if cur == '<STR_LIT:x>':<EOL><INDENT>j += num<EOL><DEDENT>elif cur == '<STR_LIT:s>':<EOL><INDENT>result.append(data[j:j + num])<EOL>j += num<EOL><DEDENT>elif cur == '<STR_LIT:p>':<EOL><INDENT>n = data[j]<EOL>if n >= num:<EOL><INDENT>n = num - <NUM_LIT:1><EOL><DEDENT>result.append(data[j + <NUM_LIT:1>:j + n + <NUM_LIT:1>])<EOL>j += num<EOL><DEDENT>else:<EOL><INDENT>for n in range(num):<EOL><INDENT>result += [format['<STR_LIT>'](data, j, format['<STR_LIT:size>'], endianness)]<EOL>j += format['<STR_LIT:size>']<EOL><DEDENT><DEDENT><DEDENT>return tuple(result)<EOL>
unpack(fmt, string) -> (v1, v2, ...)
       Unpack the string, containing packed C structure data, according
       to fmt.  Requires len(string)==calcsize(fmt).
       See struct.__doc__ for more on format strings.