Skip to content

Commit 64eabe7

Browse files
committed
fix Py2py3
1 parent 8c92564 commit 64eabe7

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

jsoncsv/dumptool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def initialize(self, **kwargs):
9797

9898
def write_headers(self):
9999
if not PY3:
100+
# Python 2 csv does not support unicode
100101
fieldnames = [header.encode('utf8') for header in self._headers]
101102
else:
102103
fieldnames = self._headers
@@ -111,7 +112,9 @@ def patch_obj(self, obj):
111112
for key, value in obj.items():
112113
if value in [None, {}, []]:
113114
value = ""
115+
114116
if not PY3:
117+
# Python 2 csv does not support unicode
115118
key = key.encode('utf8')
116119
if isinstance(value, six.text_type):
117120
value = value.encode('utf8')

jsoncsv/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# coding=utf-8
22

3+
import io
34
import click
45
import sys
56

67
from jsoncsv import jsontool
78
from jsoncsv import dumptool
9+
from jsoncsv import PY3
810
from jsoncsv.dumptool import dump_excel
911
from jsoncsv.jsontool import convert_json
1012
from jsoncsv.utils import separator_type
@@ -86,8 +88,11 @@ def jsoncsv(output, input, expand, restore, safe, separator):
8688
type=click.File('wb'),
8789
default=sys.stdout)
8890
def mkexcel(output, input, sort_, row, type_):
89-
if output == sys.stdout and type_ == "xls":
91+
if type_ == "xls" and output == sys.stdout:
9092
output = click.get_binary_stream('stdout')
93+
if type_ == "csv" and output != sys.stdout:
94+
if PY3:
95+
output = io.TextIOWrapper(output)
9196

9297
klass = dumptool.DumpCSV
9398
if type_ == "xls":

0 commit comments

Comments
 (0)