Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions lib/github/commands/rest2html
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ import sys
import os

# This fixes docutils failing with unicode parameters to CSV-Table. The -S
# switch and the following 2 lines can be removed after upgrading to python 3.
reload(sys)
sys.setdefaultencoding('utf-8')
# switch and the following 3 lines can be removed after upgrading to python 3.
if sys.version_info[0] < 3:
reload(sys)
sys.setdefaultencoding('utf-8')

import site

try:
Expand All @@ -43,6 +45,7 @@ except:
pass

import codecs
import io

from docutils import nodes
from docutils.parsers.rst import directives, roles
Expand Down Expand Up @@ -162,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
Expand All @@ -185,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()