from typing import Any
from typing import TextIO
import io


def s3_wrap_body(body: Any) -> TextIO:
    """
    Wrap body returned by S3 GetObject to a valid TextIO
    """
    # Use _raw_stream (urllib3.response.HTTPResponse) because
    # boto3 wrapper does not implement full Binary I/O interface.
    raw = body._raw_stream
    # TextIOWrapper does not work with auto_close
    # https://urllib3.readthedocs.io/en/latest/user-guide.html#using-io-wrappers-with-response-content
    raw.auto_close = False
    return io.TextIOWrapper(raw, encoding="utf-8", newline="")