Skip to content

Commit 8c90d1e

Browse files
committed
refactoring
- rearranged imports - refactored code based on Pylint recommendations
1 parent 14cdb92 commit 8c90d1e

16 files changed

+48
-38
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Splunk Enterprise SDK for Python Changelog
22

3+
## Version 2.0.0-beta
4+
5+
### Feature updates
6+
* `ensure_binary`, `ensure_str`, `ensure_text` and `assert_regex` utility methods have been migrated from `six.py` to `splunklib/__init__.py`
7+
8+
### Major changes
9+
* Removed Code specific to Python2
10+
* Removed six.py dependency
11+
* Removed `__future__` imports
12+
* Refactored & Updated `splunklib` and `tests` to utilise Python3 features
13+
* Updated CI test matrix to run with Python versions - 3.7, 3.9 and 3.10.7
14+
* Refactored Code throwing `deprecation` warnings
15+
* Refactored Code violating Pylint rules
16+
317
## Version 1.7.2
418

519
### Minor changes

splunklib/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ def splunk_version(self):
692692
@property
693693
def splunk_instance(self):
694694
if self._instance_type is None :
695-
splunk_info = self.info;
695+
splunk_info = self.info
696696
if hasattr(splunk_info, 'instance_type') :
697697
self._instance_type = splunk_info['instance_type']
698698
else:
@@ -1823,7 +1823,7 @@ def __getitem__(self, key):
18231823
# This screws up the default implementation of __getitem__ from Collection, which thinks
18241824
# that multiple entities means a name collision, so we have to override it here.
18251825
try:
1826-
response = self.get(key)
1826+
self.get(key)
18271827
return ConfigurationFile(self.service, PATH_CONF % key, state={'title': key})
18281828
except HTTPError as he:
18291829
if he.status == 404: # No entity matching key
@@ -1835,7 +1835,7 @@ def __contains__(self, key):
18351835
# configs/conf-{name} never returns a 404. We have to post to properties/{name}
18361836
# in order to find out if a configuration exists.
18371837
try:
1838-
response = self.get(key)
1838+
self.get(key)
18391839
return True
18401840
except HTTPError as he:
18411841
if he.status == 404: # No entity matching key
@@ -3617,7 +3617,7 @@ class Roles(Collection):
36173617
Retrieve this collection using :meth:`Service.roles`."""
36183618

36193619
def __init__(self, service):
3620-
return Collection.__init__(self, service, PATH_ROLES, item=Role)
3620+
Collection.__init__(self, service, PATH_ROLES, item=Role)
36213621

36223622
def __getitem__(self, key):
36233623
return Collection.__getitem__(self, key.lower())

tests/modularinput/modularinput_testlib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
# License for the specific language governing permissions and limitations
1515
# under the License.
1616

17-
# Utility file for unit tests, import common functions and modules
18-
import unittest
19-
import sys, os
2017
import io
18+
import os
19+
import sys
20+
import unittest
2121

2222
sys.path.insert(0, os.path.join('../../splunklib', '..'))
2323

tests/modularinput/test_input_definition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_attempt_to_parse_malformed_input_definition_will_throw_exception(self):
7070
"""Does malformed XML cause the expected exception."""
7171

7272
with self.assertRaises(ValueError):
73-
found = InputDefinition.parse(data_open("data/conf_with_invalid_inputs.xml"))
73+
InputDefinition.parse(data_open("data/conf_with_invalid_inputs.xml"))
7474

7575

7676
if __name__ == "__main__":

tests/searchcommands/test_decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def fix_up(cls, command_class):
283283

284284
setattr(settings_instance, name, value)
285285

286-
self.assertIn(backing_field_name, settings_instance.__dict__),
286+
self.assertIn(backing_field_name, settings_instance.__dict__)
287287
self.assertEqual(getattr(settings_instance, name), value)
288288
self.assertEqual(settings_instance.__dict__[backing_field_name], value)
289289

tests/searchcommands/test_internals_v1.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@
1717
from contextlib import closing
1818
from unittest import main, TestCase
1919
import os
20-
import pytest
20+
from io import StringIO, BytesIO
2121
from functools import reduce
22+
import pytest
2223

2324
from splunklib.searchcommands.internals import CommandLineParser, InputHeader, RecordWriterV1
2425
from splunklib.searchcommands.decorators import Configuration, Option
2526
from splunklib.searchcommands.validators import Boolean
2627

2728
from splunklib.searchcommands.search_command import SearchCommand
2829

29-
from io import StringIO, BytesIO
30-
31-
3230

3331
@pytest.mark.smoke
3432
class TestInternals(TestCase):

tests/test_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_update(self):
8383

8484
def test_delete(self):
8585
name = testlib.tmpname()
86-
app = self.service.apps.create(name)
86+
self.service.apps.create(name)
8787
self.assertTrue(name in self.service.apps)
8888
self.service.apps.delete(name)
8989
self.assertFalse(name in self.service.apps)

tests/test_binding.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def urllib2_insert_cookie_handler(url, message, **kwargs):
501501
# Mimic the insertion of 3rd party cookies into the response.
502502
# An example is "sticky session"/"insert cookie" persistence
503503
# of a load balancer for a SHC.
504-
header_list = [(k, v) for k, v in response.info().items()]
504+
header_list = list(response.info().items())
505505
header_list.append(("Set-Cookie", "BIGipServer_splunk-shc-8089=1234567890.12345.0000; path=/; Httponly; Secure"))
506506
header_list.append(("Set-Cookie", "home_made=yummy"))
507507

@@ -633,7 +633,7 @@ def test_got_updated_cookie_with_get(self):
633633
def test_login_fails_with_bad_cookie(self):
634634
# We should get an error if using a bad cookie
635635
try:
636-
new_context = binding.connect(**{"cookie": "bad=cookie"})
636+
binding.connect(**{"cookie": "bad=cookie"})
637637
self.fail()
638638
except AuthenticationError as ae:
639639
self.assertEqual(str(ae), "Login failed.")

tests/test_kvstore_batch.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
from tests import testlib
1818

19-
from splunklib import client
20-
2119

2220
class KVStoreBatchTestCase(testlib.SDKTestCase):
2321
def setUp(self):
@@ -66,7 +64,7 @@ def test_insert_find_update_data(self):
6664

6765
def tearDown(self):
6866
confs = self.service.kvstore
69-
if ('test' in confs):
67+
if 'test' in confs:
7068
confs['test'].delete()
7169

7270

tests/test_kvstore_conf.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from tests import testlib
1818
from splunklib import client
1919

20+
2021
class KVStoreConfTestCase(testlib.SDKTestCase):
2122
def setUp(self):
2223
super().setUp()
@@ -43,7 +44,6 @@ def test_update_collection(self):
4344
self.assertEqual(self.confs['test']['accelerated_fields.ind1'], '{"a": 1}')
4445
self.confs['test'].delete()
4546

46-
4747
def test_update_fields(self):
4848
self.confs.create('test')
4949
self.confs['test'].post(**{'field.a': 'number'})
@@ -52,7 +52,6 @@ def test_update_fields(self):
5252
self.assertEqual(self.confs['test']['field.a'], 'string')
5353
self.confs['test'].delete()
5454

55-
5655
def test_create_unique_collection(self):
5756
self.confs.create('test')
5857
self.assertTrue('test' in self.confs)
@@ -83,9 +82,11 @@ def test_create_accelerated_fields_fields(self):
8382
"""
8483

8584
def tearDown(self):
86-
if ('test' in self.confs):
85+
if 'test' in self.confs:
8786
self.confs['test'].delete()
8887

88+
8989
if __name__ == "__main__":
9090
import unittest
91+
9192
unittest.main()

0 commit comments

Comments
 (0)