3030import jsonstreams
3131from six import string_types
3232
33- from commoncode .system import py2
34- from commoncode .system import py3
3533from formattedcode import FileOptionType
3634from commoncode .cliutils import PluggableCommandLineOption
3735from commoncode .cliutils import OUTPUT_GROUP
@@ -64,27 +62,12 @@ def logger_debug(*args):
6462 and a or repr (a ) for a in args ))
6563
6664
67- if py2 :
68- mode = 'wb'
69- space = b' '
70- comma = b','
71- colon = b':'
72- eol = b'\n '
73-
74- if py3 :
75- mode = 'w'
76- space = u' '
77- comma = u','
78- colon = u':'
79- eol = u'\n '
80-
81-
8265@output_impl
8366class JsonCompactOutput (OutputPlugin ):
8467
8568 options = [
8669 PluggableCommandLineOption (('--json' , 'output_json' ,),
87- type = FileOptionType (mode = mode , lazy = True ),
70+ type = FileOptionType (mode = 'w' , lazy = True ),
8871 metavar = 'FILE' ,
8972 help = 'Write scan output as compact JSON to FILE.' ,
9073 help_group = OUTPUT_GROUP ,
@@ -103,7 +86,7 @@ class JsonPrettyOutput(OutputPlugin):
10386
10487 options = [
10588 PluggableCommandLineOption (('--json-pp' , 'output_json_pp' ,),
106- type = FileOptionType (mode = mode , lazy = True ),
89+ type = FileOptionType (mode = 'w' , lazy = True ),
10790 metavar = 'FILE' ,
10891 help = 'Write scan output as pretty-printed JSON to FILE.' ,
10992 help_group = OUTPUT_GROUP ,
@@ -134,10 +117,10 @@ def write_results(codebase, output_file, pretty=False, **kwargs):
134117 # If `output_file` is a path string, open the file at path `output_file` and use it as `output_file`
135118 close_fd = False
136119 if isinstance (output_file , string_types ):
137- output_file = open (output_file , mode )
120+ output_file = open (output_file , 'w' )
138121 close_fd = True
139122
140- # Begin writing JSON to `output_file`
123+ # Begin wri'w' JSON to `output_file`
141124 with jsonstreams .Stream (jsonstreams .Type .object , fd = output_file , close_fd = close_fd , ** jsonstreams_kwargs ) as s :
142125 # Write headers
143126 codebase .add_files_count_to_current_header ()
@@ -151,10 +134,8 @@ def write_results(codebase, output_file, pretty=False, **kwargs):
151134
152135 # Write files
153136 codebase_files = OutputPlugin .get_files (codebase , ** kwargs )
154- if py3 :
155- # OutputPlugin.get_files() returns a `map()`, which isn's JSON
156- # serializable in Python 3
157- codebase_files = list (codebase_files )
137+ # OutputPlugin.get_files() returns a generator, not JSON-serializable
138+ codebase_files = list (codebase_files )
158139 s .write ('files' , codebase_files )
159140
160141
0 commit comments