cheesechaser.pipe.image

This module provides image processing pipes for retrieving and handling image resources.

It includes two main classes:

  1. SimpleImagePipe: For retrieving single image files.

  2. DataAttachedImagePipe: For retrieving image files along with associated JSON data.

These pipes work with a resource pool to mock and access resources, and handle various scenarios such as missing files, multiple files, and attached data.

The module also defines a DataAttachedImage dataclass to represent images with optional associated data.

Usage:
>>> from cheesechaser.pipe import SimpleImagePipe, DataAttachedImagePipe
>>>
>>> # Create and use a SimpleImagePipe
>>> simple_pipe = SimpleImagePipe(pool)
>>> image = simple_pipe.retrieve(resource_id, resource_metainfo)
>>>
>>> # Create and use a DataAttachedImagePipe
>>> data_pipe = DataAttachedImagePipe(pool)
>>> image_with_data = data_pipe.retrieve(resource_id, resource_metainfo)

SimpleImagePipe

class cheesechaser.pipe.image.SimpleImagePipe(pool: DataPool)[source]

A pipe for retrieving single image files from a resource pool.

This pipe searches for image files in the given resource, opens the first found image file, and returns it as a PIL Image object.

Raises:
retrieve(resource_id, resource_metainfo)[source]

Retrieve an image from the resource pool.

Parameters:
  • resource_id – The identifier of the resource to retrieve.

  • resource_metainfo – Metadata information about the resource.

Returns:

A PIL Image object of the retrieved image.

Return type:

PIL.Image.Image

Raises:

DataAttachedImage

class cheesechaser.pipe.image.DataAttachedImage(image: Image, data: dict | None)[source]

A dataclass representing an image with optional attached data.

Parameters:
  • image – The PIL Image object.

  • data – Optional dictionary containing additional data associated with the image.

__eq__(other)

Return self==value.

__hash__ = None
__init__(image: Image, data: dict | None) None
__repr__()

Return repr(self).

__weakref__

list of weak references to the object (if defined)

DataAttachedImagePipe

class cheesechaser.pipe.image.DataAttachedImagePipe(pool: DataPool)[source]

A pipe for retrieving image files along with associated JSON data from a resource pool.

This pipe searches for an image file and an optional JSON file in the given resource. It returns a DataAttachedImage object containing the image and any associated data.

Raises:
retrieve(resource_id, resource_metainfo)[source]

Retrieve an image and its associated data from the resource pool.

Parameters:
  • resource_id – The identifier of the resource to retrieve.

  • resource_metainfo – Metadata information about the resource.

Returns:

A DataAttachedImage object containing the image and any associated data.

Return type:

DataAttachedImage

Raises: