#
# This file was generated from the asynchronous client at streams/stdin.py by generate_synchronous_client.sh
# Do not edit this file directly, instead edit the original file and regenerate this file.
#


"""Data source that reads data from standard input."""

from pathlib import Path

from .base import DataSource, InputStream
from .os import open_file


class StdInDataSource(DataSource):
    """A data source that reads data from standard input."""

    def __init__(self) -> None:
        super().__init__()
        self._opened = False

    def open(self, offset: int = 0, count: int | None = None) -> InputStream:
        """Open the data source for reading."""
        if self._opened:
            raise RuntimeError("Cannot open the same data source multiple times.")
        self._opened = True
        if count is not None:
            raise ValueError("Cannot read a bounded stream from standard input.")
        if offset != 0:
            raise ValueError("Cannot seek in standard input.")
        ret = open_file(Path("/sys/stdin"), mode="rb")
        return ret

    def size(self) -> int:
        """Return the size of the data - in this case -1 as unknown."""
        return -1

    def content_type(self) -> str:
        """Return the content type of the data."""
        return "application/octet-stream"

    def close(self) -> None:
        """Close the data source."""
        pass

    def checksum(
        self, algo: str = "md5", offset: int = 0, count: int | None = None
    ) -> str:
        raise NotImplementedError("Checksums are not supported for standard input.")

    def supported_checksums(self) -> list[str]:
        """Return a list of supported checksum algorithms."""
        return []

