utils.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:tecken 作者: mozilla-services 项目源码 文件源码
def key_existing(client, bucket, key):
    """return a tuple of (
        key's size if it exists or 0,
        S3 key metadata
    )
    If the file doesn't exist, return None for the metadata.
    """
    # Return 0 if the key can't be found so the memoize cache can cope
    try:
        response = client.head_object(
            Bucket=bucket,
            Key=key,
        )
        return response['ContentLength'], response.get('Metadata')
    except ClientError as exception:
        if exception.response['Error']['Code'] == '404':
            return 0, None
        raise
    except (ReadTimeout, socket.timeout) as exception:
        logger.info(
            f'ReadTimeout trying to list_objects_v2 for {bucket}:'
            f'{key} ({exception})'
        )
        return 0, None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号