From 28e93b5a0df78ac1cf2dfa202359f8c8194cce8c Mon Sep 17 00:00:00 2001 From: vmalaviya Date: Thu, 2 Dec 2021 14:46:31 +0530 Subject: [PATCH] ordereddict and all its reference removed --- examples/twitted/twitted/bin/tophashtags.py | 5 +- splunklib/ordereddict.py | 128 -------------------- splunklib/results.py | 5 +- splunklib/searchcommands/decorators.py | 5 +- splunklib/searchcommands/internals.py | 5 +- splunklib/searchcommands/search_command.py | 5 +- tests/searchcommands/test_internals_v2.py | 5 +- tests/test_job.py | 10 +- 8 files changed, 8 insertions(+), 160 deletions(-) delete mode 100644 splunklib/ordereddict.py diff --git a/examples/twitted/twitted/bin/tophashtags.py b/examples/twitted/twitted/bin/tophashtags.py index 6df5765f1..499f9f389 100755 --- a/examples/twitted/twitted/bin/tophashtags.py +++ b/examples/twitted/twitted/bin/tophashtags.py @@ -19,10 +19,7 @@ import os sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir))) -try: - from collections import OrderedDict # must be python 2.7 -except ImportError: - from splunklib.ordereddict import OrderedDict +from collections import OrderedDict from splunklib import six from splunklib.six.moves import zip diff --git a/splunklib/ordereddict.py b/splunklib/ordereddict.py deleted file mode 100644 index 9495566cf..000000000 --- a/splunklib/ordereddict.py +++ /dev/null @@ -1,128 +0,0 @@ -# Copyright (c) 2009 Raymond Hettinger -# -# Permission is hereby granted, free of charge, to any person -# obtaining a copy of this software and associated documentation files -# (the "Software"), to deal in the Software without restriction, -# including without limitation the rights to use, copy, modify, merge, -# publish, distribute, sublicense, and/or sell copies of the Software, -# and to permit persons to whom the Software is furnished to do so, -# subject to the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -# OTHER DEALINGS IN THE SOFTWARE. - -from UserDict import DictMixin - - -class OrderedDict(dict, DictMixin): - - def __init__(self, *args, **kwds): - if len(args) > 1: - raise TypeError('expected at most 1 arguments, got %d' % len(args)) - try: - self.__end - except AttributeError: - self.clear() - self.update(*args, **kwds) - - def clear(self): - self.__end = end = [] - end += [None, end, end] # sentinel node for doubly linked list - self.__map = {} # key --> [key, prev, next] - dict.clear(self) - - def __setitem__(self, key, value): - if key not in self: - end = self.__end - curr = end[1] - curr[2] = end[1] = self.__map[key] = [key, curr, end] - dict.__setitem__(self, key, value) - - def __delitem__(self, key): - dict.__delitem__(self, key) - key, prev, next = self.__map.pop(key) - prev[2] = next - next[1] = prev - - def __iter__(self): - end = self.__end - curr = end[2] - while curr is not end: - yield curr[0] - curr = curr[2] - - def __reversed__(self): - end = self.__end - curr = end[1] - while curr is not end: - yield curr[0] - curr = curr[1] - - def popitem(self, last=True): - if not self: - raise KeyError('dictionary is empty') - if last: - key = reversed(self).next() - else: - key = iter(self).next() - value = self.pop(key) - return key, value - - def __reduce__(self): - items = [[k, self[k]] for k in self] - tmp = self.__map, self.__end - del self.__map, self.__end - inst_dict = vars(self).copy() - self.__map, self.__end = tmp - if inst_dict: - return (self.__class__, (items,), inst_dict) - return self.__class__, (items,) - - def keys(self): - return list(self) - - setdefault = DictMixin.setdefault - update = DictMixin.update - pop = DictMixin.pop - values = DictMixin.values - items = DictMixin.items - iterkeys = DictMixin.iterkeys - itervalues = DictMixin.itervalues - iteritems = DictMixin.iteritems - - def __repr__(self): - if not self: - return '%s()' % (self.__class__.__name__,) - return '%s(%r)' % (self.__class__.__name__, self.items()) - - def copy(self): - return self.__class__(self) - - @classmethod - def fromkeys(cls, iterable, value=None): - d = cls() - for key in iterable: - d[key] = value - return d - - def __eq__(self, other): - if isinstance(other, OrderedDict): - if len(self) != len(other): - return False - for p, q in zip(self.items(), other.items()): - if p != q: - return False - return True - return dict.__eq__(self, other) - - def __ne__(self, other): - return not self == other diff --git a/splunklib/results.py b/splunklib/results.py index 20501c5b7..66e9ad7d1 100644 --- a/splunklib/results.py +++ b/splunklib/results.py @@ -42,10 +42,7 @@ except: import xml.etree.ElementTree as et -try: - from collections import OrderedDict # must be python 2.7 -except ImportError: - from .ordereddict import OrderedDict +from collections import OrderedDict try: from splunklib.six.moves import cStringIO as StringIO diff --git a/splunklib/searchcommands/decorators.py b/splunklib/searchcommands/decorators.py index 36590a76b..d8b3f48cc 100644 --- a/splunklib/searchcommands/decorators.py +++ b/splunklib/searchcommands/decorators.py @@ -17,10 +17,7 @@ from __future__ import absolute_import, division, print_function, unicode_literals from splunklib import six -try: - from collections import OrderedDict # must be python 2.7 -except ImportError: - from ..ordereddict import OrderedDict +from collections import OrderedDict # must be python 2.7 from inspect import getmembers, isclass, isfunction from splunklib.six.moves import map as imap diff --git a/splunklib/searchcommands/internals.py b/splunklib/searchcommands/internals.py index fa32f0b1c..1ea2833db 100644 --- a/splunklib/searchcommands/internals.py +++ b/splunklib/searchcommands/internals.py @@ -19,10 +19,7 @@ from io import TextIOWrapper from collections import deque, namedtuple from splunklib import six -try: - from collections import OrderedDict # must be python 2.7 -except ImportError: - from ..ordereddict import OrderedDict +from collections import OrderedDict from splunklib.six.moves import StringIO from itertools import chain from splunklib.six.moves import map as imap diff --git a/splunklib/searchcommands/search_command.py b/splunklib/searchcommands/search_command.py index 5a626cc5c..b3cba7b61 100644 --- a/splunklib/searchcommands/search_command.py +++ b/splunklib/searchcommands/search_command.py @@ -22,10 +22,7 @@ import io -try: - from collections import OrderedDict # must be python 2.7 -except ImportError: - from ..ordereddict import OrderedDict +from collections import OrderedDict from copy import deepcopy from splunklib.six.moves import StringIO from itertools import chain, islice diff --git a/tests/searchcommands/test_internals_v2.py b/tests/searchcommands/test_internals_v2.py index 34e6b61c4..c221cc53c 100755 --- a/tests/searchcommands/test_internals_v2.py +++ b/tests/searchcommands/test_internals_v2.py @@ -21,10 +21,7 @@ from splunklib.searchcommands import SearchMetric from splunklib import six from splunklib.six.moves import range -try: - from collections import OrderedDict # must be python 2.7 -except ImportError: - from splunklib.ordereddict import OrderedDict +from collections import OrderedDict from collections import namedtuple, deque from splunklib.six import BytesIO as BytesIO from functools import wraps diff --git a/tests/test_job.py b/tests/test_job.py index dc4c3e4e7..4de34b611 100755 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -389,10 +389,7 @@ def test_results_reader(self): N_results = 0 N_messages = 0 for r in reader: - try: - from collections import OrderedDict - except: - from splunklib.ordereddict import OrderedDict + from collections import OrderedDict self.assertTrue(isinstance(r, OrderedDict) or isinstance(r, results.Message)) if isinstance(r, OrderedDict): @@ -411,10 +408,7 @@ def test_results_reader_with_streaming_results(self): N_results = 0 N_messages = 0 for r in reader: - try: - from collections import OrderedDict - except: - from splunklib.ordereddict import OrderedDict + from collections import OrderedDict self.assertTrue(isinstance(r, OrderedDict) or isinstance(r, results.Message)) if isinstance(r, OrderedDict):