本文整理汇总了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)
示例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
示例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)
示例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
示例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
示例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
示例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()
示例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
示例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()
示例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
示例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
示例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
示例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()
示例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
示例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