Skip to content

Commit debd64c

Browse files
committed
deprecated annotation for ResultsReader
1 parent 88a9869 commit debd64c

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

splunklib/results.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636

3737
from io import BufferedReader, BytesIO
3838

39+
import deprecation
40+
3941
from splunklib import six
42+
4043
try:
4144
import xml.etree.cElementTree as et
4245
except:
@@ -55,6 +58,7 @@
5558
"Message"
5659
]
5760

61+
5862
class Message(object):
5963
"""This class represents informational messages that Splunk interleaves in the results stream.
6064
@@ -65,6 +69,7 @@ class Message(object):
6569
6670
m = Message("DEBUG", "There's something in that variable...")
6771
"""
72+
6873
def __init__(self, type_, message):
6974
self.type = type_
7075
self.message = message
@@ -78,6 +83,7 @@ def __eq__(self, other):
7883
def __hash__(self):
7984
return hash((self.type, self.message))
8085

86+
8187
class _ConcatenatedStream(object):
8288
"""Lazily concatenate zero or more streams into a stream.
8389
@@ -90,6 +96,7 @@ class _ConcatenatedStream(object):
9096
s = _ConcatenatedStream(StringIO("abc"), StringIO("def"))
9197
assert s.read() == "abcdef"
9298
"""
99+
93100
def __init__(self, *streams):
94101
self.streams = list(streams)
95102

@@ -108,6 +115,7 @@ def read(self, n=None):
108115
del self.streams[0]
109116
return response
110117

118+
111119
class _XMLDTDFilter(object):
112120
"""Lazily remove all XML DTDs from a stream.
113121
@@ -121,6 +129,7 @@ class _XMLDTDFilter(object):
121129
s = _XMLDTDFilter("<?xml abcd><element><?xml ...></element>")
122130
assert s.read() == "<element></element>"
123131
"""
132+
124133
def __init__(self, stream):
125134
self.stream = stream
126135

@@ -151,6 +160,8 @@ def read(self, n=None):
151160
n -= 1
152161
return response
153162

163+
164+
@deprecation.deprecated(deprecated_in="1.16.9", details="Use the JSONResultsReader function instead")
154165
class ResultsReader(object):
155166
"""This class returns dictionaries and Splunk messages from an XML results
156167
stream.
@@ -178,6 +189,7 @@ class ResultsReader(object):
178189
print "Message: %s" % result
179190
print "is_preview = %s " % reader.is_preview
180191
"""
192+
181193
# Be sure to update the docstrings of client.Jobs.oneshot,
182194
# client.Job.results_preview and client.Job.results to match any
183195
# changes made to ResultsReader.
@@ -258,16 +270,16 @@ def _parse_results(self, stream):
258270
# So we'll define it here
259271

260272
def __itertext(self):
261-
tag = self.tag
262-
if not isinstance(tag, six.string_types) and tag is not None:
263-
return
264-
if self.text:
265-
yield self.text
266-
for e in self:
267-
for s in __itertext(e):
268-
yield s
269-
if e.tail:
270-
yield e.tail
273+
tag = self.tag
274+
if not isinstance(tag, six.string_types) and tag is not None:
275+
return
276+
if self.text:
277+
yield self.text
278+
for e in self:
279+
for s in __itertext(e):
280+
yield s
281+
if e.tail:
282+
yield e.tail
271283

272284
text = "".join(__itertext(elem))
273285
values.append(text)
@@ -288,6 +300,7 @@ def __itertext(self):
288300
else:
289301
raise
290302

303+
291304
class JSONResultsReader(object):
292305
"""This class returns dictionaries and Splunk messages from a JSON results
293306
stream.
@@ -310,6 +323,7 @@ class JSONResultsReader(object):
310323
print "Message: %s" % result
311324
print "is_preview = %s " % reader.is_preview
312325
"""
326+
313327
# Be sure to update the docstrings of client.Jobs.oneshot,
314328
# client.Job.results_preview and client.Job.results to match any
315329
# changes made to JSONResultsReader.
@@ -339,7 +353,7 @@ def _parse_results(self, stream):
339353
"""Parse results and messages out of *stream*."""
340354
for line in stream.readlines():
341355
strip_line = line.strip()
342-
if strip_line.__len__() == 0 : continue
356+
if strip_line.__len__() == 0: continue
343357
parsed_line = json_loads(strip_line)
344358
if "preview" in parsed_line:
345359
self.is_preview = parsed_line["preview"]
@@ -352,4 +366,4 @@ def _parse_results(self, stream):
352366
yield parsed_line["result"]
353367
if "results" in parsed_line:
354368
for result in parsed_line["results"]:
355-
yield result
369+
yield result

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ deps = pytest
3333
unittest2
3434
unittest-xml-reporting
3535
python-dotenv
36+
deprecation
3637

3738
distdir = build
3839
commands =

0 commit comments

Comments
 (0)