Last active
May 12, 2020 09:39
-
-
Save OrangeDog/b3c6a0a577ebcaa90d578941e198ac87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- salt/client/mixins.py | |
+++ salt/client/mixins.py | |
@@ -10,8 +10,8 @@ | |
import logging | |
import weakref | |
import traceback | |
-import collections | |
import copy as pycopy | |
+from collections.abc import Mapping, MutableMapping | |
# Import Salt libs | |
import salt.exceptions | |
@@ -55,7 +55,7 @@ | |
]) | |
-class ClientFuncsDict(collections.MutableMapping): | |
+class ClientFuncsDict(MutableMapping): | |
''' | |
Class to make a read-only dict for accessing runner funcs "directly" | |
''' | |
@@ -141,9 +141,9 @@ | |
crypt='clear', | |
usage='master_call') as channel: | |
ret = channel.send(load) | |
- if isinstance(ret, collections.Mapping): | |
+ if isinstance(ret, Mapping): | |
if 'error' in ret: | |
- salt.utils.error.raise_error(**ret['error']) | |
+ salt.utils.error.raise_error(**ret["error"]) | |
return ret | |
def cmd_sync(self, low, timeout=None, full_return=False): | |
--- salt/cloud/clouds/softlayer_hw.py | |
+++ salt/cloud/clouds/softlayer_hw.py | |
@@ -137,7 +137,7 @@ | |
available = conn.getAvailableLocations(id=50) | |
for location in available: | |
- if location.get('isAvailable', 0) is 0: | |
+ if location.get('isAvailable', 0) == 0: | |
continue | |
ret[location['locationId']]['available'] = True | |
--- salt/config/__init__.py | |
+++ salt/config/__init__.py | |
@@ -3191,7 +3191,9 @@ | |
# Merge provided extends | |
keep_looping = False | |
for alias, entries in six.iteritems(providers.copy()): | |
- for driver, details in six.iteritems(entries): | |
+ for driver in list(six.iterkeys(entries)): | |
+ # Don't use iteritems, because the values of the dictionary will be changed | |
+ details = entries[driver] | |
if 'extends' not in details: | |
# Extends resolved or non existing, continue! | |
--- salt/daemons/__init__.py | |
+++ salt/daemons/__init__.py | |
@@ -6,12 +6,7 @@ | |
from __future__ import absolute_import, print_function, unicode_literals | |
# Import Python Libs | |
import sys | |
- | |
-try: | |
- from collections.abc import Iterable, Sequence, Mapping | |
-except ImportError: | |
- from collections import Iterable, Sequence, Mapping | |
- | |
+from collections.abc import Iterable, Mapping, Sequence | |
import logging | |
# Import Salt Libs | |
--- salt/ext/tornado/httputil.py | |
+++ salt/ext/tornado/httputil.py | |
@@ -31,6 +31,7 @@ | |
import numbers | |
import re | |
import time | |
+from collections.abc import MutableMapping | |
from salt.ext.tornado.escape import native_str, parse_qs_bytes, utf8 | |
from salt.ext.tornado.log import gen_log | |
@@ -104,7 +105,7 @@ | |
_normalized_headers = _NormalizedHeaderCache(1000) | |
-class HTTPHeaders(collections.MutableMapping): | |
+class HTTPHeaders(MutableMapping): | |
"""A dictionary that maintains ``Http-Header-Case`` for all keys. | |
Supports multiple values per key via a pair of new methods, | |
--- salt/fileserver/__init__.py | |
+++ salt/fileserver/__init__.py | |
@@ -13,6 +13,7 @@ | |
import re | |
import sys | |
import time | |
+from collections.abc import Sequence | |
# Import salt libs | |
import salt.loader | |
@@ -24,11 +25,6 @@ | |
from salt.utils.args import get_function_argspec as _argspec | |
from salt.utils.decorators import ensure_unicode_args | |
-try: | |
- from collections.abc import Sequence | |
-except ImportError: | |
- from collections import Sequence | |
- | |
# Import 3rd-party libs | |
from salt.ext import six | |
--- salt/grains/core.py | |
+++ salt/grains/core.py | |
@@ -12,18 +12,37 @@ | |
# Import python libs | |
from __future__ import absolute_import, print_function, unicode_literals | |
+import datetime | |
import os | |
import socket | |
import sys | |
import re | |
import platform | |
+import time | |
import logging | |
import locale | |
import uuid | |
+import warnings | |
from errno import EACCES, EPERM | |
-import datetime | |
-import warnings | |
-import time | |
+ | |
+# Import salt libs | |
+import salt.exceptions | |
+import salt.log | |
+ | |
+# Solve the Chicken and egg problem where grains need to run before any | |
+# of the modules are loaded and are generally available for any usage. | |
+import salt.modules.cmdmod | |
+import salt.modules.smbios | |
+import salt.utils.args | |
+import salt.utils.dns | |
+import salt.utils.files | |
+import salt.utils.network | |
+import salt.utils.path | |
+import salt.utils.pkg.rpm | |
+import salt.utils.platform | |
+import salt.utils.stringutils | |
+from salt.ext import six | |
+from salt.ext.six.moves import range | |
# pylint: disable=import-error | |
try: | |
@@ -35,20 +54,36 @@ | |
__proxyenabled__ = ['*'] | |
__FQDN__ = None | |
-# Extend the default list of supported distros. This will be used for the | |
-# /etc/DISTRO-release checking that is part of linux_distribution() | |
-from platform import _supported_dists | |
-_supported_dists += ('arch', 'mageia', 'meego', 'vmware', 'bluewhite64', | |
- 'slamd64', 'ovs', 'system', 'mint', 'oracle', 'void') | |
+# linux_distribution deprecated in py3.7 | |
+try: | |
+ from platform import linux_distribution as _deprecated_linux_distribution | |
+ | |
+ # Extend the default list of supported distros. This will be used for the | |
+ # /etc/DISTRO-release checking that is part of linux_distribution() | |
+ from platform import _supported_dists | |
-# linux_distribution deprecated in py3.7 | |
-try: | |
- from platform import linux_distribution as _deprecated_linux_distribution | |
+ _supported_dists += ( | |
+ "arch", | |
+ "mageia", | |
+ "meego", | |
+ "vmware", | |
+ "bluewhite64", | |
+ "slamd64", | |
+ "ovs", | |
+ "system", | |
+ "mint", | |
+ "oracle", | |
+ "void", | |
+ ) | |
def linux_distribution(**kwargs): | |
with warnings.catch_warnings(): | |
warnings.simplefilter("ignore") | |
- return _deprecated_linux_distribution(**kwargs) | |
+ return _deprecated_linux_distribution( | |
+ supported_dists=_supported_dists, **kwargs | |
+ ) | |
+ | |
+ | |
except ImportError: | |
from distro import linux_distribution | |
@@ -1937,9 +1972,9 @@ | |
'Getting OS name, release, and codename from ' | |
'platform.linux_distribution()' | |
) | |
- (osname, osrelease, oscodename) = \ | |
- [x.strip('"').strip("'") for x in | |
- linux_distribution(supported_dists=_supported_dists)] | |
+ (osname, osrelease, oscodename) = [ | |
+ x.strip('"').strip("'") for x in linux_distribution() | |
+ ] | |
# Try to assign these three names based on the lsb info, they tend to | |
# be more accurate than what python gets from /etc/DISTRO-release. | |
# It's worth noting that Ubuntu has patched their Python distribution | |
--- salt/loader.py | |
+++ salt/loader.py | |
@@ -18,6 +18,7 @@ | |
import threading | |
import traceback | |
import types | |
+from collections.abc import MutableMapping | |
from zipimport import zipimporter | |
# Import salt libs | |
@@ -51,11 +52,6 @@ | |
import imp | |
USE_IMPORTLIB = False | |
-try: | |
- from collections.abc import MutableMapping | |
-except ImportError: | |
- from collections import MutableMapping | |
- | |
try: | |
import pkg_resources | |
HAS_PKG_RESOURCES = True | |
--- salt/modules/boto_route53.py | |
+++ salt/modules/boto_route53.py | |
@@ -158,7 +158,7 @@ | |
else: | |
marker = None | |
ret = None | |
- while marker is not '': | |
+ while marker != "": | |
r = conn.get_all_hosted_zones(start_marker=marker, | |
zone_list=ret) | |
ret = r['ListHostedZonesResponse']['HostedZones'] | |
--- salt/modules/file.py | |
+++ salt/modules/file.py | |
@@ -29,7 +29,8 @@ | |
import glob | |
import hashlib | |
import mmap | |
-from collections import Iterable, Mapping, namedtuple | |
+from collections import namedtuple | |
+from collections.abc import Iterable, Mapping | |
from functools import reduce # pylint: disable=redefined-builtin | |
# pylint: disable=import-error,no-name-in-module,redefined-builtin | |
@@ -2744,7 +2745,7 @@ | |
if block_found: | |
diff = __utils__['stringutils.get_diff'](orig_file, new_file) | |
- has_changes = diff is not '' | |
+ has_changes = diff != '' | |
if has_changes and not dry_run: | |
# changes detected | |
# backup file attrs | |
--- salt/modules/iptables.py | |
+++ salt/modules/iptables.py | |
@@ -905,7 +905,7 @@ | |
rules = get_rules(family=family) | |
size = len(rules[table][chain]['rules']) | |
position = (size + position) + 1 | |
- if position is 0: | |
+ if position == 0: | |
position = 1 | |
wait = '--wait' if _has_option('--wait', family) else '' | |
@@ -1040,7 +1040,7 @@ | |
ret_args = {} | |
chain = parsed_args['append'] | |
for arg in parsed_args: | |
- if parsed_args[arg] and arg is not 'append': | |
+ if parsed_args[arg] and arg != 'append': | |
ret_args[arg] = parsed_args[arg] | |
if parsed_args['comment'] is not None: | |
comment = parsed_args['comment'][0].strip('"') | |
--- salt/modules/lxd.py | |
+++ salt/modules/lxd.py | |
@@ -1824,11 +1824,11 @@ | |
if mode: | |
os.chmod(dst, mode) | |
- if uid or uid is '0': | |
+ if uid or uid == '0': | |
uid = int(uid) | |
else: | |
uid = -1 | |
- if gid or gid is '0': | |
+ if gid or gid == '0': | |
gid = int(gid) | |
else: | |
gid = -1 | |
--- salt/modules/mongodb.py | |
+++ salt/modules/mongodb.py | |
@@ -484,7 +484,7 @@ | |
objects = six.text_type(objects) | |
objs = re.split(r'}\s+{', objects) | |
- if len(objs) is not 2: | |
+ if len(objs) != 2: | |
return "Your request does not contain a valid " + \ | |
"'{_\"id\": \"my_id\"} {\"my_doc\": \"my_val\"}'" | |
--- salt/modules/pillar.py | |
+++ salt/modules/pillar.py | |
@@ -5,7 +5,7 @@ | |
from __future__ import absolute_import, print_function, unicode_literals | |
# Import python libs | |
-import collections | |
+from collections.abc import Mapping | |
# Import third party libs | |
import copy | |
@@ -143,7 +143,7 @@ | |
key, | |
{}, | |
delimiter) | |
- if isinstance(ret, collections.Mapping): | |
+ if isinstance(ret, Mapping): | |
default = copy.deepcopy(default) | |
return salt.utils.dictupdate.update( | |
default, | |
--- salt/modules/virt.py | |
+++ salt/modules/virt.py | |
@@ -4737,7 +4737,7 @@ | |
if options: | |
if 'options' not in pool_caps: | |
pool_caps['options'] = {} | |
- kind = option_kind if option_kind is not 'vol' else 'volume' | |
+ kind = option_kind if option_kind != 'vol' else 'volume' | |
pool_caps['options'][kind] = options | |
return pool_caps | |
--- salt/modules/win_file.py | |
+++ salt/modules/win_file.py | |
@@ -17,7 +17,7 @@ | |
import logging | |
# pylint: disable=W0611 | |
import operator # do not remove | |
-from collections import Iterable, Mapping # do not remove | |
+from collections.abc import Iterable, Mapping # do not remove | |
from functools import reduce # do not remove | |
import datetime # do not remove. | |
import tempfile # do not remove. Used in salt.modules.file.__clean_tmp | |
--- salt/modules/win_ip.py | |
+++ salt/modules/win_ip.py | |
@@ -342,7 +342,7 @@ | |
salt -G 'os_family:Windows' ip.set_static_dns 'Local Area Connection' '192.168.1.1' | |
salt -G 'os_family:Windows' ip.set_static_dns 'Local Area Connection' '192.168.1.252' '192.168.1.253' | |
''' | |
- if addrs is () or str(addrs[0]).lower() == 'none': | |
+ if addrs == () or str(addrs[0]).lower() == 'none': | |
return {'Interface': iface, 'DNS Server': 'No Changes'} | |
# Clear the list of DNS servers if [] is passed | |
if str(addrs[0]).lower() == '[]': | |
--- salt/modules/win_lgpo.py | |
+++ salt/modules/win_lgpo.py | |
@@ -4692,7 +4692,7 @@ | |
return 'true' | |
elif val.upper() == 'Run Windows PowerShell scripts last'.upper(): | |
return 'false' | |
- elif val is 'Not Configured': | |
+ elif val == 'Not Configured': | |
return None | |
else: | |
return 'Invalid Value' | |
--- salt/modules/win_system.py | |
+++ salt/modules/win_system.py | |
@@ -1149,7 +1149,7 @@ | |
system_time.wSecond = int(seconds) | |
system_time_ptr = ctypes.pointer(system_time) | |
succeeded = ctypes.windll.kernel32.SetLocalTime(system_time_ptr) | |
- if succeeded is not 0: | |
+ if succeeded != 0: | |
return True | |
else: | |
log.error('Failed to set local time') | |
--- salt/modules/x509.py | |
+++ salt/modules/x509.py | |
@@ -131,7 +131,7 @@ | |
to create the authoritykeyidentifier extension. | |
''' | |
if name == 'subjectKeyIdentifier' and \ | |
- value.strip('0123456789abcdefABCDEF:') is not '': | |
+ value.strip('0123456789abcdefABCDEF:') != '': | |
raise salt.exceptions.SaltInvocationError( | |
'value must be precomputed hash') | |
--- salt/output/highstate.py | |
+++ salt/output/highstate.py | |
@@ -209,7 +209,7 @@ | |
# Verify that the needed data is present | |
data_tmp = {} | |
for tname, info in six.iteritems(data): | |
- if isinstance(info, dict) and tname is not 'changes' and info and '__run_num__' not in info: | |
+ if isinstance(info, dict) and tname != 'changes' and info and '__run_num__' not in info: | |
err = ('The State execution failed to record the order ' | |
'in which all states were executed. The state ' | |
'return missing data is:') | |
--- salt/output/nested.py | |
+++ salt/output/nested.py | |
@@ -25,6 +25,7 @@ | |
''' | |
from __future__ import absolute_import, print_function, unicode_literals | |
# Import python libs | |
+from collections.abc import Mapping | |
from numbers import Number | |
# Import salt libs | |
@@ -34,11 +35,6 @@ | |
import salt.utils.stringutils | |
from salt.ext import six | |
-try: | |
- from collections.abc import Mapping | |
-except ImportError: | |
- from collections import Mapping | |
- | |
class NestDisplay(object): | |
''' | |
--- salt/returners/slack_webhook_return.py | |
+++ salt/returners/slack_webhook_return.py | |
@@ -322,7 +322,7 @@ | |
show_tasks = _options.get('show_tasks') | |
author_icon = _options.get('author_icon') | |
- if not webhook or webhook is '': | |
+ if not webhook: | |
log.error('%s.webhook not defined in salt config', __virtualname__) | |
return | |
--- salt/states/debconfmod.py | |
+++ salt/states/debconfmod.py | |
@@ -210,7 +210,7 @@ | |
args['value'] = 'true' if args['value'] else 'false' | |
if current is not None and [key, args['type'], six.text_type(args['value'])] in current: | |
- if ret['comment'] is '': | |
+ if ret['comment'] == '': | |
ret['comment'] = 'Unchanged answers: ' | |
ret['comment'] += ('{0} ').format(key) | |
else: | |
--- salt/states/file.py | |
+++ salt/states/file.py | |
@@ -291,8 +291,9 @@ | |
import sys | |
import time | |
import traceback | |
-from collections import Iterable, Mapping, defaultdict | |
-from datetime import datetime, date # python3 problem in the making? | |
+from collections import defaultdict | |
+from collections.abc import Iterable, Mapping | |
+from datetime import datetime, date # python3 problem in the making? | |
# Import salt libs | |
import salt.loader | |
--- salt/states/git.py | |
+++ salt/states/git.py | |
@@ -2464,7 +2464,7 @@ | |
password, | |
output_encoding=output_encoding)[0] | |
- if remote_rev_type is 'hash': | |
+ if remote_rev_type == 'hash': | |
try: | |
__salt__['git.describe'](target, | |
rev, | |
@@ -2643,7 +2643,7 @@ | |
# get refs and checkout | |
checkout_commit_id = '' | |
- if remote_rev_type is 'hash': | |
+ if remote_rev_type == 'hash': | |
if __salt__['git.describe']( | |
target, | |
rev, | |
--- salt/states/module.py | |
+++ salt/states/module.py | |
@@ -589,7 +589,7 @@ | |
ret['result'] = False | |
return ret | |
else: | |
- if mret is not None or mret is not {}: | |
+ if mret is not None or mret != {}: | |
ret['changes']['ret'] = mret | |
if 'returner' in kwargs: | |
--- salt/states/mysql_grants.py | |
+++ salt/states/mysql_grants.py | |
@@ -167,7 +167,7 @@ | |
db_part = database.rpartition('.') | |
my_db = db_part[0] | |
my_table = db_part[2] | |
- my_db = __salt__['mysql.quote_identifier'](my_db, (my_table is '*')) | |
+ my_db = __salt__['mysql.quote_identifier'](my_db, (my_table == '*')) | |
my_table = __salt__['mysql.quote_identifier'](my_table) | |
# Removing per table grants in case of database level grant !!! | |
if token_grants['database'] == my_db: | |
--- salt/utils/args.py | |
+++ salt/utils/args.py | |
@@ -241,7 +241,12 @@ | |
def get_function_argspec(func, is_class_method=None): | |
''' | |
- A small wrapper around getargspec that also supports callable classes | |
+ A small wrapper around getargspec that also supports callable classes and wrapped functions | |
+ | |
+ If the given function is a wrapper around another function (i.e. has a | |
+ ``__wrapped__`` attribute), return the functions specification of the underlying | |
+ function. | |
+ | |
:param is_class_method: Pass True if you are sure that the function being passed | |
is a class method. The reason for this is that on Python 3 | |
``inspect.ismethod`` only returns ``True`` for bound methods, | |
@@ -253,6 +258,9 @@ | |
if not callable(func): | |
raise TypeError('{0} is not a callable'.format(func)) | |
+ if hasattr(func, "__wrapped__"): | |
+ func = func.__wrapped__ | |
+ | |
if six.PY2: | |
if is_class_method is True: | |
aspec = inspect.getargspec(func) | |
--- salt/utils/context.py | |
+++ salt/utils/context.py | |
@@ -14,11 +14,7 @@ | |
# Import python libs | |
import copy | |
import threading | |
-try: | |
- from collections.abc import MutableMapping | |
-except ImportError: | |
- from collections import MutableMapping | |
- | |
+from collections.abc import MutableMapping | |
from contextlib import contextmanager | |
from salt.ext import six | |
--- salt/utils/data.py | |
+++ salt/utils/data.py | |
@@ -12,11 +12,7 @@ | |
import logging | |
import re | |
import functools | |
- | |
-try: | |
- from collections.abc import Mapping, MutableMapping, Sequence | |
-except ImportError: | |
- from collections import Mapping, MutableMapping, Sequence | |
+from collections.abc import Mapping, MutableMapping, Sequence | |
# Import Salt libs | |
import salt.utils.dictupdate | |
--- salt/utils/decorators/path.py | |
+++ salt/utils/decorators/path.py | |
@@ -4,10 +4,11 @@ | |
''' | |
from __future__ import absolute_import, print_function, unicode_literals | |
+import functools | |
+ | |
# Import Salt libs | |
import salt.utils.path | |
from salt.exceptions import CommandNotFoundError | |
-from salt.utils.decorators.signature import identical_signature_wrapper | |
def which(exe): | |
@@ -15,13 +16,16 @@ | |
Decorator wrapper for salt.utils.path.which | |
''' | |
def wrapper(function): | |
+ @functools.wraps(function) | |
def wrapped(*args, **kwargs): | |
if salt.utils.path.which(exe) is None: | |
raise CommandNotFoundError( | |
'The \'{0}\' binary was not found in $PATH.'.format(exe) | |
) | |
return function(*args, **kwargs) | |
- return identical_signature_wrapper(function, wrapped) | |
+ | |
+ return wrapped | |
+ | |
return wrapper | |
@@ -30,6 +34,7 @@ | |
Decorator wrapper for salt.utils.path.which_bin | |
''' | |
def wrapper(function): | |
+ @functools.wraps(function) | |
def wrapped(*args, **kwargs): | |
if salt.utils.path.which_bin(exes) is None: | |
raise CommandNotFoundError( | |
@@ -39,5 +44,7 @@ | |
) | |
) | |
return function(*args, **kwargs) | |
- return identical_signature_wrapper(function, wrapped) | |
+ | |
+ return wrapped | |
+ | |
return wrapper | |
--- salt/utils/decorators/signature.py | |
+++ salt/utils/decorators/signature.py | |
@@ -1,43 +0,0 @@ | |
-# -*- coding: utf-8 -*- | |
-''' | |
-A decorator which returns a function with the same signature of the function | |
-which is being wrapped. | |
-''' | |
-# Import Python libs | |
-from __future__ import absolute_import, print_function, unicode_literals | |
-import inspect | |
-from functools import wraps | |
- | |
-# Import Salt libs | |
-import salt.utils.args | |
- | |
-# Import 3rd-party libs | |
-from salt.ext import six | |
- | |
- | |
-def identical_signature_wrapper(original_function, wrapped_function): | |
- ''' | |
- Return a function with identical signature as ``original_function``'s which | |
- will call the ``wrapped_function``. | |
- ''' | |
- context = {'__wrapped__': wrapped_function} | |
- function_def = compile( | |
- 'def {0}({1}):\n' | |
- ' return __wrapped__({2})'.format( | |
- # Keep the original function name | |
- original_function.__name__, | |
- # The function signature including defaults, i.e., 'timeout=1' | |
- inspect.formatargspec( | |
- *salt.utils.args.get_function_argspec(original_function) | |
- )[1:-1], | |
- # The function signature without the defaults | |
- inspect.formatargspec( | |
- formatvalue=lambda val: '', | |
- *salt.utils.args.get_function_argspec(original_function) | |
- )[1:-1] | |
- ), | |
- '<string>', | |
- 'exec' | |
- ) | |
- six.exec_(function_def, context) | |
- return wraps(original_function)(context[original_function.__name__]) | |
--- salt/utils/dictdiffer.py | |
+++ salt/utils/dictdiffer.py | |
@@ -13,7 +13,7 @@ | |
''' | |
from __future__ import absolute_import, print_function, unicode_literals | |
import copy | |
-from collections import Mapping | |
+from collections.abc import Mapping | |
from salt.ext import six | |
--- salt/utils/dictupdate.py | |
+++ salt/utils/dictupdate.py | |
@@ -7,14 +7,10 @@ | |
# Import python libs | |
from __future__ import absolute_import, print_function, unicode_literals | |
-try: | |
- from collections.abc import Mapping | |
-except ImportError: | |
- from collections import Mapping | |
- | |
# Import 3rd-party libs | |
import copy | |
import logging | |
+from collections.abc import Mapping | |
# Import salt libs | |
import salt.ext.six as six | |
--- salt/utils/event.py | |
+++ salt/utils/event.py | |
@@ -59,11 +59,7 @@ | |
import hashlib | |
import logging | |
import datetime | |
- | |
-try: | |
- from collections.abc import MutableMapping | |
-except ImportError: | |
- from collections import MutableMapping | |
+from collections.abc import MutableMapping | |
from multiprocessing.util import Finalize | |
from salt.ext.six.moves import range | |
@@ -89,6 +85,10 @@ | |
import salt.transport.ipc | |
import salt.transport.client | |
+# Import third party libs | |
+from salt.ext import six | |
+from salt.ext.six.moves import range | |
+ | |
log = logging.getLogger(__name__) | |
# The SUB_EVENT set is for functions that require events fired based on | |
--- salt/utils/immutabletypes.py | |
+++ salt/utils/immutabletypes.py | |
@@ -10,12 +10,7 @@ | |
''' | |
from __future__ import absolute_import, unicode_literals | |
import copy | |
- | |
-# Import python libs | |
-try: | |
- from collections.abc import Mapping, Sequence, Set | |
-except ImportError: | |
- from collections import Mapping, Sequence, Set | |
+from collections.abc import Mapping, Sequence, Set | |
class ImmutableDict(Mapping): | |
--- salt/utils/jinja.py | |
+++ salt/utils/jinja.py | |
@@ -6,13 +6,13 @@ | |
# Import python libs | |
from __future__ import absolute_import, unicode_literals | |
import atexit | |
-import collections | |
import logging | |
import os.path | |
import pipes | |
import pprint | |
import re | |
import uuid | |
+from collections.abc import Hashable | |
from functools import wraps | |
from xml.dom import minidom | |
from xml.etree.ElementTree import Element, SubElement, tostring | |
@@ -329,7 +329,7 @@ | |
return val.lower() in ('yes', '1', 'true') | |
if isinstance(val, six.integer_types): | |
return val > 0 | |
- if not isinstance(val, collections.Hashable): | |
+ if not isinstance(val, Hashable): | |
return len(val) > 0 | |
return False | |
@@ -500,7 +500,7 @@ | |
['a', 'b', 'c'] | |
''' | |
ret = None | |
- if isinstance(values, collections.Hashable): | |
+ if isinstance(values, Hashable): | |
ret = set(values) | |
else: | |
ret = [] | |
@@ -564,8 +564,8 @@ | |
2.5 | |
''' | |
- if not isinstance(lst, collections.Hashable): | |
- return float(sum(lst)/len(lst)) | |
+ if not isinstance(lst, Hashable): | |
+ return float(sum(lst) / len(lst)) | |
return float(lst) | |
@@ -585,7 +585,7 @@ | |
[1, 2, 3, 4, 6] | |
''' | |
- if isinstance(lst1, collections.Hashable) and isinstance(lst2, collections.Hashable): | |
+ if isinstance(lst1, Hashable) and isinstance(lst2, Hashable): | |
return set(lst1) | set(lst2) | |
return unique(lst1 + lst2) | |
@@ -606,7 +606,7 @@ | |
[2, 4] | |
''' | |
- if isinstance(lst1, collections.Hashable) and isinstance(lst2, collections.Hashable): | |
+ if isinstance(lst1, Hashable) and isinstance(lst2, Hashable): | |
return set(lst1) & set(lst2) | |
return unique([ele for ele in lst1 if ele in lst2]) | |
@@ -627,7 +627,7 @@ | |
[1, 3, 6] | |
''' | |
- if isinstance(lst1, collections.Hashable) and isinstance(lst2, collections.Hashable): | |
+ if isinstance(lst1, Hashable) and isinstance(lst2, Hashable): | |
return set(lst1) - set(lst2) | |
return unique([ele for ele in lst1 if ele not in lst2]) | |
@@ -648,7 +648,7 @@ | |
[1, 3] | |
''' | |
- if isinstance(lst1, collections.Hashable) and isinstance(lst2, collections.Hashable): | |
+ if isinstance(lst1, Hashable) and isinstance(lst2, Hashable): | |
return set(lst1) ^ set(lst2) | |
return unique([ele for ele in union(lst1, lst2) if ele not in intersect(lst1, lst2)]) | |
--- salt/utils/lazy.py | |
+++ salt/utils/lazy.py | |
@@ -6,12 +6,9 @@ | |
# Import Python Libs | |
from __future__ import absolute_import, unicode_literals | |
import logging | |
-import salt.exceptions | |
- | |
-try: | |
- from collections.abc import MutableMapping | |
-except ImportError: | |
- from collections import MutableMapping | |
+from collections.abc import MutableMapping | |
+ | |
+import salt.exceptions | |
log = logging.getLogger(__name__) | |
--- salt/utils/odict.py | |
+++ salt/utils/odict.py | |
@@ -22,10 +22,7 @@ | |
# Import python libs | |
from __future__ import absolute_import, unicode_literals, print_function | |
-try: | |
- from collections.abc import Callable | |
-except ImportError: | |
- from collections import Callable | |
+from collections.abc import Callable | |
# Import 3rd-party libs | |
from salt.ext import six | |
--- salt/utils/oset.py | |
+++ salt/utils/oset.py | |
@@ -21,8 +21,9 @@ | |
- added a __getstate__ and __setstate__ so it can be pickled | |
- added __getitem__ | |
''' | |
-from __future__ import absolute_import, unicode_literals, print_function | |
-import collections | |
+from __future__ import absolute_import, print_function, unicode_literals | |
+ | |
+from collections.abc import MutableSet | |
SLICE_ALL = slice(None) | |
__version__ = '2.0.1' | |
@@ -44,7 +45,7 @@ | |
return hasattr(obj, '__iter__') and not isinstance(obj, str) and not isinstance(obj, tuple) | |
-class OrderedSet(collections.MutableSet): | |
+class OrderedSet(MutableSet): | |
""" | |
An OrderedSet is a custom MutableSet that remembers its order, so that | |
every entry has an --- salt/utils/path.py | |
+++ salt/utils/path.py | |
@@ -6,10 +6,7 @@ | |
# Import python libs | |
from __future__ import absolute_import, print_function, unicode_literals | |
-try: | |
- from collections.abc import Iterable | |
-except ImportError: | |
- from collections import Iterable | |
+from collections.abc import Iterable | |
import errno | |
import logging | |
import os | |
--- salt/utils/schedule.py | |
+++ salt/utils/schedule.py | |
@@ -721,7 +721,7 @@ | |
if argspec.keywords: | |
# this function accepts **kwargs, pack in the publish data | |
for key, val in six.iteritems(ret): | |
- if key is not 'kwargs': | |
+ if key != 'kwargs': | |
kwargs['__pub_{0}'.format(key)] = copy.deepcopy(val) | |
# Only include these when running runner modules | |
--- salt/utils/win_pdh.py | |
+++ salt/utils/win_pdh.py | |
@@ -164,7 +164,7 @@ | |
''' | |
path = win32pdh.MakeCounterPath( | |
(None, obj, instance, None, instance_index, counter), 0) | |
- if win32pdh.ValidatePath(path) is 0: | |
+ if win32pdh.ValidatePath(path) == 0: | |
return Counter(path, obj, instance, instance_index, counter) | |
raise CommandExecutionError('Invalid counter specified: {0}'.format(path)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment