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


Python io.DEFAULT_BUFFER_SIZE属性代码示例

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


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

示例1: __init__

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def __init__(self, reader, writer,
                 buffer_size=DEFAULT_BUFFER_SIZE, max_buffer_size=None):
        """Constructor.

        The arguments are two RawIO instances.
        """
        if max_buffer_size is not None:
            warnings.warn("max_buffer_size is deprecated", DeprecationWarning, 2)

        if not reader.readable():
            raise IOError('"reader" argument must be readable.')

        if not writer.writable():
            raise IOError('"writer" argument must be writable.')

        self.reader = BufferedReader(reader, buffer_size)
        self.writer = BufferedWriter(writer, buffer_size) 
开发者ID:glmcdona,项目名称:meddle,代码行数:19,代码来源:_pyio.py

示例2: get_analysis_file

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def get_analysis_file(uuid, name, output_file=None, output_fp=None, *args, **kwargs):
    if output_file is None and output_fp is None:
        output_fp = sys.stdout.buffer
    elif output_fp is None:
        output_fp = open(output_file, 'wb')

    r = _execute_api_call('analysis/file/{}/{}'.format(uuid, name), stream=True, *args, **kwargs)
    
    size = 0
    for chunk in r.iter_content(io.DEFAULT_BUFFER_SIZE):
        if chunk:
            output_fp.write(chunk)
            size += len(chunk)

    if output_file is not None:
        output_fp.close()

    return True 
开发者ID:IntegralDefense,项目名称:ACE,代码行数:20,代码来源:ace_api.py

示例3: read

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def read(self, size):
    # TODO: Update this to use unconsumed_tail and a StringIO buffer
    # http://docs.python.org/2/library/zlib.html#zlib.Decompress.unconsumed_tail
    # Check if we need to start a new decoder
    if self.decoder and self.decoder.unused_data:
      self.restart_decoder()
    # Use unused data first
    if len(self.unused_buffer) > size:
      part = self.unused_buffer[:size]
      self.unused_buffer = self.unused_buffer[size:]
      return part
    # If the stream is finished and no unused raw data, return what we have
    if self.stream.closed or self.finished:
      self.finished = True
      buf, self.unused_buffer = self.unused_buffer, ''
      return buf
    # Otherwise consume new data
    raw = self.stream.read(io.DEFAULT_BUFFER_SIZE)
    if len(raw) > 0:
      self.unused_buffer += self.decoder.decompress(raw)
    else:
      self.finished = True
    return self.read(size) 
开发者ID:Smerity,项目名称:gzipstream,代码行数:25,代码来源:gzipstreamfile.py

示例4: test_new_with_params

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def test_new_with_params(self):
        mock_int_sentinel = MagicMock(__class__=int)
        mock_stream = MockEncryptionStream(
            source=self.mock_source_stream,
            key_provider=self.mock_key_provider,
            mock_read_bytes=sentinel.read_bytes,
            line_length=io.DEFAULT_BUFFER_SIZE,
            source_length=mock_int_sentinel,
        )

        assert mock_stream.config.source == self.mock_source_stream
        assert_prepped_stream_identity(mock_stream.config.source, object)
        assert mock_stream.config.key_provider is self.mock_key_provider
        assert mock_stream.config.mock_read_bytes is sentinel.read_bytes
        assert mock_stream.config.line_length == io.DEFAULT_BUFFER_SIZE
        assert mock_stream.config.source_length is mock_int_sentinel

        assert mock_stream.bytes_read == 0
        assert mock_stream.output_buffer == b""
        assert not mock_stream._message_prepped
        assert mock_stream.source_stream == self.mock_source_stream
        assert_prepped_stream_identity(mock_stream.source_stream, object)
        assert mock_stream._stream_length is mock_int_sentinel
        assert mock_stream.line_length == io.DEFAULT_BUFFER_SIZE 
开发者ID:aws,项目名称:aws-encryption-sdk-python,代码行数:26,代码来源:test_streaming_client_encryption_stream.py

