本文整理匯總了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)