Skip to content

Commit b9802ea

Browse files
author
Frederick Ross
committed
All test pass, including examples.
1 parent 58b7c00 commit b9802ea

5 files changed

Lines changed: 24 additions & 19 deletions

File tree

‎examples/oneshot.py‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@
2828

2929
def pretty(response):
3030
reader = results.ResultsReader(response)
31-
while True:
32-
kind = reader.read()
33-
if kind == None: break
34-
if kind == results.RESULT:
35-
event = reader.value
36-
pprint(event)
31+
for result in reader:
32+
if isinstance(result, dict):
33+
pprint(result)
3734

3835
def main():
3936
usage = "usage: oneshot.py <search>"
@@ -44,7 +41,7 @@ def main():
4441
search = opts.args[0]
4542
service = connect(**opts.kwargs)
4643
socket.setdefaulttimeout(None)
47-
response = service.jobs.create(search, exec_mode="oneshot")
44+
response = service.jobs.oneshot(search)
4845

4946
pretty(response)
5047

‎examples/search.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ def main(argv):
7777

7878
job = service.jobs.create(search, **kwargs_create)
7979
while True:
80-
stats = job.refresh()(
81-
'isDone',
82-
'doneProgress',
83-
'scanCount',
84-
'eventCount',
85-
'resultCount')
80+
job.refresh()
81+
stats = {'isDone': job['isDone'],
82+
'doneProgress': job['doneProgress'],
83+
'scanCount': job['scanCount'],
84+
'eventCount': job['eventCount'],
85+
'resultCount': job['resultCount']}
8686
progress = float(stats['doneProgress'])*100
8787
scanned = int(stats['scanCount'])
8888
matched = int(stats['eventCount'])

‎examples/spurl.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
# Invoke the url using the given opts parameters
2828
def invoke(path, **kwargs):
29-
message = { "method": kwargs.get("method", "GET"), }
30-
return binding.connect(**kwargs).request(path, message)
29+
method = kwargs.get("method", "GET")
30+
return binding.connect(**kwargs).request(path, method=method)
3131

3232
def print_response(response):
3333
if response.status != 200:

‎splunklib/client.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,17 @@ def _load_atom(response, match=None):
128128

129129
# Load an array of atom entries from the body of the given response
130130
def _load_atom_entries(response):
131-
entries = _load_atom(response).feed.get('entry', None)
132-
if entries is None: return None
133-
return entries if isinstance(entries, list) else [entries]
131+
r = _load_atom(response)
132+
if 'feed' in r:
133+
entries = r.feed.get('entry', None)
134+
if entries is None: return None
135+
return entries if isinstance(entries, list) else [entries]
136+
# This rigamarole is because the jobs endpoint doesn't
137+
# returned an entry inside a feed, it just returns and entry.
138+
else:
139+
entries = r.get('entry', None)
140+
if entries is None: return None
141+
return entries if isinstance(entries, list) else [entries]
134142

135143
# Load the sid from the body of the given response
136144
def _load_sid(response):

‎tests/test_job.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def check_job(self, job):
6363
def test_read(self):
6464
service = client.connect(**self.opts.kwargs)
6565

66-
for job in service.jobs:
66+
for job in service.jobs:
6767
service.jobs[job.sid]
6868
self.check_job(job)
6969
job.refresh()

0 commit comments

Comments
 (0)