5
5
from __future__ import print_function
6
6
7
7
import csv
8
+ import io
8
9
import os
9
10
import subprocess
10
11
import sys
11
12
12
13
import click
13
- import six
14
14
from tabulate import tabulate
15
15
16
16
17
17
def ensure_str (s ):
18
18
if s is None :
19
19
s = ''
20
- elif not isinstance (s , (six .text_type , six .binary_type )):
20
+ elif isinstance (s , bytes ):
21
+ s = s .decode ('utf-8' , 'strict' )
22
+ elif not isinstance (s , str ):
21
23
s = str (s )
22
24
23
- return six . ensure_str ( s )
25
+ return s
24
26
25
27
26
28
def trim (string , length = 70 ): # type: (str, int) -> str
@@ -68,7 +70,7 @@ def _tabulate(output, headers, fmt):
68
70
elif fmt == 'simple' :
69
71
return tabulate (output , headers , tablefmt = 'simple' )
70
72
elif fmt == 'csv' :
71
- result = six .StringIO ()
73
+ result = io .StringIO ()
72
74
writer = csv .writer (
73
75
result , quoting = csv .QUOTE_ALL , lineterminator = os .linesep )
74
76
writer .writerow ([ensure_str (h ) for h in headers ])
@@ -89,7 +91,9 @@ def _echo_via_pager(pager, output):
89
91
90
92
pager = subprocess .Popen (pager .split (), stdin = subprocess .PIPE , env = env )
91
93
92
- output = six .ensure_binary (output )
94
+ # TODO(stephenfin): This is potential hangover from Python 2 days
95
+ if not isinstance (output , bytes ):
96
+ output = output .encode ('utf-8' , 'strict' )
93
97
94
98
try :
95
99
pager .communicate (input = output )
0 commit comments