def pack(sequence, encoding=default_encoding, errors="strict"): if not isinstance(sequence, tuple) and not isinstance(sequence, list): raise TypeError("The first argument 'sequence' should be a tuple or list") out = _BinIO() for x in sequence: _pk_one(out, x, encoding, errors) return out.getvalue()
def pack(sequence, encoding=default_encoding, errors="strict"): if not isinstance(sequence, tuple) and not isinstance(sequence, list): raise TypeError( "The first argument 'sequence' should be a tuple or list") out = _BinIO() for x in sequence: _pk_one(out, x, encoding, errors) return out.getvalue()
def unpack(buf, offset=0, num=0, encoding=default_encoding, errors="strict"): result = [] input = _BinIO(buf[offset:]) n = 0 while num <= 0 or n < num: try: x = _uk_one(input, encoding, errors) result.append(x) n += 1 except StopIteration: break except _ClosureUnpacked: raise ValueError except: raise result.insert(0, input.tell()) return tuple(result)
def decode(buf, encoding=default_encoding, errors="strict"): if not buf: return False input = _BinIO(buf) x = _uk_one(input, encoding, errors) return x
def encode(obj, encoding=default_encoding, errors="strict"): out = _BinIO() _pk_one(out, obj, encoding, errors) return out.getvalue()