Skip to content

Commit

Permalink
lint changes and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
zenmoto committed Nov 5, 2020
1 parent 348c80b commit efaa7e1
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions tests/searchcommands/chunked_data_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class Chunk(object):
def __init__(self, version, meta, data):
self.version = six.ensure_str(version)
self.meta = json.loads(meta)
self.data = csv.DictReader(io.StringIO(data.decode("utf-8")), dialect=splunklib.searchcommands.internals.CsvDialect)
dialect = splunklib.searchcommands.internals.CsvDialect
self.data = csv.DictReader(io.StringIO(data.decode("utf-8")),
dialect=dialect)


class ChunkedDataStreamIter(collections.Iterator):
Expand Down Expand Up @@ -40,20 +42,19 @@ def __init__(self, stream):
def read_chunk(self):
header = self.stream.readline()

while len(header) > 0 and header.strip() == b'':
while header > 0 and header.strip() == b'':
header = self.stream.readline() # Skip empty lines

if len(header) == 0:
if not header == 0:
raise EOFError
version, meta, data = header.rstrip().split(b',')
metabytes = self.stream.read(int(meta))
databytes = self.stream.read(int(data))
print("sent")
return Chunk(version, metabytes, databytes)


def build_chunk(kv, data=None):
metadata = six.ensure_binary(json.dumps(kv), 'utf-8')
def build_chunk(keyval, data=None):
metadata = six.ensure_binary(json.dumps(keyval), 'utf-8')
data_output = _build_data_csv(data)
return b"chunked 1.0,%d,%d\n%s%s" % (len(metadata), len(data_output), metadata, data_output)

Expand All @@ -71,7 +72,10 @@ def build_empty_searchinfo():


def build_getinfo_chunk():
return build_chunk({'action': 'getinfo', 'preview': False, 'searchinfo': build_empty_searchinfo()})
return build_chunk({
'action': 'getinfo',
'preview': False,
'searchinfo': build_empty_searchinfo()})


def build_data_chunk(data, finished=True):
Expand All @@ -88,7 +92,8 @@ def _build_data_csv(data):
headers = set()
for datum in data:
headers.update(datum.keys())
writer = csv.DictWriter(csvout, headers, dialect=splunklib.searchcommands.internals.CsvDialect)
writer = csv.DictWriter(csvout, headers,
dialect=splunklib.searchcommands.internals.CsvDialect)
writer.writeheader()
for datum in data:
writer.writerow(datum)
Expand Down

0 comments on commit efaa7e1

Please sign in to comment.