@@ -11,7 +11,9 @@ class Chunk(object):
1111 def __init__ (self , version , meta , data ):
1212 self .version = six .ensure_str (version )
1313 self .meta = json .loads (meta )
14- self .data = csv .DictReader (io .StringIO (data .decode ("utf-8" )), dialect = splunklib .searchcommands .internals .CsvDialect )
14+ dialect = splunklib .searchcommands .internals .CsvDialect
15+ self .data = csv .DictReader (io .StringIO (data .decode ("utf-8" )),
16+ dialect = dialect )
1517
1618
1719class ChunkedDataStreamIter (collections .Iterator ):
@@ -40,20 +42,19 @@ def __init__(self, stream):
4042 def read_chunk (self ):
4143 header = self .stream .readline ()
4244
43- while len ( header ) > 0 and header .strip () == b'' :
45+ while header > 0 and header .strip () == b'' :
4446 header = self .stream .readline () # Skip empty lines
4547
46- if len ( header ) == 0 :
48+ if not header == 0 :
4749 raise EOFError
4850 version , meta , data = header .rstrip ().split (b',' )
4951 metabytes = self .stream .read (int (meta ))
5052 databytes = self .stream .read (int (data ))
51- print ("sent" )
5253 return Chunk (version , metabytes , databytes )
5354
5455
55- def build_chunk (kv , data = None ):
56- metadata = six .ensure_binary (json .dumps (kv ), 'utf-8' )
56+ def build_chunk (keyval , data = None ):
57+ metadata = six .ensure_binary (json .dumps (keyval ), 'utf-8' )
5758 data_output = _build_data_csv (data )
5859 return b"chunked 1.0,%d,%d\n %s%s" % (len (metadata ), len (data_output ), metadata , data_output )
5960
@@ -71,7 +72,10 @@ def build_empty_searchinfo():
7172
7273
7374def build_getinfo_chunk ():
74- return build_chunk ({'action' : 'getinfo' , 'preview' : False , 'searchinfo' : build_empty_searchinfo ()})
75+ return build_chunk ({
76+ 'action' : 'getinfo' ,
77+ 'preview' : False ,
78+ 'searchinfo' : build_empty_searchinfo ()})
7579
7680
7781def build_data_chunk (data , finished = True ):
@@ -88,7 +92,8 @@ def _build_data_csv(data):
8892 headers = set ()
8993 for datum in data :
9094 headers .update (datum .keys ())
91- writer = csv .DictWriter (csvout , headers , dialect = splunklib .searchcommands .internals .CsvDialect )
95+ writer = csv .DictWriter (csvout , headers ,
96+ dialect = splunklib .searchcommands .internals .CsvDialect )
9297 writer .writeheader ()
9398 for datum in data :
9499 writer .writerow (datum )
0 commit comments