示例5: __init__

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def __init__(self, filepath, mode='wb', buffer_size=io.DEFAULT_BUFFER_SIZE, backup_filepath=None):
        """ファイルパスを指定して初期化します。
        backup_filepath に None 以外が指定された場合、書き込み完了時に
        バックアップファイルが作成されます。
        """
        dirpath, filename = os.path.split(filepath)
        fd, temppath = tempfile.mkstemp(prefix=filename + '.', dir=dirpath)
        try:
            fh = os.fdopen(fd, mode)
            super(TemporaryFileWriter, self).__init__(fh, buffer_size)
        except:
            if fh:
                fh.close()
            os.remove(temppath)
            raise
        self.__filepath = filepath
        self.__temppath = temppath
        self.backup_filepath = backup_filepath 
开发者ID:CM3D2user,项目名称:Blender-CM3D2-Converter,代码行数:20,代码来源:fileutil.py

示例6: __init__

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def __init__(self, fp, length, maxbytes, bufsize=DEFAULT_BUFFER_SIZE,
                 has_trailers=False):
        # Wrap our fp in a buffer so peek() works
        self.fp = fp
        self.length = length
        self.maxbytes = maxbytes
        self.buffer = b''
        self.bufsize = bufsize
        self.bytes_read = 0
        self.done = False
        self.has_trailers = has_trailers 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:13,代码来源:_cpreqbody.py

示例7: compute_hash

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def compute_hash(filename, algorithm='md5', chunk_size=io.DEFAULT_BUFFER_SIZE):
    """ Compute the hash of a large file using hashlib """
    h = hashlib.new(algorithm)

    with io.open(filename, mode='rb') as fh:
        for chunk in iter(lambda: fh.read(chunk_size), b''):
            h.update(chunk)

    return h.hexdigest() 
开发者ID:pywr,项目名称:pywr,代码行数:11,代码来源:hashes.py

示例8: readall

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def readall(self):
        """Read until EOF, using multiple read() call."""
        res = bytearray()
        while True:
            data = self.read(DEFAULT_BUFFER_SIZE)
            if not data:
                break
            res += data
        if res:
            return bytes(res)
        else:
            # b'' or None
            return data 
开发者ID:war-and-code,项目名称:jawfish,代码行数:15,代码来源:_io.py

示例9: __init__

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE):
        """Create a new buffered reader using the given readable raw IO object.
        """
        if not raw.readable():
            raise IOError('"raw" argument must be readable.')

        _BufferedIOMixin.__init__(self, raw)
        if buffer_size <= 0:
            raise ValueError("invalid buffer size")
        self.buffer_size = buffer_size
        self._reset_read_buf()
        self._read_lock = Lock() 
开发者ID:war-and-code,项目名称:jawfish,代码行数:14,代码来源:_io.py

示例10: backport_makefile

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def backport_makefile(self, mode="r", buffering=None, encoding=None,
                      errors=None, newline=None):
    """
    Backport of ``socket.makefile`` from Python 3.5.
    """
    if not set(mode) <= {"r", "w", "b"}:
        raise ValueError(
            "invalid mode %r (only r, w, b allowed)" % (mode,)
        )
    writing = "w" in mode
    reading = "r" in mode or not writing
    assert reading or writing
    binary = "b" in mode
    rawmode = ""
    if reading:
        rawmode += "r"
    if writing:
        rawmode += "w"
    raw = SocketIO(self, rawmode)
    self._makefile_refs += 1
    if buffering is None:
        buffering = -1
    if buffering < 0:
        buffering = io.DEFAULT_BUFFER_SIZE
    if buffering == 0:
        if not binary:
            raise ValueError("unbuffered streams must be binary")
        return raw
    if reading and writing:
        buffer = io.BufferedRWPair(raw, raw, buffering)
    elif reading:
        buffer = io.BufferedReader(raw, buffering)
    else:
        assert writing
        buffer = io.BufferedWriter(raw, buffering)
    if binary:
        return buffer
    text = io.TextIOWrapper(buffer, encoding, errors, newline)
    text.mode = mode
    return text 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:42,代码来源:makefile.py

