Beispiel #1
0
    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()
Beispiel #2
0
    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()
Beispiel #3
0
 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)
Beispiel #4
0
 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)
Beispiel #5
0
 def decode(buf, encoding=default_encoding, errors="strict"):
     if not buf:
         return False
     input = _BinIO(buf)
     x = _uk_one(input, encoding, errors)
     return x
Beispiel #6
0
 def encode(obj, encoding=default_encoding, errors="strict"):
     out = _BinIO()
     _pk_one(out, obj, encoding, errors)
     return out.getvalue()
Beispiel #7
0
 def decode(buf, encoding=default_encoding, errors="strict"):
     if not buf:
         return False
     input = _BinIO(buf)
     x = _uk_one(input, encoding, errors)
     return x
Beispiel #8
0
 def encode(obj, encoding=default_encoding, errors="strict"):
     out = _BinIO()
     _pk_one(out, obj, encoding, errors)
     return out.getvalue()