Skip to content

Commit fcc6ea3

Browse files
author
David Noble
committed
splunklib.searchcommands bug fixes
1 parent 3cc7f76 commit fcc6ea3

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

splunklib/searchcommands/search_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def service(self):
275275
#region Methods
276276

277277
def error_exit(self, error):
278-
self.logger.error('Abnormal exit: ' + error)
278+
self.logger.error('Abnormal exit: %s', error)
279279
self.write_error(error)
280280
exit(1)
281281

splunklib/searchcommands/search_command_internals.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ def parse(self, argv, command):
275275

276276
# Parse options
277277

278-
for option in SearchCommandParser._options_re.finditer(
279-
command_args.group('options')):
278+
for option in SearchCommandParser._options_re.finditer(command_args.group('options')):
280279
name, value = option.group(1), option.group(2)
281280
if not name in command.options:
282281
raise ValueError('Unrecognized option: %s = %s' % (name, value))
@@ -288,9 +287,7 @@ def parse(self, argv, command):
288287
if len(missing) == 1:
289288
raise ValueError('A value for "%s" is required' % missing[0])
290289
else:
291-
raise ValueError(
292-
'Values for these options are required: %s' %
293-
', '.join(missing))
290+
raise ValueError('Values for these options are required: %s' % ', '.join(missing))
294291

295292
# Parse field names
296293

@@ -365,9 +362,9 @@ def replace(match):
365362

366363
_options_re = re.compile(r"""
367364
# Captures a set of name/value pairs when used with re.finditer
368-
([_a-zA-Z][_a-zA-Z0-9]+) # name
369-
\s*=\s* # =
370-
([^\s"]+|"(?:[^"]+|""|\\")*") # value
365+
([_a-zA-Z][_a-zA-Z0-9]+) # name
366+
\s*=\s* # =
367+
([^\s"]+|"(?:[^\\"]+|\\.|"")*") # value
371368
""", re.VERBOSE)
372369

373370
#endregion

splunklib/searchcommands/splunk_csv/dict_writer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _encode_list(self, value):
6363
multi_value = ';'.join(
6464
['$' + DictWriter._to_string(item).replace('$', '$$') + '$' for item
6565
in value])
66-
value = self._mv_delimiter.join([repr(item) for item in value])
66+
value = self._mv_delimiter.join([DictWriter._to_string(item) for item in value])
6767
return value, multi_value
6868

6969
def _header_written(self):
@@ -73,8 +73,8 @@ def _header_written(self):
7373
def _to_string(item):
7474
if isinstance(item, bool):
7575
return 't' if item else 'f'
76-
if isinstance(item, str):
77-
return item
76+
if isinstance(item, basestring):
77+
return item.decode('utf-8')
7878
if isinstance(item, Number):
7979
return str(item)
8080
return repr(item)

splunklib/searchcommands/validators.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,24 @@ def format(self, value):
214214
return value[:-1]
215215

216216

217+
class Map(Validator):
218+
""" Validates map option values.
219+
220+
"""
221+
def __init__(self, **kwargs):
222+
self.membership = kwargs
223+
224+
def __call__(self, value):
225+
if value is not None:
226+
value = str(value)
227+
if value not in self.membership:
228+
raise ValueError('Unrecognized value: %s' % value)
229+
return self.membership[value]
230+
231+
def format(self, value):
232+
return self.membership.keys()[self.membership.values().index(value)]
233+
234+
217235
class OptionName(Validator):
218236
""" Validates option names.
219237

0 commit comments

Comments
 (0)