當前位置: 首頁>>代碼示例>>Python>>正文


Python BinaryIO.seekable方法代碼示例

本文整理匯總了Python中typing.BinaryIO.seekable方法的典型用法代碼示例。如果您正苦於以下問題:Python BinaryIO.seekable方法的具體用法?Python BinaryIO.seekable怎麽用?Python BinaryIO.seekable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在typing.BinaryIO的用法示例。


在下文中一共展示了BinaryIO.seekable方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: put

# 需要導入模塊: from typing import BinaryIO [as 別名]
# 或者: from typing.BinaryIO import seekable [as 別名]
    def put(
        self, namespace: str, metadata: Dict[str, Any], bytes_io: BinaryIO,
    ) -> None:
        """Store a file."""
        subset = dict_subset(metadata, lambda k, v: k in (
            # We are not storing the 'file_name'
            'image_width', 'image_height', 'original_id', 'version'))
        self._convert_values_to_str(subset)
        if hasattr(bytes_io, 'seekable') and bytes_io.seekable():
            bytes_io.seek(0)

        # When botocore.response.StreamingBody is passed in as bytes_io,
        # the bucket.put_object() call below fails with
        # "AttributeError: 'StreamingBody' object has no attribute 'tell'"
        # so we have to read the stream, getting the bytes:
        if not hasattr(bytes_io, 'tell'):
            bytes_io = bytes_io.read()  # type: ignore

        result = self.bucket.put_object(
            Key=self._get_path(namespace, metadata),
            # done automatically by botocore:  ContentMD5=encoded_md5,
            ContentType=metadata['mime_type'],
            ContentLength=metadata['length'], Body=bytes_io, Metadata=subset)
        # print(result)
        return result
開發者ID:nandoflorestan,項目名稱:keepluggable,代碼行數:27,代碼來源:amazon_s3.py


注:本文中的typing.BinaryIO.seekable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。