File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 11# coding=utf-8
22"""Utility functions for running the functions of CLI commands outside of the CLI."""
3+ import sys
34import os
45
56
@@ -49,11 +50,20 @@ def process_content_to_output(content_str, output_file=None):
4950 dir_name = os .path .dirname (os .path .abspath (output_file ))
5051 if not os .path .isdir (dir_name ):
5152 os .makedirs (dir_name )
52- with open (output_file , 'w' ) as of :
53- of .write (content_str )
53+ if (sys .version_info < (3 , 0 )): # we need to manually encode it as UTF-8
54+ with open (output_file , 'w' ) as of :
55+ of .write (content_str .encode ('utf-8' ))
56+ else :
57+ with open (output_file , 'w' , encoding = 'utf-8' ) as of :
58+ of .write (content_str )
5459 else :
5560 if 'stdout' not in str (output_file ):
5661 dir_name = os .path .dirname (os .path .abspath (output_file .name ))
5762 if not os .path .isdir (dir_name ):
5863 os .makedirs (dir_name )
59- output_file .write (content_str )
64+ if (sys .version_info < (3 , 0 )): # we need to manually encode it as UTF-8
65+ with open (output_file , 'w' ) as of :
66+ of .write (content_str .encode ('utf-8' ))
67+ else :
68+ with open (output_file , 'w' , encoding = 'utf-8' ) as of :
69+ of .write (content_str )
You can’t perform that action at this time.
0 commit comments