当前位置: 首页>>代码示例>>Python>>正文


Python mmap.error方法代码示例

本文整理汇总了Python中mmap.error方法的典型用法代码示例。如果您正苦于以下问题:Python mmap.error方法的具体用法?Python mmap.error怎么用?Python mmap.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mmap的用法示例。


在下文中一共展示了mmap.error方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_constructor_bad_file

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import error [as 别名]
def test_constructor_bad_file(self, mmap_file):
        non_file = StringIO('I am not a file')
        non_file.fileno = lambda: -1

        # the error raised is different on Windows
        if is_platform_windows():
            msg = "The parameter is incorrect"
            err = OSError
        else:
            msg = "[Errno 22]"
            err = mmap.error

        with pytest.raises(err, match=msg):
            icom.MMapWrapper(non_file)

        target = open(mmap_file, 'r')
        target.close()

        msg = "I/O operation on closed file"
        with pytest.raises(ValueError, match=msg):
            icom.MMapWrapper(target) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_common.py

示例2: get_size

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import error [as 别名]
def get_size(fileobj):
    """Returns the size of the file.
    The position when passed in will be preserved if no error occurs.

    Args:
        fileobj (fileobj)
    Returns:
        int: The size of the file
    Raises:
        IOError
    """

    old_pos = fileobj.tell()
    try:
        fileobj.seek(0, 2)
        return fileobj.tell()
    finally:
        fileobj.seek(old_pos, 0) 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:20,代码来源:_util.py

示例3: read_full

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import error [as 别名]
def read_full(fileobj, size):
    """Like fileobj.read but raises IOError if not all requested data is
    returned.

    If you want to distinguish IOError and the EOS case, better handle
    the error yourself instead of using this.

    Args:
        fileobj (fileobj)
        size (int): amount of bytes to read
    Raises:
        IOError: In case read fails or not enough data is read
    """

    if size < 0:
        raise ValueError("size must not be negative")

    data = fileobj.read(size)
    if len(data) != size:
        raise IOError
    return data 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:23,代码来源:_util.py

示例4: test_constructor_bad_file

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import error [as 别名]
def test_constructor_bad_file(self, mmap_file):
        non_file = StringIO('I am not a file')
        non_file.fileno = lambda: -1

        # the error raised is different on Windows
        if is_platform_windows():
            msg = "The parameter is incorrect"
            err = OSError
        else:
            msg = "[Errno 22]"
            err = mmap.error

        tm.assert_raises_regex(err, msg, common.MMapWrapper, non_file)

        target = open(mmap_file, 'r')
        target.close()

        msg = "I/O operation on closed file"
        tm.assert_raises_regex(
            ValueError, msg, common.MMapWrapper, target) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:test_common.py

示例5: test_constructor_bad_file

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import error [as 别名]
def test_constructor_bad_file(self):
        non_file = StringIO('I am not a file')
        non_file.fileno = lambda: -1

        # the error raised is different on Windows
        if is_platform_windows():
            msg = "The parameter is incorrect"
            err = OSError
        else:
            msg = "[Errno 22]"
            err = mmap.error

        tm.assert_raises_regex(err, msg, common.MMapWrapper, non_file)

        target = open(self.mmap_file, 'r')
        target.close()

        msg = "I/O operation on closed file"
        tm.assert_raises_regex(
            ValueError, msg, common.MMapWrapper, target) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:22,代码来源:test_common.py

示例6: insert_bytes

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import error [as 别名]
def insert_bytes(fobj, size, offset, BUFFER_SIZE=2 ** 16):
    """Insert size bytes of empty space starting at offset.

    fobj must be an open file object, open rb+ or
    equivalent. Mutagen tries to use mmap to resize the file, but
    falls back to a significantly slower method if mmap fails.

    Args:
        fobj (fileobj)
        size (int): The amount of space to insert
        offset (int): The offset at which to insert the space
    Raises:
        IOError
    """

    if size < 0 or offset < 0:
        raise ValueError

    fobj.seek(0, 2)
    filesize = fobj.tell()
    movesize = filesize - offset

    if movesize < 0:
        raise ValueError

    resize_file(fobj, size, BUFFER_SIZE)

    if mmap is not None:
        try:
            mmap_move(fobj, offset + size, offset, movesize)
        except mmap.error:
            fallback_move(fobj, offset + size, offset, movesize, BUFFER_SIZE)
    else:
        fallback_move(fobj, offset + size, offset, movesize, BUFFER_SIZE) 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:36,代码来源:_util.py

