spdx_tools.spdx3.writer.console.console

 1# SPDX-FileCopyrightText: 2023 spdx contributors
 2#
 3# SPDX-License-Identifier: Apache-2.0
 4from enum import Enum
 5
 6from beartype.typing import Optional, TextIO, Union
 7
 8
 9def write_value(tag: str, value: Optional[Union[bool, str, dict, list, Enum]], out: TextIO, indent: bool = False):
10    """This function is duplicated from spdx_tools.spdx.writer.tagvalue.tag_value_writer_helper_functions
11    and slightly adapted to make indentation of output possible."""
12    if not value:
13        return
14    if isinstance(value, dict):
15        value = ", ".join([f"{tag}: ({key}: {val})" for key, val in value.items()])
16    if isinstance(value, list):
17        value = ", ".join([entry for entry in value])
18    if isinstance(value, Enum):
19        value = value.name
20    write_and_possibly_indent(f"{tag}: {value}", indent, out)
21
22
23def write_and_possibly_indent(text: str, indent: bool, out: TextIO):
24    if indent:
25        out.write(f"  {text}\n")
26    else:
27        out.write(f"{text}\n")
def write_value( tag: str, value: Union[bool, str, dict, list, enum.Enum, NoneType], out: <class 'TextIO'>, indent: bool = False):
10def write_value(tag: str, value: Optional[Union[bool, str, dict, list, Enum]], out: TextIO, indent: bool = False):
11    """This function is duplicated from spdx_tools.spdx.writer.tagvalue.tag_value_writer_helper_functions
12    and slightly adapted to make indentation of output possible."""
13    if not value:
14        return
15    if isinstance(value, dict):
16        value = ", ".join([f"{tag}: ({key}: {val})" for key, val in value.items()])
17    if isinstance(value, list):
18        value = ", ".join([entry for entry in value])
19    if isinstance(value, Enum):
20        value = value.name
21    write_and_possibly_indent(f"{tag}: {value}", indent, out)

This function is duplicated from spdx_tools.spdx.writer.tagvalue.tag_value_writer_helper_functions and slightly adapted to make indentation of output possible.

def write_and_possibly_indent(text: str, indent: bool, out: <class 'TextIO'>):
24def write_and_possibly_indent(text: str, indent: bool, out: TextIO):
25    if indent:
26        out.write(f"  {text}\n")
27    else:
28        out.write(f"{text}\n")