Ejemplo n.º 1
0
def do_pack_into(space, format, w_buffer, offset, args_w):
    """ Pack the values v1, v2, ... according to fmt.
Write the packed bytes into the writable buffer buf starting at offset
    """
    size = _calcsize(space, format)
    buf = space.writebuf_w(w_buffer)
    buflen = buf.getlength()
    if offset < 0:
        # Check that negative offset is low enough to fit data
        if offset + size > 0:
            raise oefmt(get_error(space),
                        "no space to pack %d bytes at offset %d", size, offset)
        # Check that negative offset is not crossing buffer boundary
        if offset + buflen < 0:
            raise oefmt(get_error(space),
                        "offset %d out of range for %d-byte buffer", offset,
                        buflen)
        offset += buflen
    if (buflen - offset) < size:
        raise oefmt(
            get_error(space),
            "pack_into requires a buffer of at least %d bytes for "
            "packing %d bytes at offset %d "
            "(actual buffer size is %d)", size + offset, size, offset, buflen)
    #
    wbuf = SubBuffer(buf, offset, size)
    fmtiter = PackFormatIterator(space, wbuf, args_w)
    try:
        fmtiter.interpret(format)
    except StructOverflowError as e:
        raise OperationError(space.w_OverflowError, space.newtext(e.msg))
    except StructError as e:
        raise OperationError(get_error(space), space.newtext(e.msg))
Ejemplo n.º 2
0
def pack(space, format, args_w):
    if jit.isconstant(format):
        size = _calcsize(space, format)
    else:
        size = 8
    fmtiter = PackFormatIterator(space, args_w, size)
    try:
        fmtiter.interpret(format)
    except StructError, e:
        raise e.at_applevel(space)
Ejemplo n.º 3
0
def pack(space, format, args_w):
    if jit.isconstant(format):
        size = _calcsize(space, format)
    else:
        size = 8
    fmtiter = PackFormatIterator(space, args_w, size)
    try:
        fmtiter.interpret(format)
    except StructOverflowError, e:
        raise OperationError(space.w_OverflowError, space.wrap(e.msg))
Ejemplo n.º 4
0
def _pack(space, format, args_w):
    if jit.isconstant(format):
        size = _calcsize(space, format)
    else:
        size = 8
    fmtiter = PackFormatIterator(space, args_w, size)
    try:
        fmtiter.interpret(format)
    except StructOverflowError, e:
        raise OperationError(space.w_OverflowError, space.wrap(e.msg))
Ejemplo n.º 5
0
def pack(space, format, args_w):
    if jit.isconstant(format):
        size = _calcsize(space, format)
    else:
        size = 8
    fmtiter = PackFormatIterator(space, args_w, size)
    try:
        fmtiter.interpret(format)
    except StructError, e:
        raise e.at_applevel(space)
Ejemplo n.º 6
0
 def bytes_from_value(self, space, w_val):
     from pypy.module.struct.formatiterator import PackFormatIterator
     itemsize = self.getitemsize()
     buf = MutableStringBuffer(itemsize)
     fmtiter = PackFormatIterator(space, buf, [w_val])
     try:
         fmtiter.interpret(self.getformat())
     except StructError as e:
         raise oefmt(space.w_TypeError,
                     "memoryview: invalid type for format '%s'",
                     self.getformat())
     return buf.finish()
Ejemplo n.º 7
0
def _pack(space, format, args_w):
    """Return string containing values v1, v2, ... packed according to fmt."""
    size = _calcsize(space, format)
    wbuf = MutableStringBuffer(size)
    fmtiter = PackFormatIterator(space, wbuf, args_w)
    try:
        fmtiter.interpret(format)
    except StructOverflowError as e:
        raise OperationError(space.w_OverflowError, space.newtext(e.msg))
    except StructError as e:
        raise OperationError(get_error(space), space.newtext(e.msg))
    assert fmtiter.pos == wbuf.getlength(), 'missing .advance() or wrong calcsize()'
    return wbuf.finish()
Ejemplo n.º 8
0
def _pack(space, format, args_w):
    if jit.isconstant(format):
        size = _calcsize(space, format)
    else:
        size = 8
    fmtiter = PackFormatIterator(space, args_w, size)
    try:
        fmtiter.interpret(format)
    except StructOverflowError as e:
        raise OperationError(space.w_OverflowError, space.wrap(e.msg))
    except StructError as e:
        raise OperationError(get_error(space), space.wrap(e.msg))
    return fmtiter.result.build()
Ejemplo n.º 9
0
def _pack(space, format, args_w):
    if jit.isconstant(format):
        size = _calcsize(space, format)
    else:
        size = 8
    fmtiter = PackFormatIterator(space, args_w, size)
    try:
        fmtiter.interpret(format)
    except StructOverflowError as e:
        raise OperationError(space.w_OverflowError, space.newtext(e.msg))
    except StructError as e:
        raise OperationError(get_error(space), space.newtext(e.msg))
    return fmtiter.result.build()
Ejemplo n.º 10
0
def _pack(space, format, args_w):
    """Return string containing values v1, v2, ... packed according to fmt."""
    if jit.isconstant(format):
        size = _calcsize(space, format)
    else:
        size = 8
    fmtiter = PackFormatIterator(space, args_w, size)
    try:
        fmtiter.interpret(format)
    except StructOverflowError as e:
        raise OperationError(space.w_OverflowError, space.newtext(e.msg))
    except StructError as e:
        raise OperationError(get_error(space), space.newtext(e.msg))
    return fmtiter.result.build()
Ejemplo n.º 11
0
def pack_into(space, format, w_buffer, offset, args_w):
    """ Pack the values v1, v2, ... according to fmt.
Write the packed bytes into the writable buffer buf starting at offset
    """
    size = _calcsize(space, format)
    buf = space.getarg_w('w*', w_buffer)
    if offset < 0:
        offset += buf.getlength()
    if offset < 0 or (buf.getlength() - offset) < size:
        raise oefmt(get_error(space),
                    "pack_into requires a buffer of at least %d bytes", size)
    #
    wbuf = SubBuffer(buf, offset, size)
    fmtiter = PackFormatIterator(space, wbuf, args_w)
    try:
        fmtiter.interpret(format)
    except StructOverflowError as e:
        raise OperationError(space.w_OverflowError, space.newtext(e.msg))
    except StructError as e:
        raise OperationError(get_error(space), space.newtext(e.msg))
Ejemplo n.º 12
0
def pack(space, format, args_w):
    fmtiter = PackFormatIterator(space, args_w)
    try:
        fmtiter.interpret(format)
    except StructError, e:
        raise e.at_applevel(space)
Ejemplo n.º 13
0
def pack(space, format, args_w):
    fmtiter = PackFormatIterator(space, args_w)
    try:
        fmtiter.interpret(format)
    except StructError, e:
        raise e.at_applevel(space)