Skip to content

Commit 408ce17

Browse files
author
Frederick Ross
committed
Remove contains methods everywhere in client.py.
Everything now must use the in operator instead. Updated the CHANGELOG, fixed two examples that depend on contains, and one test.
1 parent 0026ebe commit 408ce17

File tree

5 files changed

+5
-34
lines changed

5 files changed

+5
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.0
44

5+
* All the .contains methods on collections have been removed. Use Python's `in` operator instead.
56
* Confs has been renamed to Configurations, and ConfFile to ConfigurationFile.
67
* Stanza.submit now takes a dictionary of key/value pairs specifying the stanza instead of a raw string.
78
* Namespace handling has changed subtly. Code that depends on namespace handling in detail may break.

examples/index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def foreach(self, argv, func):
131131
if len(opts.args) == 0:
132132
error("Command requires an index name", 2)
133133
for name in opts.args:
134-
if not self.service.indexes.contains(name):
134+
if name not in self.service.indexes:
135135
error("Index '%s' does not exist" % name, 2)
136136
index = self.service.indexes[name]
137137
func(index)
@@ -143,7 +143,7 @@ def update(self, argv):
143143
error("Command requires an index name", 2)
144144
name = argv[0]
145145

146-
if not self.service.indexes.contains(name):
146+
if name not in self.service.indexes:
147147
error("Index '%s' does not exist" % name, 2)
148148
index = self.service.indexes[name]
149149

examples/upload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def main(argv):
5959
service = client.connect(**kwargs_splunk)
6060

6161
name = opts.kwargs['index']
62-
if not service.indexes.contains(name):
62+
if name not in service.indexes:
6363
error("Index '%s' does not exist." % name, 2)
6464
index = service.indexes[name]
6565

splunklib/client.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,22 +1276,6 @@ def _load_list(self, response):
12761276
entities.append(entity)
12771277
return entities
12781278

1279-
def contains(self, name):
1280-
"""**Deprecated**: Use the ``in`` operator instead.
1281-
1282-
Indicates whether an entity name exists in the collection.
1283-
1284-
Makes a single roundtrip to the server, plus at most two more
1285-
if
1286-
the ``autologin`` field of :func:`connect` is set to ``True``.
1287-
1288-
:param name: The entity name.
1289-
:type name: ``string``
1290-
:return: ``True`` if the entity exists, ``False`` if not.
1291-
:rtype: ``boolean``
1292-
"""
1293-
return name in self
1294-
12951279
def itemmeta(self):
12961280
"""Returns metadata for members of the collection.
12971281
@@ -3196,13 +3180,6 @@ def __getitem__(self, key):
31963180
def __contains__(self, name):
31973181
return Collection.__contains__(self, name.lower())
31983182

3199-
def contains(self, name):
3200-
"""**Deprecated**: Use ``in`` operator instead.
3201-
3202-
Checks whether there is a user *name* in this Splunk instance.
3203-
"""
3204-
return Collection.__contains__(self, name.lower())
3205-
32063183
def create(self, username, password, roles, **params):
32073184
"""Creates a new user.
32083185
@@ -3337,13 +3314,6 @@ def __getitem__(self, key):
33373314
def __contains__(self, name):
33383315
return Collection.__contains__(self, name.lower())
33393316

3340-
def contains(self, name):
3341-
"""**Deprecated**: Use ``in`` operator instead.
3342-
3343-
Checks whether there is a user *name* in this Splunk instance.
3344-
"""
3345-
return Collection.__contains__(self, name.lower())
3346-
33473317
def create(self, name, **params):
33483318
"""Creates a new role.
33493319

tests/test_job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
class TestUtilities(testlib.SDKTestCase):
3131
def test_service_search(self):
3232
job = self.service.search('search index=_internal earliest=-1m | head 3')
33-
self.assertTrue(self.service.jobs.contains(job.sid))
33+
self.assertTrue(job.sid in self.service.jobs)
3434
job.cancel()
3535

3636
def test_oneshot_with_garbage_fails(self):

0 commit comments

Comments
 (0)