Ejemplo n.º 1
0
def repr_str(dumper: Dumper, data: str) -> str:
    """A YAML Representer that handles strings, breaking multi-line strings into something a lot
    more readable in the yaml output. This is useful for representing long, multiline strings in
    templates or in stack parameters.

    :param dumper: The Dumper that is being used to serialize this object
    :param data: The string to serialize
    :return: The represented string
    """
    if '\n' in data:
        return dumper.represent_scalar(u'tag:yaml.org,2002:str', data, style='|')
    return dumper.represent_str(data)
Ejemplo n.º 2
0
def bytes_representer(dumper: yaml.Dumper, obj):
    try:
        return dumper.represent_str(obj.decode('utf-8'))
    except UnicodeError:
        return dumper.represent_str(binascii.hexlify(obj).decode('utf-8'))
Ejemplo n.º 3
0
def represent_granularity(dumper: yaml.Dumper, data: Granularity):
    return dumper.represent_str(data.value)
Ejemplo n.º 4
0
 def path_representer(dump: yaml.Dumper, dump_path: Path) -> str:
     """Representer that dum path objects to YAML"""
     return dump.represent_str(str(dump_path))
Ejemplo n.º 5
0
def _yaml_represent_datetime(dumper: yaml.Dumper,
                             data: bson.Decimal128) -> str:
    string = DATETIME_FIELD._serialize(data, "none", SpanJSONEncoder.EMPTY)
    return dumper.represent_str(string)
Ejemplo n.º 6
0
def _yaml_represent_decimal(dumper: yaml.Dumper, data: decimal.Decimal) -> str:
    string = str(data)
    return dumper.represent_str(string)
Ejemplo n.º 7
0
def _yaml_represent_uuid(dumper: yaml.Dumper, data: uuid.UUID) -> str:
    string = str(data)
    return dumper.represent_str(string)
Ejemplo n.º 8
0
def _yaml_represent_bytes(dumper: yaml.Dumper, data: bytes) -> str:
    string = data.hex()
    return dumper.represent_str(string)
Ejemplo n.º 9
0
def fraction_representer(dumper: yaml.Dumper, data: fractions.Fraction):
    return dumper.represent_str(str(data))