Skip to content

Commit 5f58e6b

Browse files
ljiang1shakeelmohamed
authored andcommitted
Generatorfix (#181)
* fix dvpl-7207 * add condition change only for v2 * fix unittest * fix generator unittest * remove comment out code * small fix: make \n check optional * small format fix
1 parent 1f7541d commit 5f58e6b

File tree

5 files changed

+1028
-1012
lines changed

5 files changed

+1028
-1012
lines changed

splunklib/searchcommands/generating_command.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ def _execute(self, ifile, process):
193193
:return: `None`.
194194
195195
"""
196+
if self._protocol_version == 2:
197+
result = self._read_chunk(ifile)
198+
199+
if not result:
200+
return
201+
202+
metadata, body = result
203+
action = getattr(metadata, 'action', None)
204+
205+
if action != 'execute':
206+
raise RuntimeError('Expected execute action, not {}'.format(action))
207+
196208
self._record_writer.write_records(self.generate())
197209
self.finish()
198210

splunklib/searchcommands/search_command.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# Absolute imports
2020

2121
from collections import namedtuple
22+
2223
try:
2324
from collections import OrderedDict # must be python 2.7
2425
except ImportError:
@@ -27,6 +28,7 @@
2728
from cStringIO import StringIO
2829
from itertools import chain, ifilter, imap, islice, izip
2930
from logging import _levelNames, getLevelName, getLogger
31+
3032
try:
3133
from shutil import make_archive
3234
except ImportError:
@@ -47,7 +49,7 @@
4749

4850
# Relative imports
4951

50-
from . internals import (
52+
from .internals import (
5153
CommandLineParser,
5254
CsvDialect,
5355
InputHeader,
@@ -63,6 +65,7 @@
6365
from . import Boolean, Option, environment
6466
from ..client import Service
6567

68+
6669
# ----------------------------------------------------------------------------------------------------------------------
6770

6871
# P1 [ ] TODO: Log these issues against ChunkedExternProcessor
@@ -89,6 +92,7 @@ class SearchCommand(object):
8992
""" Represents a custom search command.
9093
9194
"""
95+
9296
def __init__(self):
9397

9498
# Variables that may be used, but not altered by derived classes
@@ -873,8 +877,10 @@ def _read_chunk(ifile):
873877
# if body_length <= 0:
874878
# return metadata, ''
875879

880+
body = ""
876881
try:
877-
body = ifile.read(body_length)
882+
if body_length > 0:
883+
body = ifile.read(body_length)
878884
except Exception as error:
879885
raise RuntimeError('Failed to read body of length {}: {}'.format(body_length, error))
880886

Binary file not shown.

0 commit comments

Comments
 (0)