示例11: backport_makefile

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def backport_makefile(self, mode="r", buffering=None, encoding=None,
                      errors=None, newline=None):
    """
    Backport of ``socket.makefile`` from Python 3.5.
    """
    if not set(mode) <= set(["r", "w", "b"]):
        raise ValueError(
            "invalid mode %r (only r, w, b allowed)" % (mode,)
        )
    writing = "w" in mode
    reading = "r" in mode or not writing
    assert reading or writing
    binary = "b" in mode
    rawmode = ""
    if reading:
        rawmode += "r"
    if writing:
        rawmode += "w"
    raw = SocketIO(self, rawmode)
    self._makefile_refs += 1
    if buffering is None:
        buffering = -1
    if buffering < 0:
        buffering = io.DEFAULT_BUFFER_SIZE
    if buffering == 0:
        if not binary:
            raise ValueError("unbuffered streams must be binary")
        return raw
    if reading and writing:
        buffer = io.BufferedRWPair(raw, raw, buffering)
    elif reading:
        buffer = io.BufferedReader(raw, buffering)
    else:
        assert writing
        buffer = io.BufferedWriter(raw, buffering)
    if binary:
        return buffer
    text = io.TextIOWrapper(buffer, encoding, errors, newline)
    text.mode = mode
    return text 
开发者ID:getavalon,项目名称:core,代码行数:42,代码来源:makefile.py

示例12: read_chunks

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def read_chunks(file, size=io.DEFAULT_BUFFER_SIZE):
    """Yield pieces of data from a file-like object until EOF."""
    while True:
        chunk = file.read(size)
        if not chunk:
            break
        yield chunk 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:__init__.py

示例13: __init__

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def __init__(self, path, mode, autocommit=True, fs=None, **kwargs):
        self.path = path
        self.mode = mode
        self.fs = fs
        self.f = None
        self.autocommit = autocommit
        self.blocksize = io.DEFAULT_BUFFER_SIZE
        self._open() 
开发者ID:intake,项目名称:filesystem_spec,代码行数:10,代码来源:local.py

示例14: backport_makefile

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def backport_makefile(
    self, mode="r", buffering=None, encoding=None, errors=None, newline=None
):
    """
    Backport of ``socket.makefile`` from Python 3.5.
    """
    if not set(mode) <= {"r", "w", "b"}:
        raise ValueError("invalid mode %r (only r, w, b allowed)" % (mode,))
    writing = "w" in mode
    reading = "r" in mode or not writing
    assert reading or writing
    binary = "b" in mode
    rawmode = ""
    if reading:
        rawmode += "r"
    if writing:
        rawmode += "w"
    raw = SocketIO(self, rawmode)
    self._makefile_refs += 1
    if buffering is None:
        buffering = -1
    if buffering < 0:
        buffering = io.DEFAULT_BUFFER_SIZE
    if buffering == 0:
        if not binary:
            raise ValueError("unbuffered streams must be binary")
        return raw
    if reading and writing:
        buffer = io.BufferedRWPair(raw, raw, buffering)
    elif reading:
        buffer = io.BufferedReader(raw, buffering)
    else:
        assert writing
        buffer = io.BufferedWriter(raw, buffering)
    if binary:
        return buffer
    text = io.TextIOWrapper(buffer, encoding, errors, newline)
    text.mode = mode
    return text 
开发者ID:remg427,项目名称:misp42splunk,代码行数:41,代码来源:makefile.py

示例15: backport_makefile

# 需要导入模块: import io [as 别名]
# 或者: from io import DEFAULT_BUFFER_SIZE [as 别名]
def backport_makefile(self, mode="r", buffering=None, encoding=None,
                      errors=None, newline=None):
    """Backport of socket.makefile from Python 3.5."""
    if not set(mode) <= {"r", "w", "b"}:
        raise ValueError(
            "invalid mode {!r} (only r, w, b allowed)".format(mode)
        )
    writing = "w" in mode
    reading = "r" in mode or not writing
    assert reading or writing
    binary = "b" in mode
    rawmode = ""
    if reading:
        rawmode += "r"
    if writing:
        rawmode += "w"
    raw = SocketIO(self, rawmode)
    self._makefile_refs += 1
    if buffering is None:
        buffering = -1
    if buffering < 0:
        buffering = io.DEFAULT_BUFFER_SIZE
    if buffering == 0:
        if not binary:
            raise ValueError("unbuffered streams must be binary")
        return raw
    if reading and writing:
        buffer = io.BufferedRWPair(raw, raw, buffering)
    elif reading:
        buffer = io.BufferedReader(raw, buffering)
    else:
        assert writing
        buffer = io.BufferedWriter(raw, buffering)
    if binary:
        return buffer
    text = io.TextIOWrapper(buffer, encoding, errors, newline)
    text.mode = mode
    return text 
开发者ID:snowflakedb,项目名称:snowflake-connector-python,代码行数:40,代码来源:backport_makefile.py


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