def yaml_format(obj, indent=0):
    '\n    Pretty formats the given object as a YAML string which is returned.\n    (based on TLObject.pretty_format)\n    '
    result = []
    if isinstance(obj, TLObject):
        obj = obj.to_dict()
    if isinstance(obj, dict):
        result.append((obj.get('_', 'dict') + ':'))
        if obj:
            items = obj.items()
            has_multiple_items = (len(items) > 2)
            if has_multiple_items:
                result.append('\n')
            indent += 2
            for (k, v) in items:
                if ((k == '_') or (v is None)):
                    continue
                formatted = yaml_format(v, indent)
                if (not formatted.strip()):
                    continue
                result.append((' ' * (indent if has_multiple_items else 1)))
                result.append(f'{k}: {formatted}')
                result.append('\n')
            result.pop()
            indent -= 2
            result.append((' ' * indent))
    elif isinstance(obj, str):
        result.append(repr(obj[:STR_LEN_MAX]))
        if (len(obj) > STR_LEN_MAX):
            result.append('…')
    elif isinstance(obj, bytes):
        if all(((c in PRINTABLE_SET) for c in obj)):
            result.append(repr(obj))
        elif (len(obj) > BYTE_LEN_MAX):
            result.append('<…>')
        else:
            result.append(' '.join((f'{b:02X}' for b in obj)))
    elif isinstance(obj, datetime.datetime):
        result.append(obj.strftime('%Y-%m-%d %H:%M:%S'))
    elif hasattr(obj, '__iter__'):
        result.append('\n')
        indent += 2
        for x in obj:
            result.append((' ' * indent))
            result.append(yaml_format(x, indent))
            result.append('\n')
        result.pop()
        indent -= 2
        result.append((' ' * indent))
    else:
        result.append(repr(obj))
    return ''.join(result)
Pretty formats the given object as a YAML string which is returned.
(based on TLObject.pretty_format)
def yaml_format(obj, indent=0):
    '\n    Pretty formats the given object as a YAML string which is returned.\n    (based on TLObject.pretty_format)\n    '
    result = []
    if isinstance(obj, TLObject):
        obj = obj.to_dict()
    if isinstance(obj, dict):
        result.append((obj.get('_', 'dict') + ':'))
        if obj:
            items = obj.items()
            has_multiple_items = (len(items) > 2)
            if has_multiple_items:
                result.append('\n')
            indent += 2
            for (k, v) in items:
                if ((k == '_') or (v is None)):
                    continue
                formatted = yaml_format(v, indent)
                if (not formatted.strip()):
                    continue
                result.append((' ' * (indent if has_multiple_items else 1)))
                result.append(f'{k}: {formatted}')
                result.append('\n')
            result.pop()
            indent -= 2
            result.append((' ' * indent))
    elif isinstance(obj, str):
        result.append(repr(obj[:STR_LEN_MAX]))
        if (len(obj) > STR_LEN_MAX):
            result.append('…')
    elif isinstance(obj, bytes):
        if all(((c in PRINTABLE_SET) for c in obj)):
            result.append(repr(obj))
        elif (len(obj) > BYTE_LEN_MAX):
            result.append('<…>')
        else:
            result.append(' '.join((f'{b:02X}' for b in obj)))
    elif isinstance(obj, datetime.datetime):
        result.append(obj.strftime('%Y-%m-%d %H:%M:%S'))
    elif hasattr(obj, '__iter__'):
        result.append('\n')
        indent += 2
        for x in obj:
            result.append((' ' * indent))
            result.append(yaml_format(x, indent))
            result.append('\n')
        result.pop()
        indent -= 2
        result.append((' ' * indent))
    else:
        result.append(repr(obj))
    return .join(result)