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


Python _pyio.BufferedReader方法代码示例

本文整理汇总了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) 
开发者ID:quay,项目名称:quay,代码行数:18,代码来源:userfiles.py

示例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) 
开发者ID:exiahuang,项目名称:SalesforceXyTools,代码行数:7,代码来源:wsgiserver3.py

示例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" 
开发者ID:quay,项目名称:quay,代码行数:7,代码来源:test_generatorfile.py

示例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" 
开发者ID:quay,项目名称:quay,代码行数:14,代码来源:test_generatorfile.py

示例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 
开发者ID:quay,项目名称:quay,代码行数:36,代码来源:swift.py

示例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) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:7,代码来源:__init__.py


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