Skip to content

Commit a9425dc

Browse files
authored
Merge pull request #32 from alingse/use-unicode-csv
use unicodecsv
2 parents c729edd + ed37749 commit a9425dc

5 files changed

Lines changed: 9 additions & 12 deletions

File tree

jsoncsv/dumptool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# 2015.10.09
44

55
import six
6-
import csv
6+
import unicodecsv as csv
77
import json
88
import xlwt
99

jsoncsv/main.py

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

3-
import io
43
import click
54
import sys
65

76
from jsoncsv import jsontool
87
from jsoncsv import dumptool
9-
from jsoncsv import PY3
108
from jsoncsv.dumptool import dump_excel
119
from jsoncsv.jsontool import convert_json
1210
from jsoncsv.utils import separator_type
@@ -88,11 +86,8 @@ def jsoncsv(output, input, expand, restore, safe, separator):
8886
type=click.File('wb'),
8987
default=sys.stdout)
9088
def mkexcel(output, input, sort_, row, type_):
91-
if type_ == "xls" and output == sys.stdout:
89+
if output == sys.stdout:
9290
output = click.get_binary_stream('stdout')
93-
if type_ == "csv" and output != sys.stdout:
94-
if PY3:
95-
output = io.TextIOWrapper(output)
9691

9792
klass = dumptool.DumpCSV
9893
if type_ == "xls":

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
xlwt>=1.1.2
2-
click>=6.7
2+
click>=6.7
3+
unicodecsv>=0.14.1

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name='jsoncsv',
15-
version='2.2.0a',
15+
version='2.2.0b1',
1616
url='https://github.com/alingse/jsoncsv',
1717
description='A command tool easily convert json file to csv or xlsx.',
1818
long_description=readme,
@@ -30,6 +30,7 @@
3030
'Programming Language :: Python :: 3.6',
3131
],
3232
install_requires=[
33+
'unicodecsv',
3334
'xlwt',
3435
'click',
3536
],

tests/test_mkexcel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TestDumpTool(unittest.TestCase):
1414
# FIXME (使用虚拟文件)
1515
def test_dumpexcel_csv(self):
1616
fin = open('./fixture/files/expand.1.json', 'r')
17-
fout = open('./fixture/files/tmp.output.1.csv', 'w')
17+
fout = open('./fixture/files/tmp.output.1.csv', 'wb')
1818

1919
dump_excel(fin, fout, DumpCSV)
2020
fin.close()
@@ -30,7 +30,7 @@ def test_dumpexcel_csv(self):
3030

3131
def test_dumpexcel_csv_with_sort(self):
3232
fin = open('./fixture/files/expand.1.json', 'r')
33-
fout = open('./fixture/files/tmp.output.1.sort.csv', 'w')
33+
fout = open('./fixture/files/tmp.output.1.sort.csv', 'wb')
3434

3535
dump_excel(fin, fout, DumpCSV, sort_type=True)
3636
fin.close()
@@ -55,7 +55,7 @@ def test_dumpcexcel_xls(self):
5555

5656
def test_dump_csv_with_non_ascii(self):
5757
fin = open('./fixture/files/expand.2.json', 'r')
58-
fout = open('./fixture/files/tmp.output.2.csv', 'w')
58+
fout = open('./fixture/files/tmp.output.2.csv', 'wb')
5959

6060
dump_excel(fin, fout, DumpCSV)
6161

0 commit comments

Comments
 (0)