# Path: asciinema/asciicast/events.py
# def to_absolute_time(
#     events: Generator[List[Any], None, None]
# ) -> Generator[List[Any], None, None]:
#     time = 0
# 
#     for frame in events:
#         delay, type_, data = frame
#         time = time + delay
#         yield [time, type_, data]


import json
from codecs import StreamReader
from json.decoder import JSONDecodeError
from typing import Any, Dict, Generator, List, Optional, TextIO, Union
from .events import to_absolute_time
    @property
    def v2_header(self) -> Dict[str, Any]:
        keys = ["width", "height", "duration", "command", "title", "env"]
        header = {
            k: v
            for k, v in self.__attrs.items()
            if k in keys and v is not None
        }
        return header

    def __stdout_events(self) -> Generator[List[Any], None, None]:
        for time, data in self.__attrs["stdout"]:
            yield [time, "o", data]

    def events(self) -> Any:
        return self.stdout_events()

    def stdout_events(self) -> Generator[List[Any], None, None]:
        return to_absolute_time(self.__stdout_events())


class open_from_file:
    FORMAT_ERROR: str = "only asciicast v1 format can be opened"

    def __init__(
        self, first_line: str, file: Union[TextIO, StreamReader]
    ) -> None:
        self.first_line = first_line
        self.file = file


# Path: asciinema/asciicast/events.py
# def to_absolute_time(
#     events: Generator[List[Any], None, None]
# ) -> Generator[List[Any], None, None]:
#     time = 0
# 
#     for frame in events:
#         delay, type_, data = frame
#         time = time + delay
#         yield [time, type_, data]


# Path: asciinema/asciicast/v1.py
import json
from codecs import StreamReader
from json.decoder import JSONDecodeError
from typing import Any, Dict, Generator, List, Optional, TextIO, Union
from .events import to_absolute_time

    @property
    def v2_header(self) -> Dict[str, Any]:
        keys = ["width", "height", "duration", "command", "title", "env"]
        header = {
            k: v
            for k, v in self.__attrs.items()
            if k in keys and v is not None
        }
        return header

    def __stdout_events(self) -> Generator[List[Any], None, None]:
        for time, data in self.__attrs["stdout"]:
            yield [time, "o", data]

    def events(self) -> Any:
        return self.stdout_events()

    def stdout_events(self) -> Generator[List[Any], None, None]:
        return to_absolute_time(self.__stdout_events())


class open_from_file:
    FORMAT_ERROR: str = "only asciicast v1 format can be opened"

    def __init__(
        self, first_line: str, file: Union[TextIO, StreamReader]
    ) -> None:
        self.first_line = first_line
        self.file = file


    def __enter__(self) -> Optional[Asciicast]: