Exemplo n.º 1
0
def convert_robot_data_file(original_filepath):
    from robot.tidy import Tidy
    from base64 import b64encode

    tidy = Tidy(format='robot') if get_robot_version_num() < (3, 2) else Tidy()
    converted_content = tidy.file(original_filepath)

    if sys.version_info < (3, 0, 0):
        return b64encode(converted_content.encode('utf-8'))
    else:
        return str(b64encode(bytes(converted_content, 'utf-8')), 'utf-8')
Exemplo n.º 2
0
def robot_source_format(source, space_count=4):
    if not source.strip():
        return None

    from robot.tidy import Tidy

    t = Tidy(space_count=space_count)
    from io import StringIO

    s = StringIO()
    if isinstance(source, bytes):
        source = source.decode("utf-8", "replace")

    s.write(source)
    s.seek(0)
    formatted = t.file(s)
    if not formatted:
        return None

    return formatted