本文整理汇总了Python中_pyio.BufferedReader方法的典型用法代码示例。如果您正苦于以下问题:Python _pyio.BufferedReader方法的具体用法?Python _pyio.BufferedReader怎么用?Python _pyio.BufferedReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_pyio
的用法示例。
在下文中一共展示了_pyio.BufferedReader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BufferedReader [as 别名]
def get(self, file_id):
path = self._files.get_file_id_path(file_id)
try:
file_stream = self._storage.stream_read_file(self._locations, path)
buffered = BufferedReader(file_stream)
file_header_bytes = buffered.peek(1024)
buffered.seek(0)
return send_file(
buffered,
mimetype=self._magic.from_buffer(file_header_bytes),
as_attachment=True,
attachment_filename=file_id,
)
except IOError:
logger.exception("Error reading user file")
abort(404)
示例2: CP_makefile
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BufferedReader [as 别名]
def CP_makefile(sock, mode='r', bufsize=DEFAULT_BUFFER_SIZE):
if 'r' in mode:
return io.BufferedReader(socket.SocketIO(sock, mode), bufsize)
else:
return CP_BufferedWriter(socket.SocketIO(sock, mode), bufsize)
示例3: test_with_bufferedreader
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BufferedReader [as 别名]
def test_with_bufferedreader():
with GeneratorFile(sample_generator()) as f:
buffered = BufferedReader(f)
assert buffered.peek(10) == b"thisisatest"
assert buffered.read(10) == b"thisisates"
示例4: test_magic
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BufferedReader [as 别名]
def test_magic():
mgc = magic.Magic(mime=True)
with GeneratorFile(mimed_html_generator()) as f:
buffered = BufferedReader(f)
file_header_bytes = buffered.peek(1024)
assert mgc.from_buffer(file_header_bytes) == "text/html"
with GeneratorFile(sample_generator()) as f:
buffered = BufferedReader(f)
file_header_bytes = buffered.peek(1024)
assert mgc.from_buffer(file_header_bytes) == "text/plain"
示例5: _stream_upload_segment
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BufferedReader [as 别名]
def _stream_upload_segment(self, uuid, offset, length, in_fp, storage_metadata, content_type):
updated_metadata = copy.deepcopy(storage_metadata)
segment_count = len(updated_metadata[_SEGMENTS_KEY])
segment_path = "%s/%s/%s" % (_SEGMENT_DIRECTORY, uuid, "%09d" % segment_count)
# Track the number of bytes read and if an explicit length is specified, limit the
# file stream to that length.
if length == filelike.READ_UNTIL_END:
length = _MAXIMUM_SEGMENT_SIZE
else:
length = min(_MAXIMUM_SEGMENT_SIZE, length)
limiting_fp = filelike.LimitingStream(in_fp, length)
# If retries are requested, then we need to use a buffered reader to allow for calls to
# seek() on retries from within the Swift client.
if self._retry_count > 0:
limiting_fp = BufferedReader(limiting_fp, buffer_size=length)
# Write the segment to Swift.
self.stream_write(segment_path, limiting_fp, content_type)
# We are only going to track keys to which data was confirmed written.
bytes_written = limiting_fp.tell()
if bytes_written > 0:
updated_metadata[_SEGMENTS_KEY].append(
_PartUploadMetadata(segment_path, offset, bytes_written)
)
else:
updated_metadata[_EMPTY_SEGMENTS_KEY].append(
_PartUploadMetadata(segment_path, offset, bytes_written)
)
return bytes_written, updated_metadata
示例6: CP_makefile_PY3
# 需要导入模块: import _pyio [as 别名]
# 或者: from _pyio import BufferedReader [as 别名]
def CP_makefile_PY3(sock, mode='r', bufsize=DEFAULT_BUFFER_SIZE):
if 'r' in mode:
return io.BufferedReader(socket.SocketIO(sock, mode), bufsize)
else:
return CP_BufferedWriter(socket.SocketIO(sock, mode), bufsize)