Skip to content
Snippets Groups Projects
Commit 2649410c authored by Gabriel Mazetto's avatar Gabriel Mazetto
Browse files

Handle sys.stdin and sys.stdout encoding issues in python 3.x

This code will keep current behavior for python 2.x.
parent fa3527a6
No related branches found
No related tags found
1 merge request!2Python3 support
Pipeline #
Loading
Loading
@@ -45,6 +45,7 @@ except:
pass
 
import codecs
import io
 
from docutils import nodes
from docutils.parsers.rst import directives, roles
Loading
Loading
@@ -164,7 +165,11 @@ def main():
except IOError: # given filename could not be found
return ''
except IndexError: # no filename given
text = sys.stdin.read()
if sys.version_info[0] < 3: # python 2.x
text = sys.stdin.read()
else: # python 3
input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
text = input_stream.read()
 
writer = Writer()
writer.translator_class = GitHubHTMLTranslator
Loading
Loading
@@ -187,5 +192,9 @@ def main():
return ''
 
if __name__ == '__main__':
sys.stdout.write("%s%s" % (main(), "\n"))
if sys.version_info[0] < 3: # python 2.x
sys.stdout.write("%s%s" % (main(), "\n"))
else: # python 3
output_stream = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
output_stream.write("%s%s" % (main(), "\n"))
sys.stdout.flush()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment