Skip to content

When the output file is - use write instead of print #42

@cipriancraciun

Description

@cipriancraciun

If one uses --output -, the current ashes code uses print(output_text) which writes the representation of the bytes in Python syntax (i.e. b'<...\t\t...') as opposed to the actual text.

Instead of print(output_text) one could use sys.stdout.write(output_bytes).

The following simple patch solves this issue:

@@ -2664,21 +2664,21 @@ def _simple_render(template_path, template_literal, env_path_list,
         raise CLIError('expected model or model literal')
     elif model_path == '-':
         model = json.load(sys.stdin)
     else:
         with open(model_path) as f:
             model = json.load(f)
 
     output_text = tmpl_obj.render(model)
     output_bytes = output_text.encode(output_encoding)
     if output_path == '-':
-        print(output_bytes)
+        sys.stdout.write(output_text)
     else:
         with open(output_path, 'wb') as f:
             f.write(output_bytes)
     return
 
 
 def main():
     # using optparse for backwards compat with 2.6 (and earlier, maybe)
     from optparse import OptionParser
 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions