Skip to content

Commit 6eba95f

Browse files
author
Shakeel Mohamed
committed
Merge branch 'develop' into bug/namespace-for-server-endpoints
Conflicts: splunklib/client.py
2 parents 3315a3e + 003de93 commit 6eba95f

34 files changed

+1424
-1606
lines changed

examples/analytics/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Similarly to `AnalyticsTracker`, the `output.py` file defines the "output" side
7373
of the Analytics service. If you want to extract the events you logged in using
7474
`AnalyticsTracker`, you'd use the `AnalyticsRetriever` class.
7575

76-
Creating an `AnalyticsTracker` instance is identical to the `AnalyticsTracker`:
76+
Creating an `AnalyticsRetriever` instance is identical to the `AnalyticsTracker`:
7777

7878
```python
7979
from analytics.output import AnalyticsRetriever
@@ -138,7 +138,7 @@ you can see a graph of events over time, properties, etc.
138138

139139
We make use of the excellent open source
140140
[flot](http://code.google.com/p/flot/) graphing library to render
141-
our Javascript graphs. We also use the [`bottle.py`](bottlepy.org)
141+
our Javascript graphs. We also use the [`bottle.py`](http://bottlepy.org)
142142
micro-web framework.
143143

144144
## Running the Sample

examples/github_forks/github_forks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def get_scheme(self):
5050
scheme.use_single_instance = True
5151

5252
owner_argument = Argument("owner")
53+
owner_argument.title = "Owner"
5354
owner_argument.data_type = Argument.data_type_string
5455
owner_argument.description = "Github user or organization that created the repository."
5556
owner_argument.required_on_create = True
@@ -59,6 +60,7 @@ def get_scheme(self):
5960
scheme.add_argument(owner_argument)
6061

6162
repo_name_argument = Argument("repo_name")
63+
repo_name_argument.title = "Repo Name"
6264
repo_name_argument.data_type = Argument.data_type_string
6365
repo_name_argument.description = "Name of the Github repository."
6466
repo_name_argument.required_on_create = True

examples/random_numbers/random_numbers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def get_scheme(self):
5050
scheme.use_single_instance = True
5151

5252
min_argument = Argument("min")
53+
min_argument.title = "Minimum"
5354
min_argument.data_type = Argument.data_type_number
5455
min_argument.description = "Minimum random number to be produced by this input."
5556
min_argument.required_on_create = True
@@ -59,6 +60,7 @@ def get_scheme(self):
5960
scheme.add_argument(min_argument)
6061

6162
max_argument = Argument("max")
63+
max_argument.title = "Maximum"
6264
max_argument.data_type = Argument.data_type_number
6365
max_argument.description = "Maximum random number to be produced by this input."
6466
max_argument.required_on_create = True

examples/searchcommands_app/bin/simulate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class SimulateCommand(GeneratingCommand):
8686

8787
def generate(self):
8888
""" Yields one random record at a time for the duration of `duration` """
89-
self.logger.debug('SimulateCommand: %s' % self) # log command line
89+
self.logger.debug('SimulateCommand: %s', self) # log command line
9090
if not self.records:
9191
if self.seed is not None:
9292
random.seed(self.seed)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def run(self):
168168
sdk_dir = os.path.abspath('.')
169169

170170
def exclude(path):
171-
# TODO: Replace with filter function because exclude is deprecated
171+
# TODO: DVPL-5866 - Replace with filter function because exclude is deprecated
172172
basename = os.path.basename(path)
173173
for pattern in ['.DS_Store', '.idea', '*.log', '*.py[co]']:
174174
if fnmatch(basename, pattern):

splunklib/binding.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
from contextlib import contextmanager
4141

42-
from xml.etree.ElementTree import XML
42+
from xml.etree.ElementTree import XML, ParseError
4343

4444
from data import record
4545

@@ -974,7 +974,10 @@ def __init__(self, response, _message=None):
974974
status = response.status
975975
reason = response.reason
976976
body = response.body.read()
977-
detail = XML(body).findtext("./messages/msg")
977+
try:
978+
detail = XML(body).findtext("./messages/msg")
979+
except ParseError as err:
980+
detail = body
978981
message = "HTTP %d %s%s" % (
979982
status, reason, "" if detail is None else " -- %s" % detail)
980983
Exception.__init__(self, _message or message)

splunklib/client.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,18 @@ def _parse_atom_entry(entry):
237237

238238
# Filter some of the noise out of the content record
239239
content = record((k, v) for k, v in content.iteritems()
240-
if k not in ['eai:acl', 'eai:attributes', 'type'])
240+
if k not in ['eai:acl', 'eai:attributes'])
241+
242+
if isinstance(content['type'], list):
243+
content['type'] = [t for t in content['type'] if t != 'text/xml']
244+
# Unset type if it was only 'text/xml'
245+
if len(content['type']) == 0:
246+
content.pop('type', None)
247+
# Flatten 1 element list
248+
if len(content['type']) == 1:
249+
content['type'] = content['type'][0]
250+
else:
251+
content.pop('type', None)
241252

242253
return record({
243254
'title': title,
@@ -1619,7 +1630,7 @@ def get(self, name="", owner=None, app=None, sharing=None, **query):
16191630
name = UrlEncoded(name, encode_slash=True)
16201631
return super(Collection, self).get(name, owner, app, sharing, **query)
16211632

1622-
1633+
16231634

16241635

16251636
class ConfigurationFile(Collection):
@@ -1799,7 +1810,7 @@ def create(self, password, username, realm=None):
17991810
storage_password = StoragePassword(self.service, self._entity_path(state), state=state, skip_refresh=True)
18001811

18011812
return storage_password
1802-
1813+
18031814
def delete(self, username, realm=None):
18041815
"""Delete a storage password by username and/or realm.
18051816
@@ -1977,7 +1988,7 @@ def clean(self, timeout=60):
19771988
:return: The :class:`Index`.
19781989
"""
19791990
self.refresh()
1980-
1991+
19811992
tds = self['maxTotalDataSizeMB']
19821993
ftp = self['frozenTimePeriodInSecs']
19831994
was_disabled_initially = self.disabled
@@ -1996,7 +2007,7 @@ def clean(self, timeout=60):
19962007
while self.content.totalEventCount != '0' and datetime.now() < start+diff:
19972008
sleep(1)
19982009
self.refresh()
1999-
2010+
20002011
if self.content.totalEventCount != '0':
20012012
raise OperationError, "Cleaning index %s took longer than %s seconds; timing out." %\
20022013
(self.name, timeout)
@@ -2941,7 +2952,7 @@ def export(self, query, **params):
29412952
raise TypeError("Cannot specify an exec_mode to export.")
29422953
params['segmentation'] = params.get('segmentation', 'none')
29432954
return self.post(path_segment="export",
2944-
search=query,
2955+
search=query,
29452956
**params).body
29462957

29472958
def itemmeta(self):
@@ -3004,7 +3015,7 @@ def oneshot(self, query, **params):
30043015
raise TypeError("Cannot specify an exec_mode to oneshot.")
30053016
params['segmentation'] = params.get('segmentation', 'none')
30063017
return self.post(search=query,
3007-
exec_mode="oneshot",
3018+
exec_mode="oneshot",
30083019
**params).body
30093020

30103021

@@ -3032,7 +3043,8 @@ def __init__(self, service, path, **kwargs):
30323043
def value(self):
30333044
"""Returns the message value.
30343045
3035-
:return: The :class:`Loggers` collection.
3046+
:return: The message value.
3047+
:rtype: ``string``
30363048
"""
30373049
return self[self.name]
30383050

splunklib/modularinput/argument.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def add_to_document(self, parent):
8080
arg = ET.SubElement(parent, "arg")
8181
arg.set("name", self.name)
8282

83+
if self.title is not None:
84+
ET.SubElement(arg, "title").text = self.title
85+
8386
if self.description is not None:
8487
ET.SubElement(arg, "description").text = self.description
8588

splunklib/results.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,25 @@ def _parse_results(self, stream):
246246
elem.clear()
247247

248248
elif elem.tag in ('text', 'v') and event == 'end':
249-
text = "".join(elem.itertext())
249+
try:
250+
text = "".join(elem.itertext())
251+
except AttributeError:
252+
# Assume we're running in Python < 2.7, before itertext() was added
253+
# So we'll define it here
254+
255+
def __itertext(self):
256+
tag = self.tag
257+
if not isinstance(tag, basestring) and tag is not None:
258+
return
259+
if self.text:
260+
yield self.text
261+
for e in self:
262+
for s in __itertext(e):
263+
yield s
264+
if e.tail:
265+
yield e.tail
266+
267+
text = "".join(__itertext(elem))
250268
values.append(text.encode('utf8'))
251269
elem.clear()
252270

splunklib/searchcommands/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def __repr__(self):
222222
return str(self)
223223

224224
def __str__(self):
225-
value = self.validator.format(self.value) if self.validator is not None else str(self.value)
225+
value = str(self.value) if self.validator is None else self.validator.format(self.value)
226226
encoder = Option.Encoder(self)
227227
text = '='.join([self.name, encoder.encode(value)])
228228
return text

0 commit comments

Comments
 (0)