:py:mod:`flow.record.utils` =========================== .. py:module:: flow.record.utils Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: flow.record.utils.EventHandler Functions ~~~~~~~~~ .. autoapisummary:: :nosignatures: flow.record.utils.get_stdout flow.record.utils.get_stdin flow.record.utils.is_stdout flow.record.utils.to_bytes flow.record.utils.to_str flow.record.utils.to_native_str flow.record.utils.to_base64 flow.record.utils.catch_sigpipe flow.record.utils.boolean_argument Attributes ~~~~~~~~~~ .. autoapisummary:: flow.record.utils.LOGGING_TRACE_LEVEL .. py:data:: LOGGING_TRACE_LEVEL :value: 5 .. py:function:: get_stdout(binary: bool = False) -> TextIO | BinaryIO Return the stdout stream as binary or text stream. This function is the preferred way to get the stdout stream in flow.record. :param binary: Whether to return the stream as binary stream. :returns: The stdout stream. .. py:function:: get_stdin(binary: bool = False) -> TextIO | BinaryIO Return the stdin stream as binary or text stream. This function is the preferred way to get the stdin stream in flow.record. :param binary: Whether to return the stream as binary stream. :returns: The stdin stream. .. py:function:: is_stdout(fp: TextIO | BinaryIO) -> bool Returns True if ``fp`` is the stdout stream. .. py:function:: to_bytes(value: Any) -> bytes Convert a value to a byte string. .. py:function:: to_str(value: Any) -> str Convert a value to a unicode string. .. py:function:: to_native_str(value: str) -> str .. py:function:: to_base64(value: str) -> str Convert a value to a base64 string. .. py:function:: catch_sigpipe(func: collections.abc.Callable[Ellipsis, int]) -> collections.abc.Callable[Ellipsis, int] Catches KeyboardInterrupt and BrokenPipeError (OSError 22 on Windows). .. py:class:: EventHandler .. py:attribute:: handlers :value: [] .. py:method:: add_handler(callback: collections.abc.Callable[Ellipsis, None]) -> None .. py:method:: remove_handler(callback: collections.abc.Callable[Ellipsis, None]) -> None .. py:method:: __call__(*args, **kwargs) -> None .. py:function:: boolean_argument(value: str | bool | int) -> bool Convert a string, boolean, or integer to a boolean value. This function interprets various string representations of boolean values, such as "true", "false", "1", "0", "yes", "no". It also accepts boolean and integer values directly. :param value: The value to convert. Can be a string, boolean, or integer. :returns: The converted boolean value. :rtype: bool :raises ValueError: If the value cannot be interpreted as a boolean.