Exemplo n.º 1
0
def lseek(fd, pos, how):
    """lseek(fd, pos, how) -> newpos

    Set the current position of a file descriptor.
    """
    rawio = FileDescriptors.get(fd)
    return _handle_oserror(rawio.seek, pos, how)
Exemplo n.º 2
0
def fdopen(fd, mode='r', bufsize=-1):
    """fdopen(fd [, mode='r' [, bufsize]]) -> file_object

    Return an open file object connected to a file descriptor.
    """
    rawio = FileDescriptors.get(fd)
    if (len(mode) and mode[0] or '') not in 'rwa':
        raise ValueError("invalid file mode '%s'" % mode)
    if rawio.closed():
        raise OSError(errno.EBADF, strerror(errno.EBADF))

    try:
        fp = FileDescriptors.wrap(rawio, mode, bufsize)
    except IOError:
        raise OSError(errno.EINVAL, strerror(errno.EINVAL))
    return fp
Exemplo n.º 3
0
def lseek(fd, pos, how):
    """lseek(fd, pos, how) -> newpos

    Set the current position of a file descriptor.
    """
    rawio = FileDescriptors.get(fd)
    return _handle_oserror(rawio.seek, pos, how)
Exemplo n.º 4
0
def close(fd):
    """close(fd)

    Close a file descriptor (for low level IO).
    """
    rawio = FileDescriptors.get(fd)
    _handle_oserror(rawio.close)
Exemplo n.º 5
0
def fdopen(fd, mode='r', bufsize=-1):
    """fdopen(fd [, mode='r' [, bufsize]]) -> file_object

    Return an open file object connected to a file descriptor.
    """
    rawio = FileDescriptors.get(fd)
    if (len(mode) and mode[0] or '') not in 'rwa':
        raise ValueError("invalid file mode '%s'" % mode)
    if rawio.closed():
        raise OSError(errno.EBADF, errno.strerror(errno.EBADF))

    try:
        fp = FileDescriptors.wrap(rawio, mode, bufsize)
    except IOError:
        raise OSError(errno.EINVAL, errno.strerror(errno.EINVAL))
    return fp
Exemplo n.º 6
0
def close(fd):
    """close(fd)

    Close a file descriptor (for low level IO).
    """
    rawio = FileDescriptors.get(fd)
    _handle_oserror(rawio.close)
Exemplo n.º 7
0
def read(fd, buffersize):
    """read(fd, buffersize) -> string

    Read a file descriptor.
    """
    from org.python.core.util import StringUtil
    rawio = FileDescriptors.get(fd)
    buf = _handle_oserror(rawio.read, buffersize)
    return asPyString(StringUtil.fromBytes(buf))
Exemplo n.º 8
0
def read(fd, buffersize):
    """read(fd, buffersize) -> string

    Read a file descriptor.
    """
    from org.python.core.util import StringUtil
    rawio = FileDescriptors.get(fd)
    buf = _handle_oserror(rawio.read, buffersize)
    return asPyString(StringUtil.fromBytes(buf))
Exemplo n.º 9
0
def write(fd, string):
    """write(fd, string) -> byteswritten

    Write a string to a file descriptor.
    """
    from java.nio import ByteBuffer
    from org.python.core.util import StringUtil
    rawio = FileDescriptors.get(fd)
    return _handle_oserror(rawio.write,
                           ByteBuffer.wrap(StringUtil.toBytes(string)))
Exemplo n.º 10
0
def ftruncate(fd, length):
    """ftruncate(fd, length)

    Truncate a file to a specified length.
    """
    rawio = FileDescriptors.get(fd)
    try:
        rawio.truncate(length)
    except Exception, e:
        raise IOError(errno.EBADF, strerror(errno.EBADF))
Exemplo n.º 11
0
def write(fd, string):
    """write(fd, string) -> byteswritten

    Write a string to a file descriptor.
    """
    from java.nio import ByteBuffer
    from org.python.core.util import StringUtil
    rawio = FileDescriptors.get(fd)
    return _handle_oserror(rawio.write,
                           ByteBuffer.wrap(StringUtil.toBytes(string)))
Exemplo n.º 12
0
def ftruncate(fd, length):
    """ftruncate(fd, length)

    Truncate a file to a specified length.
    """
    rawio = FileDescriptors.get(fd)
    try:
        rawio.truncate(length)
    except Exception, e:
        raise IOError(errno.EBADF, errno.strerror(errno.EBADF))
Exemplo n.º 13
0
def _fsync(fd, metadata):
    """Internal fsync impl"""
    rawio = FileDescriptors.get(fd)
    rawio.checkClosed()
    
    from java.nio.channels import FileChannel
    channel = rawio.getChannel()
    if not isinstance(channel, FileChannel):
        raise OSError(errno.EINVAL, strerror(errno.EINVAL))

    try:
        channel.force(metadata)
    except java.io.IOException, ioe:
        raise OSError(ioe)
Exemplo n.º 14
0
def _fsync(fd, metadata):
    """Internal fsync impl"""
    rawio = FileDescriptors.get(fd)
    rawio.checkClosed()

    from java.nio.channels import FileChannel
    channel = rawio.getChannel()
    if not isinstance(channel, FileChannel):
        raise OSError(errno.EINVAL, strerror(errno.EINVAL))

    try:
        channel.force(metadata)
    except java.io.IOException, ioe:
        raise OSError(ioe)