Skip to content

for console redirection from mako-render with python2 #271

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot

Migrated issue, originally created by Patate Tomate (@patatetom)

input can be changed with ## -- coding: utf-8 -- :-)
but nothing for changing output :-(

         "template is read from stdin, the value defaults to be "
         "the current directory, otherwise it defaults to be the "
         "parent directory of the file provided.")
+    parser.add_argument(
+        "--output-encoding", default=None,
+        help="force output encoding")
     parser.add_argument('input', nargs='?', default='-')
 
     options = parser.parse_args(argv)
+
+    output_encoding = options.output_encoding
+
     if options.input == '-':
         lookup_dirs = options.template_dir or ["."]
         lookup = TemplateLookup(lookup_dirs)
         try:
-            template = Template(sys.stdin.read(), lookup=lookup)
+            template = Template(sys.stdin.read(), lookup=lookup, output_encoding=output_encoding)
         except:
             _exit()
     else:
@@ -52,7 +58,7 @@ def cmdline(argv=None):
         lookup_dirs = options.template_dir or [dirname(filename)]
         lookup = TemplateLookup(lookup_dirs)
         try:
-            template = Template(filename=filename, lookup=lookup)
+            template = Template(filename=filename, lookup=lookup, output_encoding=output_encoding)
         except:
             _exit()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions