taolib.testing.file_storage.processing.protocols#

文件处理协议定义。

定义文件验证和缩略图生成的 Protocol 接口。

Classes#

FileValidationResult

文件验证结果。

ThumbnailOutput

缩略图生成输出。

FileValidatorProtocol

文件验证器协议。

ThumbnailGeneratorProtocol

缩略图生成器协议。

Module Contents#

class taolib.testing.file_storage.processing.protocols.FileValidationResult#

文件验证结果。

valid: bool#
errors: list[str] = []#
detected_content_type: str = ''#
media_type: taolib.testing.file_storage.models.enums.MediaType#
class taolib.testing.file_storage.processing.protocols.ThumbnailOutput#

缩略图生成输出。

size: taolib.testing.file_storage.models.enums.ThumbnailSize#
width: int#
height: int#
data: bytes#
content_type: str = 'image/webp'#
class taolib.testing.file_storage.processing.protocols.FileValidatorProtocol#

Bases: Protocol

文件验证器协议。

async validate(filename: str, declared_content_type: str, size_bytes: int, header_bytes: bytes, allowed_mime_types: list[str] | None = None, max_file_size_bytes: int | None = None) FileValidationResult#

验证文件。

参数:
  • filename -- 文件名

  • declared_content_type -- 声明的 MIME 类型

  • size_bytes -- 文件大小

  • header_bytes -- 文件头部字节(用于 magic byte 检测)

  • allowed_mime_types -- 允许的 MIME 类型列表(None 表示全部允许)

  • max_file_size_bytes -- 最大文件大小(None 表示不限制)

返回:

验证结果

class taolib.testing.file_storage.processing.protocols.ThumbnailGeneratorProtocol#

Bases: Protocol

缩略图生成器协议。

supports(content_type: str) bool#

检查是否支持该内容类型的缩略图生成。

async generate(source_data: bytes, content_type: str, sizes: list[taolib.testing.file_storage.models.enums.ThumbnailSize] | None = None) list[ThumbnailOutput]#

生成缩略图。

参数:
  • source_data -- 原始图片数据

  • content_type -- MIME 类型

  • sizes -- 要生成的尺寸列表(None 表示全部规格)

返回:

缩略图输出列表