diff --git a/docs/conf.py b/docs/conf.py
index 4191da11..a18d6038 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
#
# solnlib documentation build configuration file, created by
# sphinx-quickstart on Sat Feb 27 15:17:42 2016.
diff --git a/examples/main.py b/examples/main.py
index f36f1be4..e8d6798a 100644
--- a/examples/main.py
+++ b/examples/main.py
@@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: Apache-2.0
-from __future__ import print_function
import sys
import os
import os.path as op
@@ -24,7 +23,7 @@
def setup_environment():
print("Setup solnlib demo environment...")
- print("Copying %s to %s" % (source_dir, target_dir))
+ print("Copying {} to {}".format(source_dir, target_dir))
shutil.copytree(source_dir, target_dir)
shutil.copytree(solnlib_lib_dir, solnlib_lib_target_dir)
os.system(splunk_bin + " start")
diff --git a/examples/test__kvstore.py b/examples/test__kvstore.py
index 23e4da55..2b17d544 100644
--- a/examples/test__kvstore.py
+++ b/examples/test__kvstore.py
@@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: Apache-2.0
-from builtins import range
import json
import os.path as op
import sys
diff --git a/examples/test_credentials.py b/examples/test_credentials.py
index df44afcf..7b61d167 100644
--- a/examples/test_credentials.py
+++ b/examples/test_credentials.py
@@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: Apache-2.0
-from builtins import range
import sys
import os.path as op
import pytest
diff --git a/examples/test_hec_event_writer.py b/examples/test_hec_event_writer.py
index ac81e337..36e6fbe2 100644
--- a/examples/test_hec_event_writer.py
+++ b/examples/test_hec_event_writer.py
@@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: Apache-2.0
-from builtins import range
import sys
import os.path as op
diff --git a/examples/test_metadata.py b/examples/test_metadata.py
index bdad5abe..7955c63e 100644
--- a/examples/test_metadata.py
+++ b/examples/test_metadata.py
@@ -15,7 +15,7 @@ def test_metadata_reader():
mr = metadata.MetadataReader(context.app)
modtime = mr.get("collections", "sessions", "modtime")
- assert isinstance(modtime, six.text_type)
+ assert isinstance(modtime, str)
modtime = mr.get_float("collections", "sessions", "modtime")
assert type(modtime) == float
diff --git a/examples/test_server_info.py b/examples/test_server_info.py
index 8c44cd07..70be6369 100644
--- a/examples/test_server_info.py
+++ b/examples/test_server_info.py
@@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: Apache-2.0
-from __future__ import print_function
import os.path as op
import sys
diff --git a/examples/test_user_access.py b/examples/test_user_access.py
index cccf5c1f..1f8ba3a3 100644
--- a/examples/test_user_access.py
+++ b/examples/test_user_access.py
@@ -53,7 +53,7 @@ def test_object_acl_manager():
replace_existing=False,
)
obj_acl = oaclm.get_acl(obj_collection, obj_id1)
- assert set((obj_acl.obj_perms["read"])) == set(["admin", "user1"])
+ assert set(obj_acl.obj_perms["read"]) == {"admin", "user1"}
oaclm.update_acls(
obj_collection,
diff --git a/solnlib/acl.py b/solnlib/acl.py
index 83a38aea..69a08cde 100644
--- a/solnlib/acl.py
+++ b/solnlib/acl.py
@@ -20,7 +20,7 @@ class ACLException(Exception):
pass
-class ACLManager(object):
+class ACLManager:
"""ACL manager.
:param session_key: Splunk access token.
diff --git a/solnlib/api_documenter.py b/solnlib/api_documenter.py
index 2285d655..066e86f6 100644
--- a/solnlib/api_documenter.py
+++ b/solnlib/api_documenter.py
@@ -401,7 +401,7 @@ def _generate_documentation(context, method_list):
generator.update_spec()
-class _SwaggerSpecGenerator(object):
+class _SwaggerSpecGenerator:
"""Private class to generate the swagger spec file."""
def __init__(self, swagger_api):
@@ -451,7 +451,7 @@ def update_spec(self):
)
-class _SwaggerApi(object):
+class _SwaggerApi:
"""
Private class to generate the swagger
documentation and default params values.
@@ -459,7 +459,7 @@ class _SwaggerApi(object):
def __init__(self):
if op.isfile(tempfile.gettempdir() + op.sep + "temp.yaml"):
- with open(tempfile.gettempdir() + op.sep + "temp.yaml", "r") as stream:
+ with open(tempfile.gettempdir() + op.sep + "temp.yaml") as stream:
try:
spec = yaml.safe_load(stream)
self.swagger = spec["swagger"]
@@ -606,10 +606,10 @@ def create_model(self, params, name, req):
definition["requirements"] = req
for param in params:
# get type of property
- type_info = re.findall("\((.*?)\)\s", str(params.get(param)), re.DOTALL)
+ type_info = re.findall(r"\((.*?)\)\s", str(params.get(param)), re.DOTALL)
if type_info and len(type_info) > 0:
type_info = type_info[0]
- prop_type = re.findall("\<(.*?)\(", str(params.get(param)), re.DOTALL)
+ prop_type = re.findall(r"\<(.*?)\(", str(params.get(param)), re.DOTALL)
if prop_type and len(prop_type) > 0:
prop_type = prop_type[0]
if prop_type in self.type_converter:
diff --git a/solnlib/compression.py b/solnlib/compression.py
index 68e6a8c4..62608e9e 100644
--- a/solnlib/compression.py
+++ b/solnlib/compression.py
@@ -16,7 +16,7 @@
__all__ = ["GzipHandler", "ZipHandler"]
-class GzipHandler(object):
+class GzipHandler:
"""
Class for handling gzip-formatted string content.
"""
@@ -57,7 +57,7 @@ def decompress(cls, data):
return gzip.GzipFile(fileobj=BytesIO(data), mode="rb").read()
-class ZipHandler(object):
+class ZipHandler:
"""
Class for handling zip files.
"""
diff --git a/solnlib/conf_manager.py b/solnlib/conf_manager.py
index fa1ca66b..5d6199e1 100644
--- a/solnlib/conf_manager.py
+++ b/solnlib/conf_manager.py
@@ -31,7 +31,7 @@ class ConfStanzaNotExistException(Exception):
pass
-class ConfFile(object):
+class ConfFile:
"""Configuration file.
:param name: Configuration file name.
@@ -211,12 +211,12 @@ def get(self, stanza_name, only_current_app=False):
raise
raise ConfStanzaNotExistException(
- "Stanza: %s does not exist in %s.conf" % (stanza_name, self._name)
+ "Stanza: {} does not exist in {}.conf".format(stanza_name, self._name)
)
if len(stanza_mgrs) == 0:
raise ConfStanzaNotExistException(
- "Stanza: %s does not exist in %s.conf" % (stanza_name, self._name)
+ "Stanza: {} does not exist in {}.conf".format(stanza_name, self._name)
)
stanza = self._decrypt_stanza(stanza_mgrs[0].name, stanza_mgrs[0].content)
@@ -326,7 +326,7 @@ def delete(self, stanza_name):
"Delete stanza: %s error: %s.", stanza_name, traceback.format_exc()
)
raise ConfStanzaNotExistException(
- "Stanza: %s does not exist in %s.conf" % (stanza_name, self._name)
+ "Stanza: {} does not exist in {}.conf".format(stanza_name, self._name)
)
@retry(exceptions=[binding.HTTPError])
@@ -349,7 +349,7 @@ class ConfManagerException(Exception):
pass
-class ConfManager(object):
+class ConfManager:
"""Configuration file manager.
:param session_key: Splunk access token.
diff --git a/solnlib/credentials.py b/solnlib/credentials.py
index c1e15b7f..c0419867 100644
--- a/solnlib/credentials.py
+++ b/solnlib/credentials.py
@@ -35,7 +35,7 @@ class CredentialNotExistException(Exception):
pass
-class CredentialManager(object):
+class CredentialManager:
"""Credential manager.
:param session_key: Splunk access token.
@@ -125,7 +125,7 @@ def get_password(self, user):
return password["clear_password"]
raise CredentialNotExistException(
- "Failed to get password of realm=%s, user=%s." % (self._realm, user)
+ "Failed to get password of realm={}, user={}.".format(self._realm, user)
)
@retry(exceptions=[binding.HTTPError])
@@ -211,7 +211,7 @@ def delete_password(self, user):
"""
all_passwords = self._get_all_passwords_in_realm()
deleted = False
- ent_pattern = re.compile("(%s%s\d+)" % (user.replace("\\", "\\\\"), self.SEP))
+ ent_pattern = re.compile(r"({}{}\d+)".format(user.replace("\\", "\\\\"), self.SEP))
for password in list(all_passwords):
match = (user == password.username) or ent_pattern.match(password.username)
if match and password.realm == self._realm:
@@ -220,7 +220,7 @@ def delete_password(self, user):
if not deleted:
raise CredentialNotExistException(
- "Failed to delete password of realm=%s, user=%s" % (self._realm, user)
+ "Failed to delete password of realm={}, user={}".format(self._realm, user)
)
def _get_all_passwords_in_realm(self):
diff --git a/solnlib/file_monitor.py b/solnlib/file_monitor.py
index e4a4af07..cb7994bd 100644
--- a/solnlib/file_monitor.py
+++ b/solnlib/file_monitor.py
@@ -18,7 +18,7 @@
__all__ = ["FileChangesChecker", "FileMonitor"]
-class FileChangesChecker(object):
+class FileChangesChecker:
"""Files change checker.
:param callback: Callback function for files change.
@@ -67,7 +67,7 @@ def check_changes(self):
return False
-class FileMonitor(object):
+class FileMonitor:
"""Files change monitor.
Monitor files change in a separated thread and call callback
diff --git a/solnlib/hec_config.py b/solnlib/hec_config.py
index 37fea9b5..e18ca402 100644
--- a/solnlib/hec_config.py
+++ b/solnlib/hec_config.py
@@ -10,7 +10,7 @@
__all__ = ["HECConfig"]
-class HECConfig(object):
+class HECConfig:
"""HTTP Event Collector configuration.
:param session_key: Splunk access token.
diff --git a/solnlib/log.py b/solnlib/log.py
index b23abc3f..b26d1811 100644
--- a/solnlib/log.py
+++ b/solnlib/log.py
@@ -50,7 +50,7 @@ class LogException(Exception):
pass
-class Logs(with_metaclass(Singleton, object)):
+class Logs(metaclass=Singleton):
"""A singleton class that manage all kinds of logger.
Usage::
diff --git a/solnlib/metadata.py b/solnlib/metadata.py
index e7021e1f..c0057c6a 100644
--- a/solnlib/metadata.py
+++ b/solnlib/metadata.py
@@ -24,7 +24,7 @@
__all__ = ["MetadataReader"]
-class MetadataReader(object):
+class MetadataReader:
"""Metadata reader for `app`.
:param app: App name.
@@ -46,7 +46,7 @@ def __init__(self, app):
# May raise ConfigParser.ParsingError
self._cfg.read(local_meta)
else:
- raise IOError("No such file: %s." % local_meta)
+ raise OSError("No such file: %s." % local_meta)
def get(self, conf, stanza, option):
"""Return the metadata value of option in [conf/stanza] section.
diff --git a/solnlib/modular_input/checkpointer.py b/solnlib/modular_input/checkpointer.py
index 4ea71019..72aa2f33 100644
--- a/solnlib/modular_input/checkpointer.py
+++ b/solnlib/modular_input/checkpointer.py
@@ -29,7 +29,7 @@ class CheckpointerException(Exception):
pass
-class Checkpointer(with_metaclass(ABCMeta, object)):
+class Checkpointer(metaclass=ABCMeta):
"""Base class of checkpointer."""
@abstractmethod
@@ -264,7 +264,7 @@ def update(self, key, state):
if op.exists(file_name):
try:
os.remove(file_name)
- except IOError:
+ except OSError:
pass
os.rename(file_name + "_new", file_name)
@@ -276,9 +276,9 @@ def batch_update(self, states):
def get(self, key):
file_name = op.join(self._checkpoint_dir, self.encode_key(key))
try:
- with open(file_name, "r") as fp:
+ with open(file_name) as fp:
return json.load(fp)
- except (IOError, ValueError):
+ except (OSError, ValueError):
return None
def delete(self, key):
diff --git a/solnlib/modular_input/event.py b/solnlib/modular_input/event.py
index d3297eb6..597f10c1 100644
--- a/solnlib/modular_input/event.py
+++ b/solnlib/modular_input/event.py
@@ -10,7 +10,7 @@
import json
try:
- import xml.etree.cElementTree as ET
+ import xml.etree.ElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
@@ -32,7 +32,7 @@ class EventException(Exception):
pass
-class Event(object):
+class Event:
"""Base class of modular input event."""
def __init__(
diff --git a/solnlib/modular_input/event_writer.py b/solnlib/modular_input/event_writer.py
index 185b533e..1a2e363f 100644
--- a/solnlib/modular_input/event_writer.py
+++ b/solnlib/modular_input/event_writer.py
@@ -28,7 +28,7 @@
__all__ = ["ClassicEventWriter", "HECEventWriter"]
-class EventWriter(with_metaclass(ABCMeta, object)):
+class EventWriter(metaclass=ABCMeta):
"""Base class of event writer."""
description = "EventWriter"
@@ -221,7 +221,7 @@ def __init__(
logger=None,
**context
):
- super(HECEventWriter, self).__init__()
+ super().__init__()
self._session_key = session_key
if logger:
self.logger = logger
diff --git a/solnlib/modular_input/modular_input.py b/solnlib/modular_input/modular_input.py
index 7cc061a3..345768ea 100644
--- a/solnlib/modular_input/modular_input.py
+++ b/solnlib/modular_input/modular_input.py
@@ -26,7 +26,7 @@
from six import with_metaclass
try:
- import xml.etree.cElementTree as ET
+ import xml.etree.ElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
@@ -51,7 +51,7 @@ class ModularInputException(Exception):
pass
-class ModularInput(with_metaclass(ABCMeta, object)):
+class ModularInput(metaclass=ABCMeta):
"""Base class of Splunk modular input.
It's a base modular input, it should be inherited by sub modular input. For
diff --git a/solnlib/net_utils.py b/solnlib/net_utils.py
index 80f8aab4..ef894d1c 100644
--- a/solnlib/net_utils.py
+++ b/solnlib/net_utils.py
@@ -61,7 +61,7 @@ def is_valid_hostname(hostname):
return False
if hostname[-1:] == ".":
hostname = hostname[:-1]
- allowed = re.compile("(?!-)(::)?[A-Z\d-]{1,63}(?mainlocalhostSplunkmiscThis is a test data3.'
]
assert XMLEvent.format_events([self.xe4]) == [
- u'mainlocalhostSplunkmiscThis is utf-8 \u2603 data4.'
+ 'mainlocalhostSplunkmiscThis is utf-8 \u2603 data4.'
]
-class TestHECEvent(object):
+class TestHECEvent:
@classmethod
def setup_class(cls):
cls.he1 = HECEvent(
diff --git a/tests/test_modular_input_event_writer.py b/tests/test_modular_input_event_writer.py
index 9cf4aab5..ac95cc5b 100644
--- a/tests/test_modular_input_event_writer.py
+++ b/tests/test_modular_input_event_writer.py
@@ -14,7 +14,7 @@
def test_classic_event_writer(monkeypatch):
- class MockStdout(object):
+ class MockStdout:
def __init__(self):
self._buf = ""
self.write_count = 0
diff --git a/tests/test_orphan_process_monitor.py b/tests/test_orphan_process_monitor.py
index 17db6399..41a97fbc 100644
--- a/tests/test_orphan_process_monitor.py
+++ b/tests/test_orphan_process_monitor.py
@@ -16,7 +16,7 @@ def _mock_getppid():
return random.randint(1, 65535)
-class TestOrphanProcessChecker(object):
+class TestOrphanProcessChecker:
def setup(self):
self._called = False
@@ -34,7 +34,7 @@ def orphan_callback():
assert self._called
-class TestOrphanProcessMonitor(object):
+class TestOrphanProcessMonitor:
def setup(self):
self._called = False
diff --git a/tests/test_server_info.py b/tests/test_server_info.py
index 35cf742d..0bfe55c5 100644
--- a/tests/test_server_info.py
+++ b/tests/test_server_info.py
@@ -12,7 +12,7 @@
from splunklib import binding
-class TestServerInfo(object):
+class TestServerInfo:
def test_server_name(self, monkeypatch):
common.mock_splunkhome(monkeypatch)
common.mock_serverinfo(monkeypatch)
@@ -69,7 +69,7 @@ def _mock_get(self, path_segment, owner=None, app=None, sharing=None, **query):
assert si.get_shc_members() == [
("SHC01_SearchHead02_1_85", "https://192.168.1.85:8089"),
("SHC01_SearchHead03_1_86", "https://192.168.1.86:8089"),
- ("SHC01_SearchHead01_1_84", u"https://192.168.1.84:8089"),
+ ("SHC01_SearchHead01_1_84", "https://192.168.1.84:8089"),
]
def test_is_captain_ready(self, monkeypatch):