示例7: delete_bytes

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import error [as 别名]
def delete_bytes(fobj, size, offset, BUFFER_SIZE=2 ** 16):
    """Delete size bytes of empty space starting at offset.

    fobj must be an open file object, open rb+ or
    equivalent. Mutagen tries to use mmap to resize the file, but
    falls back to a significantly slower method if mmap fails.

    Args:
        fobj (fileobj)
        size (int): The amount of space to delete
        offset (int): The start of the space to delete
    Raises:
        IOError
    """

    if size < 0 or offset < 0:
        raise ValueError

    fobj.seek(0, 2)
    filesize = fobj.tell()
    movesize = filesize - offset - size

    if movesize < 0:
        raise ValueError

    if mmap is not None:
        try:
            mmap_move(fobj, offset, offset + size, movesize)
        except mmap.error:
            fallback_move(fobj, offset, offset + size, movesize, BUFFER_SIZE)
    else:
        fallback_move(fobj, offset, offset + size, movesize, BUFFER_SIZE)

    resize_file(fobj, -size, BUFFER_SIZE) 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:36,代码来源:_util.py

示例8: mmapwrapper

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import error [as 别名]
def mmapwrapper(*args, **kwargs):
    """
    Python's mmap call sucks and ommitted the "offset" argument for no
    discernable reason. Replace this with a mmap module that has offset.
    """

    offset = kwargs.get('offset', None)
    if offset in [None, 0]:
        if 'offset' in kwargs:
            del kwargs['offset']
    else:
        raise mmap.error("mmap: Python sucks and does not support offset.")
    return mmap.mmap(*args, **kwargs) 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:15,代码来源:stream.py

示例9: connectionMade

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import error [as 别名]
def connectionMade(self):
        p = StreamProducer(self.inputStream)
        # if the process stopped reading from the input stream,
        # this is not an error condition, so it oughtn't result
        # in a ConnectionLost() from the input stream:
        p.stopProducing = lambda err = None: StreamProducer.stopProducing(p, err)

        d = p.beginProducing(self.transport)
        d.addCallbacks(lambda _: self.transport.closeStdin(),
                       self._inputError) 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:12,代码来源:stream.py

示例10: mmap_move

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import error [as 别名]
def mmap_move(fileobj, dest, src, count):
    """Mmaps the file object if possible and moves 'count' data
    from 'src' to 'dest'. All data has to be inside the file size
    (enlarging the file through this function isn't possible)

    Will adjust the file offset.

    Args:
        fileobj (fileobj)
        dest (int): The destination offset
        src (int): The source offset
        count (int) The amount of data to move
    Raises:
        mmap.error: In case move failed
        IOError: In case an operation on the fileobj fails
        ValueError: In case invalid parameters were given
    """

    assert mmap is not None, "no mmap support"

    if dest < 0 or src < 0 or count < 0:
        raise ValueError("Invalid parameters")

    try:
        fileno = fileobj.fileno()
    except (AttributeError, IOError):
        raise mmap.error(
            "File object does not expose/support a file descriptor")

    fileobj.seek(0, 2)
    filesize = fileobj.tell()
    length = max(dest, src) + count

    if length > filesize:
        raise ValueError("Not in file size boundary")

    offset = ((min(dest, src) // mmap.ALLOCATIONGRANULARITY) *
              mmap.ALLOCATIONGRANULARITY)
    assert dest >= offset
    assert src >= offset
    assert offset % mmap.ALLOCATIONGRANULARITY == 0

    # Windows doesn't handle empty mappings, add a fast path here instead
    if count == 0:
        return

    # fast path
    if src == dest:
        return

    fileobj.flush()
    file_map = mmap.mmap(fileno, length - offset, offset=offset)
    try:
        file_map.move(dest - offset, src - offset, count)
    finally:
        file_map.close() 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:58,代码来源:_util.py

示例11: read

# 需要导入模块: import mmap [as 别名]
# 或者: from mmap import error [as 别名]
def read(self, sendfile=False):
        if self.f is None:
            return None

        length = self.length
        if length == 0:
            self.f = None
            return None

        # if sendfile and length > SENDFILE_THRESHOLD:
        #    # XXX: Yay using non-existent sendfile support!
        #    # FIXME: if we return a SendfileBuffer, and then sendfile
        #    #        fails, then what? Or, what if file is too short?
        #    readSize = min(length, SENDFILE_LIMIT)
        #    res = SendfileBuffer(self.f, self.start, readSize)
        #    self.length -= readSize
        #    self.start += readSize
        #    return res

        if self.useMMap and length > MMAP_THRESHOLD:
            readSize = min(length, MMAP_LIMIT)
            try:
                res = mmapwrapper(self.f.fileno(), readSize,
                                  access=mmap.ACCESS_READ, offset=self.start)
                # madvise(res, MADV_SEQUENTIAL)
                self.length -= readSize
                self.start += readSize
                return res
            except mmap.error:
                pass

        # Fall back to standard read.
        readSize = min(length, self.CHUNK_SIZE)

        self.f.seek(self.start)
        b = self.f.read(readSize)
        bytesRead = len(b)
        if not bytesRead:
            raise RuntimeError("Ran out of data reading file %r, expected %d more bytes" % (self.f, length))
        else:
            self.length -= bytesRead
            self.start += bytesRead
            return b 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:45,代码来源:stream.py


注:本文中的mmap.error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。